Skip to content

Commit 5017a8f

Browse files
author
Konstantinacc
committed
Fixed test for walkthrough pages on Chrome browser.
Added global variable BROWSER with default value firefox that updates its value from capabilities.yaml browserName parameter. Added user agent on Chrome browser for Linux, Windows and Mac to test walkthrough pages, on each OS.
1 parent 5fbc9e4 commit 5017a8f

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

bin/seleniumbender

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,17 @@ elif [ "${walkthrough}" -eq 1 ]; then
9797
IDENTIFIER="walkthrough"
9898
RETVALS=()
9999
# Linux
100+
export SELENIUM_USER_AGENT_CHROME='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'
100101
export SELENIUM_USER_AGENT='Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0 codebender-selenium'
101102
tox tests/walkthrough -- --url=${URL} --source=${SOURCE} --plugin
102103
RETVALS+=($?)
103104
# Windows
105+
export SELENIUM_USER_AGENT_CHROME='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'
104106
export SELENIUM_USER_AGENT='Mozilla/5.0 (Windows NT 6.1; rv:43.0) Gecko/20100101 Firefox/43.0 codebender-selenium'
105107
tox tests/walkthrough -- --url=${URL} --source=${SOURCE} --plugin
106108
RETVALS+=($?)
107109
# MacOSX
110+
export SELENIUM_USER_AGENT_CHROME='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'
108111
export SELENIUM_USER_AGENT='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1; rv:43.0) Gecko/20100101 Firefox/43.0 codebender-selenium'
109112
tox tests/walkthrough -- --url=${URL} --source=${SOURCE} --plugin
110113
RETVALS+=($?)

codebender_testing/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def jsondump(data):
9595
DEFAULT_USER_AGENT = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0 codebender-selenium'
9696
TESTS_USER_AGENT = os.getenv('SELENIUM_USER_AGENT', DEFAULT_USER_AGENT)
9797

98+
DEFAULT_USER_AGENT_CHROME = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'
99+
TESTS_USER_AGENT_CHROME = os.getenv('SELENIUM_USER_AGENT_CHROME', DEFAULT_USER_AGENT_CHROME)
100+
101+
BROWSER = "firefox"
102+
98103
# Set up Selenium Webdrivers to be used for selenium tests.
99104
def _get_firefox_profile():
100105
"""Returns the Firefox profile to be used for the FF webdriver.
@@ -140,12 +145,14 @@ def create_webdriver(command_executor, desired_capabilities):
140145
browser_profile_path = None
141146

142147
if browser_name == "chrome":
148+
BROWSER = "chrome"
143149
desired_capabilities = DesiredCapabilities.CHROME.copy()
144150
desired_capabilities.update(_capabilities)
145151
if desired_capabilities["version"] > CHROME_EXT_MAX_CHROME_VERSION:
146152
# Add new chrome extension to capabilities.
147153
options = chrome.options.Options()
148154
options.add_extension(os.path.join(_EXTENSIONS_DIR, _CHROME_APP_FNAME))
155+
options.add_argument("--user-agent=" + TESTS_USER_AGENT_CHROME)
149156
desired_capabilities.update(options.to_capabilities())
150157
desired_capabilities.update(_capabilities)
151158
else:
@@ -154,6 +161,7 @@ def create_webdriver(command_executor, desired_capabilities):
154161
% (CHROME_EXT_MAX_CHROME_VERSION, desired_capabilities["version"]))
155162

156163
elif browser_name == "firefox":
164+
BROWSER = "firefox"
157165
desired_capabilities = DesiredCapabilities.FIREFOX.copy()
158166
desired_capabilities.update(_capabilities)
159167
browser_profile = _get_firefox_profile()

tests/walkthrough/test_walkthrough.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import pytest
33

44
from codebender_testing.config import TESTS_USER_AGENT
5+
from codebender_testing.config import TESTS_USER_AGENT_CHROME
6+
from codebender_testing.config import BROWSER
57
from codebender_testing.utils import SeleniumTestCase
68
from codebender_testing.utils import SELECT_BOARD_SCRIPT
79

8-
910
TEST_BOARD = 'Arduino Uno'
1011

1112

@@ -28,12 +29,20 @@ def test_page_2(self):
2829

2930
def test_page_3(self):
3031
"""Test page 3"""
31-
if 'Linux' in TESTS_USER_AGENT:
32-
self.get_element(By.CSS_SELECTOR, '#linux-directions .btn:nth-child(2)').click()
33-
elif 'Windows' in TESTS_USER_AGENT:
34-
self.get_element(By.CSS_SELECTOR, '#windows-directions .btn:nth-child(2)').click()
35-
elif 'Mac' in TESTS_USER_AGENT:
36-
self.get_element(By.CSS_SELECTOR, '#mac-directions .btn:nth-child(2)').click()
32+
if BROWSER == "firefox":
33+
if 'Linux' in TESTS_USER_AGENT:
34+
self.get_element(By.CSS_SELECTOR, '#linux-directions .btn:nth-child(2)').click()
35+
elif 'Windows' in TESTS_USER_AGENT:
36+
self.get_element(By.CSS_SELECTOR, '#windows-directions .btn:nth-child(2)').click()
37+
elif 'Mac' in TESTS_USER_AGENT:
38+
self.get_element(By.CSS_SELECTOR, '#mac-directions .btn:nth-child(2)').click()
39+
elif BROWSER == "chrome":
40+
if 'Linux' in TESTS_USER_AGENT_CHROME:
41+
self.get_element(By.CSS_SELECTOR, '#linux-directions .btn:nth-child(2)').click()
42+
elif 'Windows' in TESTS_USER_AGENT_CHROME:
43+
self.get_element(By.CSS_SELECTOR, '#windows-directions .btn:nth-child(2)').click()
44+
elif 'Mac' in TESTS_USER_AGENT_CHROME:
45+
self.get_element(By.CSS_SELECTOR, '#mac-directions .btn:nth-child(2)').click()
3746

3847
def test_page_4(self):
3948
"""Test page 4"""

0 commit comments

Comments
 (0)