diff --git a/atest/acceptance/1-plugin/plugin_does_not_exist.robot b/atest/acceptance/1-plugin/plugin_does_not_exist.robot index 503c32f71..e97d25f21 100644 --- a/atest/acceptance/1-plugin/plugin_does_not_exist.robot +++ b/atest/acceptance/1-plugin/plugin_does_not_exist.robot @@ -1,5 +1,5 @@ *** Variables *** -${SERVER}= localhost:7000 +${SERVER}= localhost:${PORT} ${BROWSER}= firefox ${REMOTE_URL}= ${NONE} ${ROOT}= http://${SERVER}/html diff --git a/atest/acceptance/1-plugin/plugin_open_browser.robot b/atest/acceptance/1-plugin/plugin_open_browser.robot index 41247443b..9d391d956 100644 --- a/atest/acceptance/1-plugin/plugin_open_browser.robot +++ b/atest/acceptance/1-plugin/plugin_open_browser.robot @@ -2,7 +2,7 @@ Library SeleniumLibrary plugins=${CURDIR}/OpenBrowserExample.py *** Variables *** -${SERVER}= localhost:7000 +${SERVER}= localhost:${PORT} ${ROOT}= http://${SERVER}/html &{EXTRA DICTIONARY} extra=dictionary key=value diff --git a/atest/acceptance/2-event_firing_webdriver/event_firing_webdriver.robot b/atest/acceptance/2-event_firing_webdriver/event_firing_webdriver.robot index b31c8fa91..2ee7904a1 100644 --- a/atest/acceptance/2-event_firing_webdriver/event_firing_webdriver.robot +++ b/atest/acceptance/2-event_firing_webdriver/event_firing_webdriver.robot @@ -1,7 +1,7 @@ *** Settings *** Library SeleniumLibrary event_firing_webdriver=${CURDIR}/../../resources/testlibs/MyListener.py Resource resource_event_firing_webdriver.robot -Suite Setup Open Browser ${FRONT PAGE} ${BROWSER} alias=event_firing_webdriver +Suite Setup Open Browser ${FRONT_PAGE} ${BROWSER} alias=event_firing_webdriver ... remote_url=${REMOTE_URL} Suite Teardown Close All Browsers @@ -14,7 +14,7 @@ Open Browser To Start Page [Documentation] ... LOG 1:31 DEBUG Wrapping driver to event_firing_webdriver. ... LOG 1:33 INFO Got driver also from SeleniumLibrary. - Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL} + Open Browser ${FRONT_PAGE} ${BROWSER} remote_url=${REMOTE_URL} Event Firing Webdriver Go To (WebDriver) [Tags] NoGrid diff --git a/atest/acceptance/2-event_firing_webdriver/resource_event_firing_webdriver.robot b/atest/acceptance/2-event_firing_webdriver/resource_event_firing_webdriver.robot index a224bc9bd..27e92aab7 100644 --- a/atest/acceptance/2-event_firing_webdriver/resource_event_firing_webdriver.robot +++ b/atest/acceptance/2-event_firing_webdriver/resource_event_firing_webdriver.robot @@ -1,14 +1,7 @@ -*** Variables *** -${SERVER}= localhost:7000 -${BROWSER}= Chrome -${REMOTE_URL}= ${NONE} -${DESIRED_CAPABILITIES}= ${NONE} -${ROOT}= http://${SERVER}/html -${FRONT_PAGE}= ${ROOT}/ +*** Settings *** +Resource ../variables.robot *** Keywords *** - Go To Page "${relative url}" [Documentation] Goes to page Go To ${ROOT}/${relative url} - diff --git a/atest/acceptance/keywords/click_element_modifier.robot b/atest/acceptance/keywords/click_element_modifier.robot index f83a0317d..f3b9ac5ce 100644 --- a/atest/acceptance/keywords/click_element_modifier.robot +++ b/atest/acceptance/keywords/click_element_modifier.robot @@ -5,19 +5,23 @@ Resource ../resource.robot *** Test Cases *** Click Element Modifier CTRL + [Tags] SKIP_ON_MAC Click Element Button modifier=CTRL Element Text Should Be output CTRL click Click Link Modifier CTRL + [Tags] SKIP_ON_MAC Click Link link text modifier=CTRL Element Text Should Be output CTRL click [Teardown] Close Popup Window Click Button Modifier CTRL + [Tags] SKIP_ON_MAC Click Button Click me! modifier=CTRL Element Text Should Be output CTRL click Click Image Modifier CTRL + [Tags] SKIP_ON_MAC Click Image robot modifier=CTRL Element Text Should Be output CTRL click @@ -46,7 +50,7 @@ Click Element Action Chain and modifier [Documentation] LOG 1:1 INFO Clicking element 'Button' with CTRL. Click Element Button modifier=CTRL action_chain=True Element Text Should Be output CTRL click - + *** Keywords *** Initialize Page Reload Page diff --git a/atest/acceptance/keywords/elements.robot b/atest/acceptance/keywords/elements.robot index fa053b0ff..a93ccd219 100644 --- a/atest/acceptance/keywords/elements.robot +++ b/atest/acceptance/keywords/elements.robot @@ -90,7 +90,7 @@ Get DOM Attribute Should Be Equal ${id} some_id # Test custom attribute ${existing_custom_attr}= Get DOM Attribute id:emptyDiv data-id - Should Be Equal ${existing_custom_attr} my_id + Should Be Equal ${existing_custom_attr} my_id ${doesnotexist_custom_attr}= Get DOM Attribute id:emptyDiv data-doesnotexist Should Be Equal ${doesnotexist_custom_attr} ${None} # Get non existing DOM Attribute @@ -156,7 +156,7 @@ Get Element Attribute And Element Attribute Value Should Be Should have same res Element Attribute Value Should Be css=#second_div class ${attribute_value} Get Element Attribute Value Should Be Should Be Succesfull with non-ascii characters - Element Attribute Value Should Be link=Link with Unicode äöüÄÖÜß href http://localhost:7000/html/index.html + Element Attribute Value Should Be link=Link with Unicode äöüÄÖÜß href ${FRONT_PAGE}index.html Get Element Attribute Value Should Be Should Be Succesfull error and error messages Run Keyword And Expect Error @@ -169,8 +169,8 @@ Get Element Attribute Value Should Be Should Be Succesfull error and error messa ... Element with locator 'id=non_existing' not found. ... Element Attribute Value Should Be id=non_existing href http://non_existing.com Run Keyword And Expect Error - ... Element 'link=Target opens in new window' attribute should have value 'http://localhost:7000/html/indéx.html' (str) but its value was 'http://localhost:7000/html/index.html' (str). - ... Element Attribute Value Should Be link=Target opens in new window href http://localhost:7000/html/indéx.html + ... Element 'link=Target opens in new window' attribute should have value '${FRONT_PAGE}indéx.html' (str) but its value was '${FRONT_PAGE}index.html' (str). + ... Element Attribute Value Should Be link=Target opens in new window href ${FRONT_PAGE}indéx.html Get Horizontal Position ${pos}= Get Horizontal Position link=Link diff --git a/atest/acceptance/keywords/location.robot b/atest/acceptance/keywords/location.robot index 19d9ac1d8..d96fdb3aa 100644 --- a/atest/acceptance/keywords/location.robot +++ b/atest/acceptance/keywords/location.robot @@ -44,12 +44,13 @@ Wait Until Location Contains At The End Wait Until Location Contains In The Middle [Setup] Go To Page "javascript/wait_location.html" Click Element button - Wait Until Location Contains 7000 + Wait Until Location Contains ${PORT} Wait Until Location Contains As Number [Setup] Go To Page "javascript/wait_location.html" Click Element button - Wait Until Location Contains ${7000} + ${number} Convert To Integer ${PORT} + Wait Until Location Contains ${number} Wait Until Location Contains Fails [Setup] Go To Page "javascript/wait_location.html" @@ -70,7 +71,7 @@ Wait Until Location Contains Fails With Timeout Wait Until Location Is [Setup] Go To Page "javascript/wait_location.html" Click Element button - Wait Until Location Is http://localhost:7000/html/ + Wait Until Location Is ${FRONT_PAGE} Wait Until Location Is Fails [Setup] Go To Page "javascript/wait_location.html" @@ -91,14 +92,14 @@ Wait Until Location Is Fails With Timeout Wait Until Location Is Not [Setup] Go To Page "javascript/wait_location.html" Click Element button - Wait Until Location Is Not http://localhost:7000/html/javascript/wait_location.html + Wait Until Location Is Not ${FRONT_PAGE}javascript/wait_location.html Wait Until Location Is Not Fail [Setup] Go To Page "javascript/wait_location.html" ${orig_timeout}= Set Selenium Timeout 2 s Run Keyword And Expect Error - ... Location is 'http://localhost:7000/html/javascript/wait_location.html' in 2 seconds. - ... Wait Until Location Is Not http://localhost:7000/html/javascript/wait_location.html + ... Location is '${FRONT_PAGE}javascript/wait_location.html' in 2 seconds. + ... Wait Until Location Is Not ${FRONT_PAGE}javascript/wait_location.html Set Selenium Timeout ${orig_timeout} Wait Until Location Is Not Fails With Timeout @@ -106,8 +107,8 @@ Wait Until Location Is Not Fails With Timeout ${orig_timeout}= Set Selenium Timeout 2 s Click Element button Run Keyword And Expect Error - ... Location is 'http://localhost:7000/html/javascript/wait_location.html' in 750 milliseconds. - ... Wait Until Location Is Not http://localhost:7000/html/javascript/wait_location.html timeout=750ms + ... Location is '${FRONT_PAGE}javascript/wait_location.html' in 750 milliseconds. + ... Wait Until Location Is Not ${FRONT_PAGE}javascript/wait_location.html timeout=750ms Set Selenium Timeout ${orig_timeout} Wait Until Location Is Not Fails With Message @@ -116,7 +117,7 @@ Wait Until Location Is Not Fails With Message ${orig_timeout}= Set Selenium Timeout 2 s Run Keyword And Expect Error ... my_message - ... Wait Until Location Is Not http://localhost:7000/html/javascript/wait_location.html message=my_message + ... Wait Until Location Is Not ${FRONT_PAGE}javascript/wait_location.html message=my_message Set Selenium Timeout ${orig_timeout} Wait Until Location Does Not Contain @@ -143,9 +144,10 @@ Wait Until Location Does Not Contain Fail In The Middle Wait Until Location Does Not Contain Fail As Number [Setup] Go To Page "javascript/wait_location.html" ${orig_timeout}= Set Selenium Timeout 2 s + ${number} Convert To Integer ${PORT} run keyword and expect error - ... Location did contain '${7000}' in 2 seconds. - ... Wait Until Location Does Not Contain ${7000} + ... Location did contain '${number}' in 2 seconds. + ... Wait Until Location Does Not Contain ${number} Set Selenium Timeout ${orig_timeout} Wait Until Location Does Not Contain Fail At The End diff --git a/atest/acceptance/resource.robot b/atest/acceptance/resource.robot index 4bcaf38eb..7b429d0ff 100644 --- a/atest/acceptance/resource.robot +++ b/atest/acceptance/resource.robot @@ -3,15 +3,7 @@ Library SeleniumLibrary run_on_failure=Nothing implicit_wait=0.2 Library Collections Library OperatingSystem Library DateTime - -*** Variables *** -${SERVER}= localhost:7000 -${BROWSER}= firefox -${REMOTE_URL}= ${NONE} -${DESIRED_CAPABILITIES}= ${NONE} -${ROOT}= http://${SERVER}/html -${FRONT_PAGE}= ${ROOT}/ -${SPEED}= 0 +Resource variables.robot *** Keywords *** Open Browser To Start Page diff --git a/atest/acceptance/variables.robot b/atest/acceptance/variables.robot new file mode 100644 index 000000000..b613ccb5a --- /dev/null +++ b/atest/acceptance/variables.robot @@ -0,0 +1,9 @@ +*** Variables *** +${PORT}= 7000 +${SERVER}= localhost:${PORT} +${BROWSER}= firefox +${REMOTE_URL}= ${NONE} +${DESIRED_CAPABILITIES}= ${NONE} +${ROOT}= http://${SERVER}/html +${FRONT_PAGE}= ${ROOT}/ +${SPEED}= 0 \ No newline at end of file diff --git a/atest/resources/html/javascript/wait_location.html b/atest/resources/html/javascript/wait_location.html index c4e96c147..68bc0478e 100644 --- a/atest/resources/html/javascript/wait_location.html +++ b/atest/resources/html/javascript/wait_location.html @@ -5,7 +5,8 @@ setTimeout('doLocation()', 1000) } function doLocation() { - self.location = 'http://localhost:7000/html/' + var base_url = window.location.origin; + self.location = `${base_url}/html/` } diff --git a/atest/resources/testserver/testserver.py b/atest/resources/testserver/testserver.py index 565c6506f..b3e582e88 100644 --- a/atest/resources/testserver/testserver.py +++ b/atest/resources/testserver/testserver.py @@ -1,6 +1,7 @@ # Initially based on: # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/336012 +import argparse import os import sys @@ -40,11 +41,14 @@ def start_server(path, port=7000): if __name__ == "__main__": - if len(sys.argv) != 2 or sys.argv[1] not in ["start", "stop"]: - print("usage: %s start|stop" % sys.argv[0]) - sys.exit(1) - if sys.argv[1] == "start": + parser = argparse.ArgumentParser() + parser.add_argument("command", choices=["start", "stop"]) + parser.add_argument("--port", default=7000, type=int) + args = parser.parse_args() + port = args.port + command = args.command + if command == "start": path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - start_server(path) + start_server(path, port) else: - stop_server() + stop_server(port) diff --git a/atest/run.py b/atest/run.py index 2c86cf994..3e7960a15 100755 --- a/atest/run.py +++ b/atest/run.py @@ -53,6 +53,7 @@ from robot import rebot_cli from robot import __version__ as robot_version from selenium import __version__ as selenium_version +from selenium.webdriver.common.utils import free_port from robot.utils import is_truthy try: @@ -107,10 +108,12 @@ def acceptance_tests( if os.path.exists(RESULTS_DIR): shutil.rmtree(RESULTS_DIR) os.mkdir(RESULTS_DIR) + port = free_port() + print(f"Using port: {port}") if grid: hub, node = start_grid() - with http_server(interpreter): - execute_tests(interpreter, browser, rf_options, grid, event_firing) + with http_server(interpreter, port): + execute_tests(interpreter, browser, rf_options, grid, event_firing, port) failures = process_output(browser) if failures: print( @@ -178,23 +181,23 @@ def _grid_status(status=False, role="hub"): @contextmanager -def http_server(interpreter): +def http_server(interpreter, port:int): serverlog = open(os.path.join(RESULTS_DIR, "serverlog.txt"), "w") interpreter = "python" if not interpreter else interpreter process = subprocess.Popen( - [interpreter, HTTP_SERVER_FILE, "start"], + [interpreter, HTTP_SERVER_FILE, "start", "--port", str(port)], stdout=serverlog, stderr=subprocess.STDOUT, ) try: yield finally: - subprocess.call([interpreter, HTTP_SERVER_FILE, "stop"]) + subprocess.call([interpreter, HTTP_SERVER_FILE, "stop", "--port", str(port)]) process.wait() serverlog.close() -def execute_tests(interpreter, browser, rf_options, grid, event_firing): +def execute_tests(interpreter, browser, rf_options, grid, event_firing, port): options = [] if grid: runner = interpreter.split() + [ @@ -204,7 +207,11 @@ def execute_tests(interpreter, browser, rf_options, grid, event_firing): "2", ] else: - runner = interpreter.split() + ["-m", "robot.run"] + runner = interpreter.split() + ["-m", "robot.run", "--variable", f"PORT:{port}"] + if platform.system() == "Darwin": + runner.append("--exclude") + runner.append("SKIP_ON_MAC") + options.extend([opt.format(browser=browser) for opt in ROBOT_OPTIONS]) if rf_options: options += rf_options