Forum Discussion
Lago
4 years agoStaff
Try to warp you script in a try/except so that you can set pass/fail at the end.
Check out this link to add the try execpt to your preferred scripting language:
https://support.smartbear.com/crossbrowsertesting/docs/automated-testing/index.html
example (in python):
try: # load the page url print('Loading Url') self.driver.get('http://crossbrowsertesting.github.io/selenium_example_page.html') # maximize the window - DESKTOPS ONLY #print('Maximizing window') #self.driver.maximize_window() #check the title print('Checking title') self.assertEqual("Selenium Test Example Page", self.driver.title) # if we are still in the try block after all of our assertions that # means our test has had no failures, so we set the status to "pass" self.test_result = 'pass' except AssertionError as e: # if any assertions are false, we take a snapshot of the screen, log # the error message, and set the score to "during tearDown()". snapshot_hash = self.api_session.post('https://crossbrowsertesting.com/api/v3/selenium/' + self.driver.session_id + '/snapshots').json()['hash'] self.api_session.put('https://crossbrowsertesting.com/api/v3/selenium/' + self.driver.session_id + '/snapshots/' + snapshot_hash, data={'description':"AssertionError: " + str(e)}) self.test_result = 'fail' raise def tearDown(self): print("Done with session %s" % self.driver.session_id) self.driver.quit() # Here we make the api call to set the test's score. # Pass it it passes, fail if an assertion fails, unset if the test didn't finish if self.test_result is not None: self.api_session.put('https://crossbrowsertesting.com/api/v3/selenium/' + self.driver.session_id, data={'action':'set_score', 'score':self.test_result}) if __name__ == '__main__': unittest.main()
Related Content
Recent Discussions
- 2 years ago
- 2 years ago