Skip to content

Commit

Permalink
EES-4117 - slight change to refetching selenium elements behaviour to…
Browse files Browse the repository at this point in the history
… make it a bit clearer as to why we need to reinitialise the selenium elements prior to each test run
  • Loading branch information
duncan-at-hiveit committed Nov 24, 2023
1 parent 5d36371 commit 2085598
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions tests/robot-tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import admin_api as admin_api
import args_and_variables as args_and_variables
import tests.libs.selenium_elements as selenium_elements
from pabot.pabot import main_program as pabot_run_cli
from robot import rebot_cli as robot_rebot_cli
from robot import run_cli as robot_run_cli
Expand Down Expand Up @@ -188,6 +189,11 @@ def run():
while args.rerun_attempts is None or test_run_index < args.rerun_attempts:
test_run_index += 1

# Ensure all SeleniumLibrary elements and keywords are updated to use a branch new
# Selenium instance for every test (re)run.
if test_run_index > 0:
selenium_elements.clear_instances()

rerunning_failed_suites = args.rerun_failed_suites or test_run_index > 0

# Perform any cleanup before the test run.
Expand Down
26 changes: 23 additions & 3 deletions tests/robot-tests/tests/libs/selenium_elements.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
from robot.libraries.BuiltIn import BuiltIn
from SeleniumLibrary.keywords.waiting import WaitingKeywords

sl_instance = None
element_finder_instance = None
waiting_instance = None


def sl():
return BuiltIn().get_library_instance("SeleniumLibrary")
global sl_instance
if sl_instance is None:
sl_instance = BuiltIn().get_library_instance("SeleniumLibrary")
return sl_instance


def element_finder():
return sl()._element_finder
global element_finder_instance
if element_finder_instance is None:
element_finder_instance = sl()._element_finder
return element_finder_instance


def waiting():
return WaitingKeywords(sl())
global waiting_instance
if waiting_instance is None:
waiting_instance = WaitingKeywords(sl())
return waiting_instance


def clear_instances():
global sl_instance, element_finder_instance, waiting_instance
sl_instance = None
element_finder_instance = None
waiting_instance = None

0 comments on commit 2085598

Please sign in to comment.