Best Python code snippet using pytractor_python
test_selenium.py
Source: test_selenium.py
...22 assert(element.id == TestServer.TEST_FIND_ELEMENT)23 child = getattr(element, fn)('foo')24 assert(isinstance(child, WebElement))25 assert(child.id == TestServer.TEST_FIND_ELEMENT)26def test_find_elements(driver, fn):27 """ Test a find_elements_by_FOO method of both the webdriver28 and the WebElement class. The former will return a list of 29 WebElements, each of which should have a method of the same name,30 and which in should turn should also return a list of WebElements.31 """32 elements = getattr(driver, fn)('foo')33 # elements should be a list34 assert(isinstance(elements, list))35 # elements should match the TEST_FIND_ELEMENTS list36 assert(map(lambda x: x.id, elements) == TestServer.TEST_FIND_ELEMENTS)37 # Each member of elements should be a WebElement that has the same38 # method, which should in turn return a list of WebElements when called.39 for element in elements:40 assert(isinstance(element, WebElement))41 children = getattr(element, fn)('foo')42 assert(isinstance(children, list))43 assert(map(lambda x: x.id, children) == TestServer.TEST_FIND_ELEMENTS)44 assert(len(filter(lambda x: not isinstance(x, WebElement), children)) == 0)45if __name__ == '__main__':46 # start the test server on port 262647 server = TestServer(2626)48 thread = threading.Thread(target=server.run)49 thread.daemon = True50 thread.start()51 # Start the selenium proxy on port 4444, connecting to the test server52 # on port 2626.53 proxy = SeleniumProxy('127.0.0.1', 2626, proxy_port=4444)54 proxy_thread = threading.Thread(target=proxy.start)55 proxy_thread.daemon = True56 proxy_thread.start()57 # invoke selenium commands as tests58 driver = webdriver.Remote(command_executor='http://127.0.0.1:4444',59 desired_capabilities=webdriver.DesiredCapabilities.FIREFOX)60 assert(driver)61 # test navigation methods62 driver.get(TestServer.TEST_URL)63 assert(driver.current_url == TestServer.TEST_URL)64 driver.back()65 driver.forward()66 driver.refresh()67 # test script methods68 driver.set_script_timeout(10) # in selenium the number is in seconds69 driver.implicitly_wait(10) # ditto70 assert(TestServer.TEST_EXECUTE_RETURN_VALUE == driver.execute_script(TestServer.TEST_EXECUTE_SCRIPT))71 assert(TestServer.TEST_EXECUTE_RETURN_VALUE == driver.execute_script(TestServer.TEST_EXECUTE_SCRIPT,72 TestServer.TEST_EXECUTE_SCRIPT_ARGS))73 assert(TestServer.TEST_EXECUTE_RETURN_VALUE == driver.execute_async_script(TestServer.TEST_EXECUTE_SCRIPT))74 assert(TestServer.TEST_EXECUTE_RETURN_VALUE == driver.execute_async_script(TestServer.TEST_EXECUTE_SCRIPT,75 TestServer.TEST_EXECUTE_SCRIPT_ARGS))76 # test all the find_element_by_FOO methods77 test_find_element(driver, 'find_element_by_name')78 test_find_element(driver, 'find_element_by_id')79 test_find_element(driver, 'find_element_by_xpath')80 test_find_element(driver, 'find_element_by_link_text')81 test_find_element(driver, 'find_element_by_partial_link_text')82 test_find_element(driver, 'find_element_by_tag_name')83 test_find_element(driver, 'find_element_by_class_name')84 test_find_element(driver, 'find_element_by_css_selector')85 # test all the find_elements_by_FOO methods86 test_find_elements(driver, 'find_elements_by_name')87 test_find_elements(driver, 'find_elements_by_id')88 test_find_elements(driver, 'find_elements_by_xpath')89 test_find_elements(driver, 'find_elements_by_link_text')90 test_find_elements(driver, 'find_elements_by_partial_link_text')91 test_find_elements(driver, 'find_elements_by_tag_name')92 test_find_elements(driver, 'find_elements_by_class_name')93 test_find_elements(driver, 'find_elements_by_css_selector')94 # test WebElement methods95 element = driver.find_element_by_name('foo')96 element.click()97 assert(element.text == TestServer.TEST_GET_TEXT)98 element.send_keys('Mozilla Firefox')99 element.clear()100 assert(element.is_selected())101 assert(element.is_enabled())102 assert(element.is_displayed())103 assert(element.get_attribute('id') == TestServer.TEST_GET_VALUE)104 # make the server return error responses so we can test them105 server.responses = server.error_responses106 # test exception handling107 try:...
Check out the latest blogs from LambdaTest on this topic:
In today’s tech world, where speed is the key to modern software development, we should aim to get quick feedback on the impact of any change, and that is where CI/CD comes in place.
Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.
Building a website is all about keeping the user experience in mind. Ultimately, it’s about providing visitors with a mind-blowing experience so they’ll keep coming back. One way to ensure visitors have a great time on your site is to add some eye-catching text or image animations.
One of the most important tasks of a software developer is not just writing code fast; it is the ability to find what causes errors and bugs whenever you encounter one and the ability to solve them quickly.
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!