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 main(): py = Pylenium() py.visit('https://google.com') py.get(search_field).type('puppies', Keys.ENTER) py.get(images_link).click() print(py.title) py.quit()
def pyc(test_run, py_config, request): """ A singleton of Pylenium to be shared in the tests of a Class. The tests in the class are executed sequentially and in order. Warnings: This approach is NOT recommended. You should want your tests to be modular, atomic and deterministic. Examples: class TestGoogle: def test_visit_google(self, pyc): # first test navigates to google.com pyc.visit('https://google.com') def test_google_search(self, pyc): # second test is already on google.com, test search pyc.get("[name='q']").type('puppies', Keys.ENTER) assert 'puppies' in pyc.title """ # init logger class_name = request.node.name file_path = f'{test_run}/{class_name}' if not os.path.exists(file_path): os.makedirs(file_path) logger = Logger(class_name, file_path) # init driver py = Pylenium(py_config, logger) yield py py.quit()
def py_(): # Code before `yield` is executed Before Each test. # By default, fixtures are mapped to each test. # You can change the scope by using: # `@pytest.fixture(scope=SCOPE)` where SCOPE is 'class', 'module' or 'session' _py = Pylenium() # Then `yield` or `return` the instance of Pylenium yield _py # Code after `yield` is executed After Each test. # In this case, once the test is complete, quit the driver. # This will be executed whether the test passed or failed. _py.quit()
def login_session(test_case, py_config, selenium, tested_user, request, logger) -> SessionStorage: """Access login pages to get the session storage values.""" py = Pylenium(py_config) params = request.param if params['accessName'] in ['BCSC', 'STAFF']: login_page = BCSCLoginPage(py) if params['loginAs'] in ['ADMIN', 'STAFF_ADMIN']: login_page.run(url=f'{params["path"]}', username=params['username'], password=params['password']) else: for config in tested_user.config: invitation_token = config.invitation_token if invitation_token: login_page = BCSCInvitationLoginPage(py) login_page.run(url=f'{params["path"]}/{invitation_token}', username=params['username'], password=params['password']) break elif params['accessName'] in ['BCEID']: login_page = BCEIDLoginPage(py) login_page.run(url=f'{params["path"]}', username=params['username'], password=params['password']) login_session = SessionStorage(py) login_session.access_type = params['accessName'] login_session.login_as = params['loginAs'] login_session.username = params['username'] yield login_session """ 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: logger.info("Test Failed - Attaching Screenshot", attachment={"name": "test_failed.png", "data": image_file, "mime": "image/png"}) except AttributeError: logger.error('Unable to access request.node.report.failed, unable to take screenshot.') except TypeError: logger.info('Report Portal is not connected to this test run.') """ py.quit() return login_session
def py(test_case, py_config, request): """ 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, test_case.logger) yield py if request.node.rep_call.failed: # if the test failed, execute code in this block if py_config.logging.screenshots_on: py.screenshot(f'{test_case.file_path}/test_failed.png') py.quit()
def test_pay_by_paybc(self, testing_config, test_case, py_config, selenium, request): """Access login pages to get the session storage values.""" py = Pylenium(py_config, test_case.logger) paybc_page = PayBCPage(py) paybc_page.run(url=testing_config.pay_system_url, creditcard=get_settings().PAYBC_CREDITCARD, cvv=get_settings().PAYBC_CREDITCARD_CVV)