Skip to content

Instantly share code, notes, and snippets.

@davehunt
Created December 1, 2011 13:27
Show Gist options
  • Save davehunt/1416716 to your computer and use it in GitHub Desktop.
Save davehunt/1416716 to your computer and use it in GitHub Desktop.
pytest issue 93 example test case

install required python modules

sudo pip install pytest pytest-xdist selenium

download selenium server

curl http://selenium.googlecode.com/files/selenium-server-standalone-2.14.0.jar -o selenium-server-standalone-2.14.0.jar

start selenium grid hub

java -cp selenium-server-standalone-2.14.0.jar org.openqa.grid.selenium.GridLauncher -role hub

start selenium grid node

java -cp selenium-server-standalone-2.14.0.jar org.openqa.grid.selenium.GridLauncher -role node -hubHost localhost -hubPort 4444 -host localhost

passing test case (without queuing)

py.test -n 5 test_issue_93.py

failing test case (with queuing)

py.test -n 6 test_issue_93.py

notes

  • The failing test case will eventually time out (after 5 minutes)
  • Firefox must be installed in a predictable location
  • A default of 5 Firefox instances is supported, therefore -n 5 will not queue but -n 6 will
from selenium import selenium
def pytest_runtest_setup(item):
TestSetup.selenium = selenium('localhost', 4444, '*firefox', 'http://example.com')
TestSetup.selenium.start()
def pytest_runtest_teardown(item):
TestSetup.selenium.stop()
def pytest_funcarg__testsetup(request):
return TestSetup(request)
class TestSetup:
def __init__(self, request):
self.request = request
py.test -n 6 test_issue_93.py
===================================================== test session starts ======================================================
platform darwin -- Python 2.7.1 -- pytest-2.2.0
gw0 [6] / gw1 [6] / gw2 [6] / gw3 [6] / gw4 [6] / gw5 [6]
scheduling tests via LoadScheduling
......EEEEE
============================================================ ERRORS ============================================================
_______________________________________ ERROR at teardown of TestIssue93.test_issue_93_3 _______________________________________
[gw3] darwin -- Python 2.7.1 /Users/dave/.virtualenvs/pytest-issue-93/bin/python
item = <Function 'test_issue_93_3'>
def pytest_runtest_teardown(item):
> TestSetup.selenium.stop()
conftest.py:11:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.selenium.selenium object at 0x101c03210>
def stop(self):
> self.do_command("testComplete", [])
../../.virtualenvs/pytest-issue-93/lib/python2.7/site-packages/selenium/selenium.py:193:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.selenium.selenium object at 0x101c03210>, verb = 'testComplete'
args = []
def do_command(self, verb, args):
conn = httplib.HTTPConnection(self.host, self.port)
try:
body = u'cmd=' + urllib.quote_plus(unicode(verb).encode('utf-8'))
for i in range(len(args)):
body += '&' + unicode(i+1) + '=' + \
urllib.quote_plus(unicode(args[i]).encode('utf-8'))
if (None != self.sessionId):
body += "&sessionId=" + unicode(self.sessionId)
headers = {
"Content-Type":
"application/x-www-form-urlencoded; charset=utf-8"
}
conn.request("POST", "/selenium-server/driver/", body, headers)
response = conn.getresponse()
data = unicode(response.read(), "UTF-8")
if (not data.startswith('OK')):
> raise Exception, data
E Exception: <html>
E <head>
E <title>Error 500 org.openqa.grid.common.exception.GridException: Session [804d4ef8341d449d9dcd68edf142a16d] not available - [ext. key 057f2cddf4a44654ace6df7a255e851f]</title>
E </head>
E <body>
E <h2>HTTP ERROR: 500</h2><pre>org.openqa.grid.common.exception.GridException: Session [804d4ef8341d449d9dcd68edf142a16d] not available - [ext. key 057f2cddf4a44654ace6df7a255e851f]</pre>
E <p>RequestURI=/selenium-server/driver/</p>
E <p><i><small><a href="http://jetty.mortbay.org">Powered by Jetty://</a></small></i></p>
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E </body>
E </html>
../../.virtualenvs/pytest-issue-93/lib/python2.7/site-packages/selenium/selenium.py:214: Exception
_______________________________________ ERROR at teardown of TestIssue93.test_issue_93_1 _______________________________________
[gw4] darwin -- Python 2.7.1 /Users/dave/.virtualenvs/pytest-issue-93/bin/python
item = <Function 'test_issue_93_1'>
def pytest_runtest_teardown(item):
> TestSetup.selenium.stop()
conftest.py:11:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.selenium.selenium object at 0x10bd76210>
def stop(self):
> self.do_command("testComplete", [])
../../.virtualenvs/pytest-issue-93/lib/python2.7/site-packages/selenium/selenium.py:193:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.selenium.selenium object at 0x10bd76210>, verb = 'testComplete'
args = []
def do_command(self, verb, args):
conn = httplib.HTTPConnection(self.host, self.port)
try:
body = u'cmd=' + urllib.quote_plus(unicode(verb).encode('utf-8'))
for i in range(len(args)):
body += '&' + unicode(i+1) + '=' + \
urllib.quote_plus(unicode(args[i]).encode('utf-8'))
if (None != self.sessionId):
body += "&sessionId=" + unicode(self.sessionId)
headers = {
"Content-Type":
"application/x-www-form-urlencoded; charset=utf-8"
}
conn.request("POST", "/selenium-server/driver/", body, headers)
response = conn.getresponse()
data = unicode(response.read(), "UTF-8")
if (not data.startswith('OK')):
> raise Exception, data
E Exception: <html>
E <head>
E <title>Error 500 org.openqa.grid.common.exception.GridException: Session [2c930eb511e4486097a35dc1ff632229] not available - [ext. key 057f2cddf4a44654ace6df7a255e851f]</title>
E </head>
E <body>
E <h2>HTTP ERROR: 500</h2><pre>org.openqa.grid.common.exception.GridException: Session [2c930eb511e4486097a35dc1ff632229] not available - [ext. key 057f2cddf4a44654ace6df7a255e851f]</pre>
E <p>RequestURI=/selenium-server/driver/</p>
E <p><i><small><a href="http://jetty.mortbay.org">Powered by Jetty://</a></small></i></p>
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E </body>
E </html>
../../.virtualenvs/pytest-issue-93/lib/python2.7/site-packages/selenium/selenium.py:214: Exception
_______________________________________ ERROR at teardown of TestIssue93.test_issue_93_4 _______________________________________
[gw1] darwin -- Python 2.7.1 /Users/dave/.virtualenvs/pytest-issue-93/bin/python
item = <Function 'test_issue_93_4'>
def pytest_runtest_teardown(item):
> TestSetup.selenium.stop()
conftest.py:11:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.selenium.selenium object at 0x10224e210>
def stop(self):
> self.do_command("testComplete", [])
../../.virtualenvs/pytest-issue-93/lib/python2.7/site-packages/selenium/selenium.py:193:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.selenium.selenium object at 0x10224e210>, verb = 'testComplete'
args = []
def do_command(self, verb, args):
conn = httplib.HTTPConnection(self.host, self.port)
try:
body = u'cmd=' + urllib.quote_plus(unicode(verb).encode('utf-8'))
for i in range(len(args)):
body += '&' + unicode(i+1) + '=' + \
urllib.quote_plus(unicode(args[i]).encode('utf-8'))
if (None != self.sessionId):
body += "&sessionId=" + unicode(self.sessionId)
headers = {
"Content-Type":
"application/x-www-form-urlencoded; charset=utf-8"
}
conn.request("POST", "/selenium-server/driver/", body, headers)
response = conn.getresponse()
data = unicode(response.read(), "UTF-8")
if (not data.startswith('OK')):
> raise Exception, data
E Exception: <html>
E <head>
E <title>Error 500 org.openqa.grid.common.exception.GridException: Session [8dd144b8eb8344f18122be9f0ec51bc1] not available - [ext. key 057f2cddf4a44654ace6df7a255e851f]</title>
E </head>
E <body>
E <h2>HTTP ERROR: 500</h2><pre>org.openqa.grid.common.exception.GridException: Session [8dd144b8eb8344f18122be9f0ec51bc1] not available - [ext. key 057f2cddf4a44654ace6df7a255e851f]</pre>
E <p>RequestURI=/selenium-server/driver/</p>
E <p><i><small><a href="http://jetty.mortbay.org">Powered by Jetty://</a></small></i></p>
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E </body>
E </html>
../../.virtualenvs/pytest-issue-93/lib/python2.7/site-packages/selenium/selenium.py:214: Exception
_______________________________________ ERROR at teardown of TestIssue93.test_issue_93_6 _______________________________________
[gw2] darwin -- Python 2.7.1 /Users/dave/.virtualenvs/pytest-issue-93/bin/python
item = <Function 'test_issue_93_6'>
def pytest_runtest_teardown(item):
> TestSetup.selenium.stop()
conftest.py:11:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.selenium.selenium object at 0x103f72210>
def stop(self):
> self.do_command("testComplete", [])
../../.virtualenvs/pytest-issue-93/lib/python2.7/site-packages/selenium/selenium.py:193:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.selenium.selenium object at 0x103f72210>, verb = 'testComplete'
args = []
def do_command(self, verb, args):
conn = httplib.HTTPConnection(self.host, self.port)
try:
body = u'cmd=' + urllib.quote_plus(unicode(verb).encode('utf-8'))
for i in range(len(args)):
body += '&' + unicode(i+1) + '=' + \
urllib.quote_plus(unicode(args[i]).encode('utf-8'))
if (None != self.sessionId):
body += "&sessionId=" + unicode(self.sessionId)
headers = {
"Content-Type":
"application/x-www-form-urlencoded; charset=utf-8"
}
conn.request("POST", "/selenium-server/driver/", body, headers)
response = conn.getresponse()
data = unicode(response.read(), "UTF-8")
if (not data.startswith('OK')):
> raise Exception, data
E Exception: <html>
E <head>
E <title>Error 500 org.openqa.grid.common.exception.GridException: Session [18f3ca5969f046cc924c5b51693d205b] not available - [ext. key 057f2cddf4a44654ace6df7a255e851f]</title>
E </head>
E <body>
E <h2>HTTP ERROR: 500</h2><pre>org.openqa.grid.common.exception.GridException: Session [18f3ca5969f046cc924c5b51693d205b] not available - [ext. key 057f2cddf4a44654ace6df7a255e851f]</pre>
E <p>RequestURI=/selenium-server/driver/</p>
E <p><i><small><a href="http://jetty.mortbay.org">Powered by Jetty://</a></small></i></p>
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E </body>
E </html>
../../.virtualenvs/pytest-issue-93/lib/python2.7/site-packages/selenium/selenium.py:214: Exception
_______________________________________ ERROR at teardown of TestIssue93.test_issue_93_2 _______________________________________
[gw5] darwin -- Python 2.7.1 /Users/dave/.virtualenvs/pytest-issue-93/bin/python
item = <Function 'test_issue_93_2'>
def pytest_runtest_teardown(item):
> TestSetup.selenium.stop()
conftest.py:11:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.selenium.selenium object at 0x104520210>
def stop(self):
> self.do_command("testComplete", [])
../../.virtualenvs/pytest-issue-93/lib/python2.7/site-packages/selenium/selenium.py:193:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.selenium.selenium object at 0x104520210>, verb = 'testComplete'
args = []
def do_command(self, verb, args):
conn = httplib.HTTPConnection(self.host, self.port)
try:
body = u'cmd=' + urllib.quote_plus(unicode(verb).encode('utf-8'))
for i in range(len(args)):
body += '&' + unicode(i+1) + '=' + \
urllib.quote_plus(unicode(args[i]).encode('utf-8'))
if (None != self.sessionId):
body += "&sessionId=" + unicode(self.sessionId)
headers = {
"Content-Type":
"application/x-www-form-urlencoded; charset=utf-8"
}
conn.request("POST", "/selenium-server/driver/", body, headers)
response = conn.getresponse()
data = unicode(response.read(), "UTF-8")
if (not data.startswith('OK')):
> raise Exception, data
E Exception: <html>
E <head>
E <title>Error 500 org.openqa.grid.common.exception.GridException: Session [e6158fb5b3304e9ca8eca4a7b3922487] not available - [ext. key 057f2cddf4a44654ace6df7a255e851f]</title>
E </head>
E <body>
E <h2>HTTP ERROR: 500</h2><pre>org.openqa.grid.common.exception.GridException: Session [e6158fb5b3304e9ca8eca4a7b3922487] not available - [ext. key 057f2cddf4a44654ace6df7a255e851f]</pre>
E <p>RequestURI=/selenium-server/driver/</p>
E <p><i><small><a href="http://jetty.mortbay.org">Powered by Jetty://</a></small></i></p>
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E </body>
E </html>
../../.virtualenvs/pytest-issue-93/lib/python2.7/site-packages/selenium/selenium.py:214: Exception
============================================= 6 passed, 5 error in 347.53 seconds ==============================================
class TestIssue93:
def test_issue_93_1(self, testsetup):
testsetup.selenium.set_context('1')
def test_issue_93_2(self, testsetup):
testsetup.selenium.set_context('2')
def test_issue_93_3(self, testsetup):
testsetup.selenium.set_context('3')
def test_issue_93_4(self, testsetup):
testsetup.selenium.set_context('4')
def test_issue_93_5(self, testsetup):
testsetup.selenium.set_context('5')
def test_issue_93_6(self, testsetup):
testsetup.selenium.set_context('6')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment