From f5f442cc5d1f178e1b6bbac5133f93639c5658c6 Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Fri, 14 Aug 2015 15:01:53 +0100 Subject: [PATCH] Use existing users for most tests due to the site being shut down for new users --- pages/base.py | 14 +------------- requirements.txt | 1 + tests/conftest.py | 21 ++++++++++++++++++++ tests/test_about_page.py | 4 ++-- tests/test_banner.py | 4 ++-- tests/test_profile.py | 42 +++++++++++++++++----------------------- tests/test_start_page.py | 8 ++++---- variables.json | 9 +++++++++ 8 files changed, 58 insertions(+), 45 deletions(-) create mode 100644 tests/conftest.py create mode 100644 variables.json diff --git a/pages/base.py b/pages/base.py index 03d86e6..0bc7bcb 100644 --- a/pages/base.py +++ b/pages/base.py @@ -1,12 +1,7 @@ -#!/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 urllib2 -import json - from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.action_chains import ActionChains @@ -42,14 +37,7 @@ def is_user_logged_in(self): def username(self): return self.selenium.find_element(*self._username_locator).text - def _create_persona_test_user(self): - response = urllib2.urlopen('http://personatestuser.org/email/').read() - user = json.loads(response) - return user['email'], user['pass'] - - def login(self, email=None, password=None): - if not all([email, password]): - email, password = self._create_persona_test_user() + def login(self, email, password): self.click_login() from browserid import BrowserID pop_up = BrowserID(self.selenium, self.timeout) diff --git a/requirements.txt b/requirements.txt index 0aa843f..2b6ea68 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ execnet==1.1 py==1.4.26 pytest==2.7.0 pytest-mozwebqa +pytest-variables pytest-xdist==1.11 selenium -e git+https://github.com/mozilla/bidpom.git@master#egg=browserid diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..78783eb --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,21 @@ +# 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 json +import urllib2 + +import pytest + + +@pytest.fixture +def existing_user(variables): + return variables['users']['default'] + + +@pytest.fixture +def new_user(variables): + response = urllib2.urlopen('http://personatestuser.org/email/').read() + user = json.loads(response) + return {'email': user['email'], + 'password': user['pass']} diff --git a/tests/test_about_page.py b/tests/test_about_page.py index 685577c..def968f 100644 --- a/tests/test_about_page.py +++ b/tests/test_about_page.py @@ -15,9 +15,9 @@ class TestAboutPage: @nondestructive - def test_about_page_has_proper_layout(self, mozwebqa): + def test_about_page_has_proper_layout(self, mozwebqa, existing_user): start_page = StartPage(mozwebqa) - home_page = start_page.login() + home_page = start_page.login(existing_user['email'], existing_user['password']) about_page = home_page.click_about_nav_link() Assert.true(about_page.is_the_current_url) Assert.equal(about_page.faq_header, 'Frequently Asked Questions', diff --git a/tests/test_banner.py b/tests/test_banner.py index ec20d81..68db620 100644 --- a/tests/test_banner.py +++ b/tests/test_banner.py @@ -17,9 +17,9 @@ class TestBanners: @destructive @pytest.mark.xfail("'affiliates.allizom' in config.getvalue('base_url')", reason="Bug 1053752 - [stage] Newly created banners don't show up on dashboard page") - def test_user_can_create_banner(self, mozwebqa): + def test_user_can_create_banner(self, mozwebqa, existing_user): start_page = StartPage(mozwebqa) - home_page = start_page.login() + home_page = start_page.login(existing_user['email'], existing_user['password']) create_banner_page = home_page.click_create_banner() create_banner_page.choose_category() diff --git a/tests/test_profile.py b/tests/test_profile.py index f88e4bf..89e7ac0 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -7,6 +7,8 @@ from datetime import datetime import pytest +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait from unittestzero import Assert from pages.start_page import StartPage @@ -17,12 +19,11 @@ class TestProfilePage: @destructive - def test_edit_profile_change_display_name(self, mozwebqa): + def test_edit_profile_change_display_name(self, mozwebqa, existing_user): new_username = "Testbot: %s" % (datetime.now()) start_page = StartPage(mozwebqa) - email, password = start_page._create_persona_test_user() - home_page = start_page.login(email, password) + home_page = start_page.login(existing_user['email'], existing_user['password']) profile_page = home_page.click_profile() # verify changing username, update username to include a timestamp @@ -36,7 +37,7 @@ def test_edit_profile_change_display_name(self, mozwebqa): # verify username persists after logging out and then logging back in logged_out = profile_page.logout() - home_page = logged_out.login(email, password) + home_page = logged_out.login(existing_user['email'], existing_user['password']) profile_page = home_page.click_profile() actual_username = profile_page.profile_username @@ -55,13 +56,10 @@ def test_edit_profile_change_display_name(self, mozwebqa): "to 'Affiliate'. Expected 'Affiliate', but returned '%s'" % actual_username) @destructive - def test_edit_profiles_website(self, mozwebqa): + def test_edit_profiles_website(self, mozwebqa, existing_user): start_page = StartPage(mozwebqa) new_url = 'http://wiki.mozilla.org/' + datetime.utcnow().strftime("%s") - - email, password = start_page._create_persona_test_user() - - home_page = start_page.login(email, password) + home_page = start_page.login(existing_user['email'], existing_user['password']) profile_page = home_page.click_profile() # update profile website to include a timestamp @@ -75,7 +73,7 @@ def test_edit_profiles_website(self, mozwebqa): # verify username persists after logging out and then logging back in logged_out = profile_page.logout() - home_page = logged_out.login(email, password) + home_page = logged_out.login(existing_user['email'], existing_user['password']) profile_page = home_page.click_profile() actual_website = profile_page.profile_website @@ -94,9 +92,9 @@ def test_edit_profiles_website(self, mozwebqa): "Expected '', returned '%s'" % actual_website) @destructive - def test_verify_layout_logged_in_user(self, mozwebqa): + def test_verify_layout_logged_in_user(self, mozwebqa, existing_user): start_page = StartPage(mozwebqa) - home_page = start_page.login() + home_page = start_page.login(existing_user['email'], existing_user['password']) edit_page = home_page.click_profile() Assert.true(edit_page.is_stats_section_visible()) @@ -107,18 +105,14 @@ def test_verify_layout_logged_in_user(self, mozwebqa): Assert.true(edit_page.is_stats_clicks_visible()) Assert.not_none(edit_page.stats_clicks, 'Stats clicks is null') Assert.true(edit_page.is_milestones_section_visible()) - Assert.true(edit_page.is_newsletter_form_visible()) @destructive - def test_new_account_creation(self, mozwebqa): + def test_new_account_creation(self, mozwebqa, new_user): start_page = StartPage(mozwebqa) - email, password = start_page._create_persona_test_user() - home_page = start_page.login(email, password) - - Assert.true(home_page.is_user_logged_in) - - logged_out = home_page.logout() - Assert.false(logged_out.is_user_logged_in) - - logged_in = logged_out.login(email, password) - Assert.true(logged_in.is_user_logged_in) + start_page.click_login() + from browserid import BrowserID + pop_up = BrowserID(mozwebqa.selenium, mozwebqa.timeout) + pop_up.sign_in(new_user['email'], new_user['password']) + error = mozwebqa.selenium.find_element(By.CLASS_NAME, 'error') + WebDriverWait(mozwebqa.selenium, mozwebqa.timeout).until( + lambda s: error.text == 'Login failed. Firefox Affiliates has stopped accepting new users.') diff --git a/tests/test_start_page.py b/tests/test_start_page.py index 3a9a113..15417c7 100644 --- a/tests/test_start_page.py +++ b/tests/test_start_page.py @@ -18,14 +18,14 @@ class TestStartPage: def test_start_page_has_proper_titles(self, mozwebqa): start_page = StartPage(mozwebqa) Assert.true(start_page.is_the_current_page) - Assert.equal(start_page.header, 'Become a Firefox Affiliate today!') + Assert.equal(start_page.header, 'Important Notice: Firefox Affiliates is being discontinued') @nondestructive - def test_login_logout_works_properly(self, mozwebqa): + def test_login_logout_works_properly(self, mozwebqa, existing_user): start_page = StartPage(mozwebqa) - home_page = start_page.login() + home_page = start_page.login(existing_user['email'], existing_user['password']) Assert.true(home_page.is_user_logged_in, 'User not logged in') Assert.equal(home_page.header, 'Dashboard') home_page.logout() Assert.false(home_page.is_user_logged_in, 'User logged in') - Assert.equal(start_page.header, 'Become a Firefox Affiliate today!') + Assert.equal(start_page.header, 'Important Notice: Firefox Affiliates is being discontinued') diff --git a/variables.json b/variables.json new file mode 100644 index 0000000..4ae4416 --- /dev/null +++ b/variables.json @@ -0,0 +1,9 @@ +{ + "users": { + "default": { + "email": "", + "password": "", + "name": "" + } + } +}