Skip to content

Commit 14fabef

Browse files
author
Brandon Duffany
committed
Add utility function
1 parent 2f0734d commit 14fabef

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

codebender_testing/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from selenium import webdriver
22

33

4+
BASE_URL = "http://localhost"
5+
46
WEBDRIVERS = {
57
"firefox": webdriver.Firefox,
68
"chrome": webdriver.Chrome

codebender_testing/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import re
12
import sys
23

34
from selenium import webdriver
45
import pytest
56

67
from codebender_testing.config import WEBDRIVERS
8+
from codebender_testing.config import BASE_URL
79

810

911
class SeleniumTestCase(object):
@@ -14,7 +16,18 @@ class SeleniumTestCase(object):
1416
def setup(self, request):
1517
"""Sets up attributes that should be accessible to all test cases."""
1618

17-
# We repeat each test for each webdriver configuration
19+
# Repeat each test for each webdriver configuration
1820
webdriver_cls = WEBDRIVERS[request.param]
1921
self.driver = webdriver_cls()
2022

23+
def open(self, url):
24+
"""Open the resource specified by `url`.
25+
If an absolute URL is specified (like 'http://codebender.cc') we
26+
use that URL. Otherwise the resource is relative to `BASE_URL` in
27+
`codebender_testing.config`.
28+
"""
29+
if re.match(".+?://^", url):
30+
return self.driver.get(url)
31+
else:
32+
return self.driver.get("%s/%s" % (BASE_URL, url))
33+

tests/home/test_home.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
class TestHome(SeleniumTestCase):
55

66
def test_navigate_home(self):
7-
self.driver.get("http://localhost")
7+
self.open("/")
88
assert "Codebender" in self.driver.title
99

0 commit comments

Comments
 (0)