Forum Discussion

jadelaird's avatar
New Member
3 years ago

Selenium Python setting test to pass

Just starting out with selenium using python using the example on cross browser testing. 


Im only doing a simple script to start but its not setting the status to pass although I have this 


self.test_result = 'pass'


full script 



import unittest
from selenium import webdriver
import requests

class RAPLogin(unittest.TestCase):
def setUp(self):

self.username = ""
self.authkey = "u289162f9a08ba06"

self.api_session = requests.Session()
self.api_session.auth = (self.username,self.authkey)
self.test_result = None

caps = {}
caps['name'] = 'RAP - Login'
caps['browserName'] = 'Chrome'
caps['version'] = '60x64'
caps['platform'] = 'Windows 10'
caps['screenResolution'] = '1366x768'
caps['record_video'] = 'true'

self.driver = webdriver.Remote(


def test_CBT(self):
self.assertEqual("Login Page - Remote Access Portal", self.driver.title)
self.test_result = 'pass'

if __name__ == '__main__':


1 Reply

Replies have been turned off for this discussion
  • 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:

    example (in python):

                # load the page url
                print('Loading Url')
                # maximize the window - DESKTOPS ONLY
                #print('Maximizing 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.driver.session_id + '/snapshots').json()['hash']
                self.api_session.put('' + self.driver.session_id + '/snapshots/' + snapshot_hash,
                    data={'description':"AssertionError: " + str(e)})
                self.test_result = 'fail'
        def tearDown(self):
            print("Done with session %s" % self.driver.session_id)
            # 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('' + self.driver.session_id, 
                    data={'action':'set_score', 'score':self.test_result})
    if __name__ == '__main__':