I’ve a selenium python test suite which is used to run regression tests for an UI application.
@pytest.fixture(scope='class')
def setup(request):
driver = None
try:
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument("--window-size=1920,1080")
options.add_argument("--start-maximized")
options.add_argument('--headless')
options.add_argument('--ignore-certificate-errors')
driver = webdriver.Chrome(options=options)
request.cls.driver = driver
driver.delete_all_cookies()
driver.get(TestData_common.BASE_URL)
except WebDriverException as e:
print('UAT seems to be down...> ', e)
yield driver
if driver is not None:
print("Quitting the driver..")
driver.quit()
@pytest.mark.usefixtures("setup")
@pytest.mark.incremental
class Test_InvPayment:
def test_001_login(self):
"""Login to UAT and click AGREE button in Site Minder"""
assert TestData_common.URL_FOUND, "UAT seems to be down.."
self.loginPage = LoginPage(self.driver)
self.loginPage.do_click_agree_button()
assert TestData_common.AGREE_BTN_FOUND, "Unable to click Site Minder AGREE btn"
self.driver.maximize_window()
print('Successfully clicked AGREE button in SiteMinder')
time.sleep(2)
def test_002_enter_user_and_password(self):
"""Enter User name for UAT"""
self.loginPage = LoginPage(self.driver)
TestData_common.UserEnabled = True
self.loginPage.do_enter_user_name(TestData_common.USER_NAME_6, 'USER')
assert TestData_common.UserEnabled, "Unable to enter User Name.."
print('Entered User name:', TestData_common.USER_NAME_6)
time.sleep(2)
def test_003_enter_password(self):
"""Enter Password for Treasury"""
self.loginPage = LoginPage(self.driver)
self.loginPage.do_enter_password(TestData_common.PASSWORD, 'PASS')
assert TestData_common.PasswordEnabled, "Unable to enter Password.."
print('Entered password:', TestData_common.PASSWORD)
time.sleep(2)
def test_004_click_login_button(self):
"""Click LOGIN button"""
self.loginPage = LoginPage(self.driver)
self.loginPage.do_click_login_button()
assert TestData_common.LOGIN_BTN_FOUND, "Unable to click LOGIN button.."
print('Clicked LOGIN button')
This code works well on most times.
Sometimes the siteminder application which sits in front of the UAT application which is responsible for re-directing the traffic to the UAT application.This is where I enter the user/pwd and login to the app. Sometimes for whatever reason the siteminder application doesn’t re-direct to the UAT app and in those cases all the tests following test_004 fails.
In those cases, I want to build a re-try mechanism to again launch the URL and try logging in one more time. Is there a way to do this here? All I want is after clicking the login button from test_004, if the UAT application is not launched, the control goes back to the login page.
Any help is much appreciated.