How to reconnect to a URL with python selenium

I’ve a selenium python test suite which is used to run regression tests for an UI application.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@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')
</code>
<code>@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') </code>
@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.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật