Skip to content

Instantly share code, notes, and snippets.

@poliarush
Last active August 29, 2015 14:07
Show Gist options
  • Save poliarush/701fcb5990b9c89fabb3 to your computer and use it in GitHub Desktop.
Save poliarush/701fcb5990b9c89fabb3 to your computer and use it in GitHub Desktop.
Pyhon parallel run exeuciont via py.test for selenium webdriver
py.test -n 2 .
============================= test session starts =============================
platform win32 -- Python 2.7.3 -- pytest-2.5.1
plugins: xdist
gw0 [3] / gw1 [3]
scheduling tests via LoadScheduling
...
========================== 3 passed in 48.16 seconds ==========================
from selenium import webdriver
import time
class Driver(object):
_instance = None
@classmethod
def get(cls):
if not getattr(cls, '_instance'):
cls._instance = webdriver.Firefox()
return cls._instance
@classmethod
def close(cls):
cls.get().quit()
cls._instance = None
class PageObjectTwo(object):
def action(self):
print Driver.get().title
class PageObjectOne(object):
def __init__(self, url):
self.url = url
def open(self):
Driver.get().get(self.url)
time.sleep(2)
return PageObjectTwo()
def close(self):
Driver.close()
class TestSampleTestSuite:
def test_1(self):
page = PageObjectOne('http://lessons2.ru')
another_page = page.open()
another_page.action()
page.close()
def test_2(self):
page = PageObjectOne('http://automated-testing.info')
page.open()
PageObjectTwo().action()
page.close()
def test_3(self):
page = PageObjectOne('http://poliarush.com')
page.open()
page.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment