Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make test run on Mac #1899

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion atest/acceptance/1-plugin/plugin_does_not_exist.robot
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*** Variables ***
${SERVER}= localhost:7000
${SERVER}= localhost:${PORT}
${BROWSER}= firefox
${REMOTE_URL}= ${NONE}
${ROOT}= http://${SERVER}/html
Expand Down
2 changes: 1 addition & 1 deletion atest/acceptance/1-plugin/plugin_open_browser.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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}

6 changes: 5 additions & 1 deletion atest/acceptance/keywords/click_element_modifier.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions atest/acceptance/keywords/elements.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 13 additions & 11 deletions atest/acceptance/keywords/location.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -91,23 +92,23 @@ 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
[Setup] Go To Page "javascript/wait_location.html"
${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
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 1 addition & 9 deletions atest/acceptance/resource.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions atest/acceptance/variables.robot
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion atest/resources/html/javascript/wait_location.html
Original file line number Diff line number Diff line change
Expand Up @@ -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/`
}
</script>
<head>
Expand Down
16 changes: 10 additions & 6 deletions atest/resources/testserver/testserver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Initially based on:
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/336012

import argparse
import os
import sys

Expand Down Expand Up @@ -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)
21 changes: 14 additions & 7 deletions atest/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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() + [
Expand All @@ -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
Expand Down