Merge pull request #39 from mdmintz/phantomjs-improvements
Phantomjs improvements
This commit is contained in:
commit
290dc0ca11
|
@ -120,6 +120,8 @@ cd examples/
|
|||
nosetests my_first_test.py --browser=firefox --with-selenium -s
|
||||
|
||||
nosetests my_first_test.py --browser=chrome --with-selenium -s
|
||||
|
||||
nosetests my_first_test.py --browser=phantomjs --with-selenium -s
|
||||
```
|
||||
|
||||
After the test completes, in the console output you'll see a dot (``.``) on a new line, representing a passing test. (On test failures you'll see an ``F`` instead, and on test errors you'll see an ``E``). It looks more like a moving progress bar when you're running a ton of unit tests side by side. This is part of nosetests. After all tests complete (in this case there is only one), you'll see the "``Ran 1 test in ...``" line, followed by an "``OK``" if all nosetests passed.
|
||||
|
@ -182,9 +184,11 @@ Here are some other useful nosetest arguments that you may want to append to you
|
|||
Due to high demand, pytest support has been added. You can run the above sample script in pytest like this:
|
||||
|
||||
```bash
|
||||
py.test my_first_test.py --with-selenium --with-testing_base --browser=firefox -s
|
||||
|
||||
py.test my_first_test.py --with-selenium --with-testing_base --browser=chrome -s
|
||||
|
||||
py.test my_first_test.py --with-selenium --with-testing_base --browser=firefox -s
|
||||
py.test my_first_test.py --with-selenium --with-testing_base --browser=phantomjs -s
|
||||
```
|
||||
|
||||
(NOTE: The ``--with-testing_base`` plugin gives you full logging on test failures for screenshots, page source, and basic test info.)
|
||||
|
|
|
@ -13,11 +13,21 @@ Run the example test in Chrome
|
|||
nosetests my_first_test.py --browser=chrome --with-selenium
|
||||
```
|
||||
|
||||
Run the example test in PhantomJS
|
||||
```bash
|
||||
nosetests my_first_test.py --browser=phantomjs --with-selenium
|
||||
```
|
||||
|
||||
Run the example test suite in Firefox and generate an html report (nosetests-only)
|
||||
```bash
|
||||
nosetests my_test_suite.py --with-selenium --browser=firefox --with-testing_base --report
|
||||
```
|
||||
|
||||
Run the example test suite in Chrome and generate an html report (nosetests-only)
|
||||
```bash
|
||||
nosetests my_test_suite.py --with-selenium --browser=chrome --with-testing_base --report
|
||||
```
|
||||
|
||||
Run the example test suite in PhantomJS and generate an html report (nosetests-only)
|
||||
```bash
|
||||
nosetests my_test_suite.py --with-selenium --browser=phantomjs --with-testing_base --report
|
||||
|
|
|
@ -14,6 +14,7 @@ class MyTestSuite(BaseCase):
|
|||
|
||||
def test_2(self):
|
||||
# This test should FAIL
|
||||
print "\n(This test fails on purpose)"
|
||||
self.open("http://xkcd.com/1675/")
|
||||
raise Exception("FAKE EXCEPTION: This test fails on purpose.")
|
||||
|
||||
|
@ -25,5 +26,6 @@ class MyTestSuite(BaseCase):
|
|||
|
||||
def test_4(self):
|
||||
# This test should FAIL
|
||||
print "\n(This test fails on purpose)"
|
||||
self.open("http://xkcd.com/1670/")
|
||||
self.find_element("FakeElement.DoesNotExist", timeout=0.5)
|
||||
|
|
|
@ -19,7 +19,7 @@ self.click_link_text(link_text, timeout=settings.SMALL_TIMEOUT)
|
|||
self.get_text(selector, by=By.CSS_SELECTOR, timeout=settings.SMALL_TIMEOUT)
|
||||
|
||||
self.get_attribute(selector, attribute, by=By.CSS_SELECTOR,
|
||||
timeout=settings.SMALL_TIMEOUT):
|
||||
timeout=settings.SMALL_TIMEOUT)
|
||||
|
||||
self.add_text(selector, new_value, timeout=settings.SMALL_TIMEOUT)
|
||||
|
||||
|
@ -57,6 +57,8 @@ self.jquery_click(selector, wait=False)
|
|||
|
||||
self.jq_format(code)
|
||||
|
||||
self.get_domain_url(url)
|
||||
|
||||
self.set_value(selector, value, wait=False)
|
||||
|
||||
self.jquery_update_text_value(selector, new_value,
|
||||
|
|
|
@ -14,6 +14,7 @@ import time
|
|||
import traceback
|
||||
import unittest
|
||||
import uuid
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
from pyvirtualdisplay import Display
|
||||
from seleniumbase.config import settings
|
||||
from seleniumbase.core.application_manager import ApplicationManager
|
||||
|
@ -77,6 +78,35 @@ class BaseCase(unittest.TestCase):
|
|||
time.sleep(spacing)
|
||||
|
||||
def click_link_text(self, link_text, timeout=settings.SMALL_TIMEOUT):
|
||||
""" This method clicks link text on a page """
|
||||
# If using phantomjs, might need to extract and open the link directly
|
||||
if self.browser == 'phantomjs':
|
||||
if self.is_link_text_visible(link_text):
|
||||
element = self.wait_for_link_text_visible(link_text)
|
||||
element.click()
|
||||
return
|
||||
source = self.driver.page_source
|
||||
soup = BeautifulSoup(source)
|
||||
html_links = soup.fetch('a')
|
||||
for html_link in html_links:
|
||||
if html_link.text == link_text:
|
||||
for html_attribute in html_link.attrs:
|
||||
if html_attribute[0] == 'href':
|
||||
href = html_attribute[1]
|
||||
if href.startswith('//'):
|
||||
link = "http:" + href
|
||||
elif href.startswith('/'):
|
||||
url = self.driver.current_url
|
||||
domain_url = self.get_domain_url(url)
|
||||
link = domain_url + href
|
||||
else:
|
||||
link = href
|
||||
self.open(link)
|
||||
return
|
||||
raise Exception(
|
||||
'Could not parse link from link_text [%s]' % link_text)
|
||||
raise Exception("Link text [%s] was not found!" % link_text)
|
||||
# Not using phantomjs
|
||||
element = self.wait_for_link_text_visible(link_text, timeout=timeout)
|
||||
element.click()
|
||||
if settings.WAIT_FOR_RSC_ON_CLICKS:
|
||||
|
@ -230,6 +260,9 @@ class BaseCase(unittest.TestCase):
|
|||
def jq_format(self, code):
|
||||
return page_utils.jq_format(code)
|
||||
|
||||
def get_domain_url(self, url):
|
||||
return page_utils.get_domain_url(url)
|
||||
|
||||
def set_value(self, selector, value, wait=False):
|
||||
self.scroll_to(selector, wait=wait)
|
||||
val = json.dumps(value)
|
||||
|
|
|
@ -14,3 +14,11 @@ def jq_format(code):
|
|||
code = code.replace('\v', '\\v').replace('\a', '\\a').replace('\f', '\\f')
|
||||
code = code.replace('\b', '\\b').replace('\u', '\\u').replace('\r', '\\r')
|
||||
return code
|
||||
|
||||
|
||||
def get_domain_url(url):
|
||||
url_header = url.split('://')[0]
|
||||
simple_url = url.split('://')[1]
|
||||
base_url = simple_url.split('/')[0]
|
||||
domain_url = url_header + '://' + base_url
|
||||
return domain_url
|
||||
|
|
Loading…
Reference in New Issue