Best Python code snippet using robotframework-pageobjects_python
test_functional.py
Source:test_functional.py  
...87        except IOError:88            raise Exception("Couldn't open log file %s" % log_path)89        finally:90            f.close()91    @unittest.skipUnless(BaseTestCase.are_sauce_creds_set_for_testing(),92                         "Must set 'SAUCE_USERNAME' and 'SAUCE_APIKEY' ("93                         "not PO_SAUCE."94                         ".) "95                         "as an env "96                         "variables to run this test")97    def test_sauce_unittest(self):98        self.assertFalse(os.path.exists(self.get_log_path()))99        run = self.run_scenario("test_sauce.py")100        job_data = self.get_job_data(self.get_sid_from_log())101        # Just check an arbitrary entry in the job data returned from sauce.102        self.assertEquals(job_data["browser"], "firefox", "The job ran in Sauce")103        # We expect this to fail, because the test makes a purposely false assertion104        # to test that we can assert against things going on in Sauce.105        self.assert_run(run, expected_returncode=1, search_output="Title should have been 'foo' but was 'Home - "106                                                                  "PubMed - NCBI")107    @unittest.skipUnless(BaseTestCase.are_sauce_creds_set_for_testing(),108                         "Must set 'SAUCE_USERNAME' and 'SAUCE_APIKEY' ("109                         "not "110                         "PO_SAUCE..) "111                         "as an env "112                         "variables to run this test")113    def test_sauce_robot(self):114        self.assertFalse(os.path.exists(self.get_log_path(is_robot=True)))115        run = self.run_scenario("test_sauce.robot", variablefile=os.path.join(self.test_dir, "sauce_vars.py"))116        job_data = self.get_job_data(self.get_sid_from_log(is_robot=True))117        # Just check an arbitrary entry in the job data returned from sauce.118        self.assertEquals(job_data["browser"], "firefox", "The job ran in Sauce")119        self.assert_run(run, expected_returncode=1, search_output="Title should have been 'foo' but was 'Home - "120                                                                  "PubMed - NCBI")121class ActionsTestCase(BaseTestCase):...test_unit.py
Source:test_unit.py  
...154        os.environ["PO_SAUCE_PLATFORM"] = "Windows 8.1"155        self.PO.uri = "/foo"156        p = self.PO()157        p.open()158    @skipUnless(BaseTestCase.are_sauce_creds_set_for_testing(),159                "SAUCE_USERNAME and SAUCE_APIKEY env vars must be set to test")160    @raises(selenium.common.exceptions.WebDriverException)161    def test_sauce_invalid_browser(self):162        self.set_baseurl_env(base_file=False, arbitrary_base="http://www.ncbi.nlm.nih.gov")163        os.environ["PO_BROWSER"] = "Firefox"164        os.environ["PO_SAUCE_BROWSERVERSION"] = "27"165        username, apikey = self.get_sauce_creds()166        os.environ["PO_SAUCE_USERNAME"] = username167        os.environ["PO_SAUCE_APIKEY"] = apikey168        os.environ["PO_SAUCE_PLATFORM"] = "Winows 8.1"169        self.PO.uri = "/foo"170        p = self.PO()171        p.open()172class ResolveUrlTestCase(BaseTestCase):...basetestcase.py
Source:basetestcase.py  
...15    base_file_url = "file:///%s/scenarios" % test_dir.replace("\\", "/")16    site_under_test_file_url = "%s/site/index.html" % base_file_url17    @classmethod18    @nottest19    def are_sauce_creds_set_for_testing(cls):20        """21        Determines if private sauce credentials are set as environment variables.22        It doens't check for "PO_SAUCE..." because these special env vars23        actually affect the tests. This leaves out "PO" so we can get the24        credentials and keep them around, without affecting any tests.25        """26        return "SAUCE_USERNAME" in os.environ and "SAUCE_APIKEY" in os.environ27    def get_log_path(self, is_robot=False, output_xml=False):28        if is_robot:29            if output_xml:30                filename = "output.xml"31            else:32                filename = "log.html"33        else:...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!!
