This repository has been archived by the owner on Aug 20, 2018. It is now read-only.
forked from mozilla/bidpom
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 695a853
Showing
11 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.pyc | ||
*.komodoproject |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/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 selenium | ||
|
||
|
||
class BrowserID(object): | ||
|
||
def __init__(self, selenium, timeout=60): | ||
self.selenium = selenium | ||
self.timeout = timeout | ||
|
||
def sign_in(self, email, password): | ||
"""Signs in using the specified email address and password.""" | ||
if isinstance(self.selenium, selenium.selenium): | ||
from pages.rc.sign_in import SignIn | ||
else: | ||
from pages.webdriver.sign_in import SignIn | ||
sign_in = SignIn(self.selenium, timeout=self.timeout) | ||
sign_in.sign_in(email, password) |
Empty file.
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/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 selenium.webdriver.common.by import By | ||
|
||
|
||
class Base(object): | ||
|
||
_page_title = 'Browser ID' | ||
|
||
def __init__(self, selenium, timeout=60): | ||
self.selenium = selenium | ||
self.timeout = timeout | ||
if selenium.get_title != self._page_title: | ||
self.wait_for_popup() | ||
selenium.select_pop_up(self._page_title) | ||
|
||
def wait_for_popup(self): | ||
count = 0 | ||
while not self._page_title in self.selenium.get_all_window_titles(): | ||
time.sleep(1) | ||
count += 1 | ||
if count == self.timeout: | ||
raise Exception('Popup has not loaded') | ||
|
||
def wait_for_element_present(self, element): | ||
count = 0 | ||
while not self.selenium.is_element_present(element): | ||
time.sleep(1) | ||
count += 1 | ||
if count == self.timeout: | ||
raise Exception(element + ' has not loaded') | ||
|
||
def wait_for_element_visible(self, element): | ||
self.wait_for_element_present(element) | ||
count = 0 | ||
while not self.selenium.is_visible(element): | ||
time.sleep(1) | ||
count += 1 | ||
if count == self.timeout: | ||
raise Exception(element + ' is not visible') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/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/. | ||
|
||
from base import Base | ||
|
||
|
||
class SignIn(Base): | ||
|
||
_email_locator = 'id=email' | ||
_password_locator = 'id=password' | ||
_next_locator = 'css=button.start' | ||
_select_email_locator = 'css=button.returning' | ||
_sign_in_locator = 'id=signInButton' | ||
|
||
@property | ||
def email(self): | ||
"""Get the value of the email field.""" | ||
self.wait_for_element_visible(self._email_locator) | ||
return self.selenium.get_text(self._email_locator) | ||
|
||
@email.setter | ||
def email(self, value): | ||
"""Set the value of the email field.""" | ||
self.wait_for_element_visible(self._email_locator) | ||
self.selenium.type(self._email_locator, value) | ||
|
||
@property | ||
def password(self): | ||
"""Get the value of the password field.""" | ||
self.wait_for_element_visible(self._password_locator) | ||
return self.selenium.get_text(self._password_locator) | ||
|
||
@password.setter | ||
def password(self, value): | ||
"""Set the value of the password field.""" | ||
self.wait_for_element_visible(self._password_locator) | ||
self.selenium.type(self._password_locator, value) | ||
|
||
def click_next(self): | ||
"""Clicks the 'next' button.""" | ||
self.wait_for_element_visible(self._next_locator) | ||
self.selenium.click(self._next_locator) | ||
|
||
def click_select_email(self): | ||
"""Clicks the 'select email' button.""" | ||
self.wait_for_element_visible(self._select_email_locator) | ||
self.selenium.click(self._select_email_locator) | ||
|
||
def click_sign_in(self): | ||
"""Clicks the 'Sign In' button.""" | ||
self.wait_for_element_visible(self._sign_in_locator) | ||
self.selenium.click(self._sign_in_locator) | ||
self.selenium.deselect_pop_up() | ||
|
||
def sign_in(self, email, password): | ||
"""Signs in using the specified email address and password.""" | ||
self.email = email | ||
self.click_next() | ||
self.password = password | ||
self.click_select_email() | ||
self.click_sign_in() |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/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/. | ||
|
||
from selenium.webdriver.support.ui import WebDriverWait | ||
|
||
|
||
class Base(object): | ||
|
||
_page_title = 'Browser ID' | ||
|
||
def __init__(self, selenium, timeout=60): | ||
self.selenium = selenium | ||
self.timeout = timeout | ||
if selenium.title != self._page_title: | ||
for handle in selenium.window_handles: | ||
selenium.switch_to_window(handle) | ||
if selenium.title == self._page_title: | ||
break | ||
|
||
def wait_for_element_displayed(self, locator): | ||
WebDriverWait(self.selenium, self.timeout).until(lambda s: s.find_element(*locator).is_displayed()) | ||
return self.selenium.find_element(*locator) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/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/. | ||
|
||
from base import Base | ||
|
||
from selenium.webdriver.common.by import By | ||
|
||
|
||
class SignIn(Base): | ||
|
||
_email_locator = (By.ID, 'email') | ||
_password_locator = (By.ID, 'password') | ||
_next_locator = (By.CSS_SELECTOR, 'button.start') | ||
_select_email_locator = (By.CSS_SELECTOR, 'button.returning') | ||
_sign_in_locator = (By.ID, 'signInButton') | ||
|
||
@property | ||
def email(self): | ||
"""Get the value of the email field.""" | ||
return self.wait_for_element_displayed(self._email_locator).text | ||
|
||
@email.setter | ||
def email(self, value): | ||
"""Set the value of the email field.""" | ||
email = self.wait_for_element_displayed(self._email_locator) | ||
email.clear() | ||
email.send_keys(value) | ||
|
||
@property | ||
def password(self): | ||
"""Get the value of the password field.""" | ||
return self.wait_for_element_displayed(self._password_locator).text | ||
|
||
@password.setter | ||
def password(self, value): | ||
"""Set the value of the password field.""" | ||
password = self.wait_for_element_displayed(self._password_locator) | ||
password.clear() | ||
password.send_keys(value) | ||
|
||
def click_next(self): | ||
"""Clicks the 'next' button.""" | ||
self.wait_for_element_displayed(self._next_locator).click() | ||
|
||
def click_select_email(self): | ||
"""Clicks the 'select email' button.""" | ||
self.wait_for_element_displayed(self._select_email_locator).click() | ||
|
||
def click_sign_in(self): | ||
"""Clicks the 'Sign In' button.""" | ||
self.wait_for_element_displayed(self._sign_in_locator).click() | ||
self.selenium.switch_to_window('') | ||
|
||
def sign_in(self, email, password): | ||
"""Signs in using the specified email address and password.""" | ||
self.email = email | ||
self.click_next() | ||
self.password = password | ||
self.click_select_email() | ||
self.click_sign_in() |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/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 browser_id 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() | ||
|
||
# BrowserID | ||
browser_id = BrowserID(sel) | ||
browser_id.sign_in(self._email, self._password) | ||
|
||
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('/') | ||
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() |