def LT(py_config: PyleniumConfig): # 1. Define the 3 pieces needed to connect to LambdaTest username = os.getenv('LT_USERNAME') access_key = os.getenv('LT_ACCESS_KEY') remote_url = f'https://{username}:{access_key}@hub.lambdatest.com/wd/hub' # update Pylenium's config with this URL # * You can also set this in pylenium.json or via the CLI! * py_config.driver.remote_url = remote_url # 2. Update the Desired Capabilities for this Test Run desired_caps = { "build": 'pytest build', "name": 'pytest tutorial', "platform": 'Windows 10', "browserName": 'Chrome', "version": '87.0', "resolution": '1024x768', "console": 'true', "network": 'true' } # update Pylenium's config with this dictionary # * You can also set this in pylenium.json or via the CLI! * py_config.driver.capabilities.update(desired_caps) # 3. Instantiate a new instance of Pylenium that is connected to LambdaTest py = Pylenium(py_config) # 4. Yield the driver so the test can use it, then quit() when the test is complete yield py py.quit()
def py(test_case, py_config, request, rp_logger): """ Initialize a Pylenium driver for each test. Pass in this `py` fixture into the test function. Examples: def test_go_to_google(py): py.visit('https://google.com') assert 'Google' in py.title() """ py = Pylenium(py_config) yield py try: if request.node.report.failed: # if the test failed, execute code in this block if py_config.logging.screenshots_on: screenshot = py.screenshot(f'{test_case.file_path}/test_failed.png') with open(screenshot, "rb") as image_file: rp_logger.info("Test Failed - Attaching Screenshot", attachment={"name": "test_failed.png", "data": image_file, "mime": "image/png"}) except AttributeError: rp_logger.error('Unable to access request.node.report.failed, unable to take screenshot.') except TypeError: rp_logger.info('Report Portal is not connected to this test run.') py.quit()
def test_slither_io(py: Pylenium, fake): py.visit('https://slither.io') py.viewport(800, 800) py.get('#nick').type(fake.first_name()) py.getx("//div[@id='playh']//div[contains(text(), Play)]").click() game = True first_turn = True moves = list() center = 400, 400 while game: time.sleep(1) if not in_game(py): break py.screenshot('state.png') if first_turn: x, y = center first_turn = False else: x = random.randint(-50, 50) y = random.randint(-50, 50) move = x, y print(move) moves.append(move) ActionChains(py.webdriver).move_by_offset(x, y).perform()
def test_is_the_message_bold_when_unread_in_the_message_view(py: Pylenium): """ Test 5: Check to see if unread messages are bolded """ py.visit("https://automationintesting.online/#/admin/messages"); py.getx("//div[@class=\"form-group\"][1]/input").type('admin') py.getx("//div[@class=\"form-group\"][2]/input").type('password') py.get('.float-right').click() assert check_count(py.find('.read-false')) is True
def toggle(py: Pylenium, element: str): """ Element should be Str and needs to already be visible on page Example: If Home is currently the only visible element I can't expand anything below Home until I expand Home > [] Home Example: element = "home" """ py.getx(f'//label[@for="tree-node-{element}"]/../button').click()
def test_google(py: Pylenium): py.visit('https://google.com') py.get('[name="q"]').type('puppies') py.get('[name="btnK"]').submit() assert py.should().contain_title('puppies')
def check_checkbox(py: Pylenium, element: str): """ Element should be Str element = "commands" """ py.get(f"#tree-node-{element}").click(force=True)
def test_add_new_item(py: Pylenium, page: TodoPage): page.add_todo('Finish the course') assert page.get_all_todos().should().have_length(6) assert py.contains('6 of 6 remaining')
def test_check_all_items(py: Pylenium, page: TodoPage): for todo in page.get_all_todos(): todo.click() assert py.contains('0 of 5 remaining')
def test_check_many_items(py: Pylenium, page: TodoPage): todos = page.get_all_todos() todo2, todo4 = todos[1], todos[3] todo2.click() todo4.click() assert py.contains('3 of 5 remaining')
def test_axe_run(py: Pylenium): py.visit('https://qap.dev') axe = PyleniumAxe(py.webdriver) report = axe.run(name='a11y.json') number_of_violations = len(report.violations) assert number_of_violations < 10, f'{number_of_violations} violation(s) found'
def test_contact_check(py: Pylenium): """ Test 4: Check to see if the contact form shows a success message """ py.visit("https://automationintesting.online") py.get("input[placeholder=\"Name\"]").type('TEST123') py.get("input[placeholder=\"Email\"]").type('*****@*****.**') py.get("input[placeholder=\"Phone\"]").type('01212121311') py.get("input[placeholder=\"Subject\"]").type('TesTEST') py.get('textarea').type('TEsTESTTEsTESTTEsTEST') py.getx("//button[text()=\"Submit\"]").click() time.sleep(4) assert ('Thanks for getting in touch' in py.get('.contact').text()) is True
def test_update_branding(py: Pylenium): """ Test 3: Check to see the confirm message appears when branding is updated """ py.visit("https://automationintesting.online/#/admin") py.getx("//a[@href=\"/#/admin\"]").click() py.getx("//div[@class=\"form-group\"][1]/input").type('admin') py.getx("//div[@class=\"form-group\"][2]/input").type('password') py.get('.float-right').click() py.visit("https://automationintesting.online/#/admin/branding") py.get('.form-control').type('Test') py.get('.btn-outline-primary').click() count = py.findx("//button[text()=\"Close\"]").length() if count == 1: assert True is (True) else: assert True is False
def test_room(py: Pylenium): """ Test 2: Check to see if rooms are saved and displayed in the UI """ py.visit("https://automationintesting.online/#/") py.getx("//a[@href=\"/#/admin\"]").click() py.getx("//div[@class=\"form-group\"][1]/input").type('admin') py.getx("//div[@class=\"form-group\"][2]/input").type('password') py.get('.float-right').click() py.get(".room-form > div:nth-child(1) input").type('101') py.get(".room-form > div:nth-child(4) input").type('101') time.sleep(3) py.get(".btn-outline-primary").click() assert py.find('.detail').length() != 1
def test_login(py: Pylenium): """ Test 1: Check to see if you can log in with valid credentials """ py.visit('https://automationintesting.online/#/') py.get('footer p a:nth-child(5)').click() py.getx('//div[@class=\'form-group\'][1]/input').type('admin') py.getx("//div[@class=\"form-group\"][2]/input").type('password') py.get(".float-right").click() time.sleep(3) element = py.get('.navbar-collapse') print(element.text()) title = 'Rooms' in element.text() assert True is title
def test_the_home_page_data(py: Pylenium, home: HomePage): py.visit('https://automationintesting.online/') assert home.get_hotel_logo().should().have_attr( 'src', 'https://www.mwtestconsultancy.co.uk/img/rbp-logo.png')