Best Python code snippet using grail_python
test_qa_assessment_steps.py
Source:test_qa_assessment_steps.py  
...99def refresh_page():100    """user refreshes the page'"""101    test_assert.refresh_page()102@when(parsers.cfparse('user logins with "{username}" username and "{password}" password'))103def login_to_application(username,password):104    """user logins with "{username}" username and "{password}" password"""105    test_assert.login_to_app(username=username, password=password)106@when(parsers.cfparse('user logins without username'))107def login_to_application():108    """user logins without username"""109    test_assert.login_to_app(username="")110@when(parsers.cfparse('user logins without password'))111def login_to_application():112    """user logins without password"""113    test_assert.login_to_app(password="")114@when(parsers.cfparse('user logins without username and password'))115def login_to_application():116    """user logins without username and password"""117    test_assert.login_to_app(username="", password="")118@when(parsers.cfparse('user logins with "{username}" username'))119def login_to_application(username):120    """user logins with "{username}" username"""121    test_assert.login_to_app(username=username)122@when(parsers.cfparse('user logins with "{password}" password'))123def login_to_application(password):124    """user logins with "{password}" password"""125    test_assert.login_to_app(password=password)126@when(parsers.cfparse('user logins with only spaces in username and password fields'))127def login_to_application():128    """user logins with only spaces in username and password fields"""129    test_assert.login_to_app(username="  ", password="  ")130"""---------------------------- Then Statement(s)--------------------------------------------------"""131@then(parsers.cfparse('user should see "{content}" content on the page'))132def verify_content(content):133    """user should see "{content}" content on the page"""134    assert test_assert.verify_result(result=content)135@then(parsers.cfparse('user should see "{content}" validation message on the page'))136def verify_content(content):137    """user should see "{content}" validation message on the page"""138    assert test_assert.verify_result(validation=content)139@then('user should see empty username and password fields')140def verify_page_refresh():141    """user should see empty username and password fields"""...test_given_tasks.py
Source:test_given_tasks.py  
...8@ddt9class TestOrangeHRM(softest.TestCase):10    @file_data(Config.TEST_DATA_FILE)11    def test_scenario_1_invalid_credentials_using_datadriven(self,username,password):12        self.loginpage.login_to_application(username,password)13        error_message_text =  self.loginpage.get_login_error_message() 14        self.soft_assert(self.assertEqual,error_message_text,"Invalid credentials")15    def test_scenario_1_invalid_credentials_using_custom_testdata_handler(self):16        data = self.test_data_handle.get_test_data('Scenario 1')17        self.loginpage.login_to_application(data['username'],data['password'])18        error_message_text =  self.loginpage.get_login_error_message() 19        self.loginpage.log.info(error_message_text)20        self.soft_assert(self.assertEqual,error_message_text,"Invalid credentials")21    def test_scenario_1_invalid_credentials_capture_screenshot_on_failure(self):22        data = self.test_data_handle.get_test_data('Scenario 1')23        self.loginpage.login_to_application(data['username'],data['password'])24        error_message_text =  self.loginpage.get_login_error_message() 25        self.soft_assert(self.assertEqual(error_message_text,"Invalids credentials XXX"))26    def test_Scenario_2_Extract_Credentials_and_Login(self):27            username,password = self.loginpage.extract_credentials_from_login_page()28            assert username is not None and password is not None29            homepage = self.loginpage.login_to_application(username,password)30            assert 'dashboard' in homepage.get_page_url().lower()31            print(homepage.get_logged_in_user_name())...test_login.py
Source:test_login.py  
...9        url = 'https://www.saucedemo.com'10        logger.info(f'----- Opening browser and navigating to {url} -----')11        browser.config.base_url = url12    def test_login(self):13        self.login_page.login_to_application('standard_user', 'secret_sauce')14        self.login_page.assert_logged_in()15    def test_invalid_password(self):16        self.login_page.login_to_application('standard_user', 'bad_password')17        self.login_page.assert_not_logged_in()18        self.login_page.assert_error_matches_expected(19            'Epic sadface: Username and password do not match any user in this service'20        )21    def test_no_user_name(self):22        self.login_page.login_to_application('', 'secret_sauce')23        self.login_page.assert_not_logged_in()24        self.login_page.assert_error_matches_expected(25            'Epic sadface: Username is required')26    def test_no_password(self):27        self.login_page.login_to_application('standard_user', '')28        self.login_page.assert_not_logged_in()29        self.login_page.assert_error_matches_expected(30            'Epic sadface: Password is required')31    def test_user_locked_out(self):32        self.login_page.login_to_application('locked_out_user', 'secret_sauce')33        self.login_page.assert_not_logged_in()34        self.login_page.assert_error_matches_expected(...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!!
