Path: blob/trunk/py/test/selenium/webdriver/remote/remote_custom_element_tests.py
1865 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import pytest1819from selenium.webdriver.common.by import By20from selenium.webdriver.remote.webelement import WebElement212223# Custom element class24class MyCustomElement(WebElement):25def custom_method(self):26return "Custom element method"272829@pytest.fixture()30def custom_element_driver(driver):31try:32driver._web_element_cls = MyCustomElement33yield driver34finally:35driver._web_element_cls = WebElement363738def test_find_element_with_custom_class(custom_element_driver, pages):39"""Test to ensure custom element class is used for a single element."""40pages.load("simpleTest.html")41element = custom_element_driver.find_element(By.TAG_NAME, "body")42assert isinstance(element, MyCustomElement)43assert element.custom_method() == "Custom element method"444546def test_find_elements_with_custom_class(custom_element_driver, pages):47"""Test to ensure custom element class is used for multiple elements."""48pages.load("simpleTest.html")49elements = custom_element_driver.find_elements(By.TAG_NAME, "div")50assert all(isinstance(el, MyCustomElement) for el in elements)51assert all(el.custom_method() == "Custom element method" for el in elements)525354def test_default_element_class(driver, pages):55"""Test to ensure default WebElement class is used."""56pages.load("simpleTest.html")57element = driver.find_element(By.TAG_NAME, "body")58assert isinstance(element, WebElement)59assert not hasattr(element, "custom_method")606162