Last active
August 29, 2015 13:57
-
-
Save lucaswiman/9788422 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nose==1.1.2 | |
selenium==2.35.0 | |
wsgiref==0.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import logging | |
from selenium.webdriver import phantomjs | |
import sys | |
class SeleniumTestCase(unittest.TestCase): | |
def setUp(self): | |
self.selenium = phantomjs.webdriver.WebDriver() | |
def tearDown(self): | |
self.selenium.quit() | |
def test_that_something_fails(self): | |
self.selenium.get('https://www.google.com') | |
print repr(self.selenium.get_log('browser')) | |
print repr(self.selenium.get_log('har')) | |
raise AssertionError() | |
class QuitEarlySeleniumTestCase(unittest.TestCase): | |
def setUp(self): | |
self.selenium = phantomjs.webdriver.WebDriver() | |
def test_that_something_fails(self): | |
self.selenium.get('https://www.google.com') | |
s1 = repr(self.selenium.get_log('browser')) | |
s2 = repr(self.selenium.get_log('har')) | |
self.selenium.quit() | |
print s1 | |
print s2 | |
raise AssertionError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fcntl | |
import unittest | |
import logging | |
from selenium.webdriver import phantomjs | |
import sys | |
import os | |
def _make_fd_blocking(file_obj): | |
""" | |
Updates the flags of the file descriptor to make it blocking. | |
file_obj is a `file` object, which has a `.fileno()` method. | |
See http://trac.edgewall.org/ticket/2066#comment:1 | |
""" | |
fd = file_obj.fileno() | |
flags = fcntl.fcntl(fd, fcntl.F_GETFL) | |
if flags & os.O_NONBLOCK: | |
fcntl.fcntl(fd, fcntl.F_SETFL, flags & ~os.O_NONBLOCK) | |
def make_stdio_blocking(): | |
""" | |
Makes stdout and stderr blocking. | |
This prevents resource contention issues with Selenium subprocesses. | |
See https://github.com/cobrateam/splinter/issues/257 | |
""" | |
# Use __stderr__ attribute since sys.stderr can be patched by the test | |
# runner. | |
_make_fd_blocking(sys.__stderr__) | |
_make_fd_blocking(sys.__stdout__) | |
class SeleniumTestCase(unittest.TestCase): | |
def setUp(self): | |
self.selenium = phantomjs.webdriver.WebDriver() | |
make_stdio_blocking() | |
def tearDown(self): | |
self.selenium.quit() | |
def test_that_something_fails(self): | |
self.selenium.get('https://www.google.com') | |
print repr(self.selenium.get_log('browser')) | |
print repr(self.selenium.get_log('har')) | |
raise AssertionError() | |
class QuitEarlySeleniumTestCase(unittest.TestCase): | |
def setUp(self): | |
self.selenium = phantomjs.webdriver.WebDriver() | |
make_stdio_blocking() | |
def test_that_something_fails(self): | |
self.selenium.get('https://www.google.com') | |
s1 = repr(self.selenium.get_log('browser')) | |
s2 = repr(self.selenium.get_log('har')) | |
self.selenium.quit() | |
print s1 | |
print s2 | |
raise AssertionError() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Breaks with the following:
It also breaks using nosetests.