Permalink
Browse files

Replaced examples with working tests.

  • Loading branch information...
1 parent 569cf44 commit d841394af9f09c845571700db799361203b28c5b @davehunt davehunt committed May 20, 2012
View
@@ -1,2 +1,4 @@
*.pyc
*.komodoproject
+build
+results
View
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import py
+
+
+def pytest_runtest_setup(item):
+ pytest_mozwebqa = py.test.config.pluginmanager.getplugin('mozwebqa')
+ pytest_mozwebqa.TestSetup.email = item.config.option.email
+ pytest_mozwebqa.TestSetup.password = item.config.option.password
+
+
+def pytest_addoption(parser):
+ group = parser.getgroup('persona', 'persona')
+ group._addoption('--email',
+ action='store',
+ metavar='str',
+ help='email address for persona account')
+ group._addoption('--password',
+ action='store',
+ metavar='str',
+ help='password for persona account')
+
+
+def pytest_funcarg__mozwebqa(request):
+ return request.getfuncargvalue('mozwebqa')
View
@@ -1,56 +0,0 @@
-#!/usr/bin/env python
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-import time
-
-from .. import BrowserID
-
-from selenium import webdriver
-from selenium import selenium
-
-
-class TestSignIn:
-
- _email = ''
- _password = ''
-
- def test_sign_in_to_my_favorite_beer_using_webdriver(self):
- sel = webdriver.Firefox()
- sel.implicitly_wait(10)
- sel.get('http://myfavoritebeer.org/')
- sel.find_element_by_css_selector('#loginInfo .login').click()
- sel.implicitly_wait(0)
-
- # BrowserID
- browser_id = BrowserID(sel)
- browser_id.sign_in(self._email, self._password)
-
- sel.implicitly_wait(20)
- assert sel.find_element_by_id('logout').is_displayed()
- sel.quit()
-
- def test_sign_in_to_my_favorite_beer_using_rc(self):
- sel = selenium('localhost',
- '4444',
- '*firefox',
- 'http://myfavoritebeer.org')
- sel.start()
- sel.open('/')
- time.sleep(5)
- sel.click('css=#loginInfo .login')
-
- # BrowserID
- browser_id = BrowserID(sel)
- browser_id.sign_in(self._email, self._password)
-
- logout_locator = 'id=logout'
- count = 0
- while count < 60 and not (sel.is_element_present(logout_locator) and
- sel.is_visible(logout_locator)):
- time.sleep(1)
- count += 1
- assert sel.is_visible('id=logout')
- sel.stop()
View
@@ -0,0 +1,3 @@
+[DEFAULT]
+baseurl = http://123done.org
+tags = bidpom
View
@@ -0,0 +1 @@
+pytest-mozwebqa==0.10
View
@@ -0,0 +1,2 @@
+[pytest]
+python_files=check_*.py
File renamed without changes.
View
No changes.
View
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import pytest
+
+
+@pytest.mark.nondestructive
+class TestSignIn:
+
+ def test_sign_in_helper(self, mozwebqa):
+ from ... import BrowserID
+ browser_id = BrowserID(mozwebqa.selenium)
+ browser_id.sign_in(mozwebqa.email, mozwebqa.password)
+
+ logout_locator = 'css=#loggedin a'
+ mozwebqa.wait_for_element_visible(mozwebqa, logout_locator)
+ assert mozwebqa.selenium.is_visible(logout_locator)
+
+ def test_sign_in(self, mozwebqa):
+ from ...pages.rc.sign_in import SignIn
+ signin = SignIn(mozwebqa.selenium, mozwebqa.timeout)
+ signin.email = mozwebqa.email
+ signin.click_next()
+ signin.password = mozwebqa.password
+ signin.click_sign_in()
+
+ logout_locator = 'css=#loggedin a'
+ mozwebqa.wait_for_element_visible(mozwebqa, logout_locator)
+ assert mozwebqa.selenium.is_visible(logout_locator)
View
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import time
+
+
+def pytest_runtest_setup(item):
+ item.config.option.api = 'rc'
+
+
+def pytest_funcarg__mozwebqa(request):
+ mozwebqa = request.getfuncargvalue('mozwebqa')
+ mozwebqa.wait_for_element_visible = wait_for_element_visible
+ mozwebqa.selenium.open('%s/' % mozwebqa.base_url)
+ login_locator = 'css=#loggedout button'
+ wait_for_element_visible(mozwebqa, login_locator)
+ mozwebqa.selenium.click(login_locator)
+ return mozwebqa
+
+def wait_for_element_visible(mozwebqa, locator):
+ count = 0
+ while count < mozwebqa.timeout and not (mozwebqa.selenium.is_visible(locator)):
+ time.sleep(1)
+ count += 1
No changes.
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import pytest
+from selenium.webdriver.support.ui import WebDriverWait
+
+
+@pytest.mark.nondestructive
+class TestSignIn:
+
+ def test_sign_in_helper(self, mozwebqa):
+ from ... import BrowserID
+ browser_id = BrowserID(mozwebqa.selenium, mozwebqa.timeout)
+ browser_id.sign_in(mozwebqa.email, mozwebqa.password)
+
+ WebDriverWait(mozwebqa.selenium, mozwebqa.timeout).until(
+ lambda s: s.find_element_by_id('loggedin').is_displayed())
+
+ def test_sign_in(self, mozwebqa):
+ from ...pages.webdriver.sign_in import SignIn
+ signin = SignIn(mozwebqa.selenium, mozwebqa.timeout)
+ signin.email = mozwebqa.email
+ signin.click_next()
@zacc

zacc May 21, 2012

Contributor

need an explicit wait here!

In my pull I have moved the explicit wait from click_next as the element to wait for differs depending upon which workflow you are going through

@davehunt

davehunt May 21, 2012

Member

The wait should be in the method. If the method should differ depending on your flow then we will need new page objects.

@zacc

zacc May 21, 2012

Contributor

I just changed the wait, it's simpler.

@davehunt

davehunt May 21, 2012

Member

Sure. Once I see the updated pull request I can review the change.

+ signin.password = mozwebqa.password
+ signin.click_sign_in()
+
+ WebDriverWait(mozwebqa.selenium, mozwebqa.timeout).until(
+ lambda s: s.find_element_by_id('loggedin').is_displayed())
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+def pytest_runtest_setup(item):
+ item.config.option.api = 'webdriver'
+
+
+def pytest_funcarg__mozwebqa(request):
+ mozwebqa = request.getfuncargvalue('mozwebqa')
+ mozwebqa.selenium.implicitly_wait(10)
+ mozwebqa.selenium.get('%s/' % mozwebqa.base_url)
+ mozwebqa.selenium.find_element_by_id('loggedout'). \
+ find_element_by_tag_name('button').click()
+ mozwebqa.selenium.implicitly_wait(0)
+ return mozwebqa

0 comments on commit d841394

Please sign in to comment.