Skip to content

Commit

Permalink
Add url support as static member
Browse files Browse the repository at this point in the history
Add help to nose plugin
  • Loading branch information
Igor Khrol committed Mar 13, 2015
1 parent 2c35026 commit 605915a
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 22 deletions.
9 changes: 4 additions & 5 deletions README.md
Expand Up @@ -22,11 +22,10 @@ from webium import BasePage, Find, Finds


class GooglePage(BasePage):
input = Find(by=By.NAME, value='q')
button = Find(by=By.NAME, value='btnK')
url = 'http://www.google.com'

def __init__(self):
super(GooglePage, self).__init__(url='http://www.google.com')
text_field = Find(by=By.NAME, value='q')
button = Find(by=By.NAME, value='btnK')


class ResultItem(WebElement):
Expand All @@ -41,7 +40,7 @@ class ResultsPage(BasePage):
if __name__ == '__main__':
home_page = GooglePage()
home_page.open()
home_page.input.send_keys('Page Object')
home_page.text_field.send_keys('Page Object')
home_page.button.click()
results_page = ResultsPage()
print 'Results summary: %s' % results_page.stat.text
Expand Down
2 changes: 2 additions & 0 deletions docs/base_page.rst
Expand Up @@ -11,6 +11,8 @@ url
If your page has static url you can specify it in ``__init__``.
After that you can use ``open()`` method to open your page.

url can be also defined as static attribute of your class.

.. literalinclude:: ../examples/3_base_page_with_url.py

driver
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -54,9 +54,9 @@
# built documents.
#
# The short X.Y version.
version = '1.0.0'
version = '1.0.6'
# The full version, including alpha/beta/rc tags.
release = '1.0.0'
release = '1.0.6'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
9 changes: 4 additions & 5 deletions examples/1_basic_google.py
Expand Up @@ -6,11 +6,10 @@


class GooglePage(BasePage):
input = Find(by=By.NAME, value='q')
button = Find(by=By.NAME, value='btnK')
url = 'http://www.google.com'

def __init__(self):
super(GooglePage, self).__init__(url='http://www.google.com')
text_field = Find(by=By.NAME, value='q')
button = Find(by=By.NAME, value='btnK')


class ResultItem(WebElement):
Expand All @@ -25,7 +24,7 @@ class ResultsPage(BasePage):
if __name__ == '__main__':
home_page = GooglePage()
home_page.open()
home_page.input.send_keys('Page Object')
home_page.text_field.send_keys('Page Object')
home_page.button.click()
results_page = ResultsPage()
print 'Results summary: %s' % results_page.stat.text
Expand Down
Empty file modified generate_docs.sh 100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions setup.py
@@ -1,6 +1,6 @@
from setuptools import setup

version = '1.0.5'
version = '1.0.6'

setup(
name='webium',
Expand All @@ -24,7 +24,7 @@
'like Link, Button and group them as pages.',
install_requires=[
'selenium',
'waiting',
'waiting>=1.2.1',
],
entry_points={
'nose.plugins': ['browser_closer = webium.plugins.browser_closer:BrowserCloserPlugin'],
Expand Down
15 changes: 13 additions & 2 deletions tests/test_base_page.py
@@ -1,14 +1,25 @@
from unittest import TestCase
from nose.tools import assert_raises
from nose.tools import assert_raises, eq_
import tests
from webium.base_page import BasePage
from webium.driver import get_driver
from webium.errors import WebiumException


class PageWithoutUrl(BasePage):
pass


class TestWithStaticUrl(BasePage):
url = tests.get_url('simple_page.html')


class TestNoUrlValidation(TestCase):
def test_no_url_validation(self):
page = PageWithoutUrl()
assert_raises(WebiumException, page.open)
assert_raises(WebiumException, page.open)

def test_static_url(self):
page = TestWithStaticUrl()
page.open()
eq_(get_driver().title, 'Hello Webium')
5 changes: 4 additions & 1 deletion webium/base_page.py
Expand Up @@ -34,14 +34,17 @@ def is_displayed():


class BasePage(object):
url = None

@property
def _driver(self):
if self.__driver:
return self.__driver
return get_driver()

def __init__(self, driver=None, url=None):
self.url = url
if url:
self.url = url
self.__driver = driver
self.is_element_present = MethodType(is_element_present, self)

Expand Down
15 changes: 10 additions & 5 deletions webium/plugins/browser_closer.py
@@ -1,3 +1,4 @@
import os
from nose.plugins import Plugin
from webium.driver import close_driver

Expand All @@ -11,11 +12,15 @@ class BrowserCloserPlugin(Plugin):
enabled = True
name = 'browser_closer'

def options(self, parser, env):
parser.add_option("--whenclose", action="store",
default='after_test',
dest="browser_closer_when",
metavar="STR",)
def options(self, parser, env=None):
env = env or os.environ
parser.add_option('--whenclose', action='store',
default=env.get('WEBIUM_WHEN_CLOSE', 'after_test'),
dest='browser_closer_when',
metavar='STR',
help='When browser is closed (after_test, after_all). \
Example: --whenclose after_all \
Default: after_test or env variable [WEBIUM_WHEN_CLOSE]')

def configure(self, options, conf):
"""Configure plugin. Plugin is enabled by default.
Expand Down

0 comments on commit 605915a

Please sign in to comment.