Skip to content

Instantly share code, notes, and snippets.

@casschin
Created May 24, 2013 23:20
Show Gist options
  • Save casschin/5647164 to your computer and use it in GitHub Desktop.
Save casschin/5647164 to your computer and use it in GitHub Desktop.
Abridged version of Mozilla based page tests
#!/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.common.by import By
from pages.desktop.base import Base
class MozillaBasedPage(Base):
def go_to_page(self):
self.open('/about/mozilla-based/')
product_link_list_1 = [
{
'locator': (By.CSS_SELECTOR, 'ul.productlist > li:nth-of-type(1) > h3 > a'),
'url_suffix': 'http://www.adobe.com/products/acrobat/',
}, {
'locator': (By.CSS_SELECTOR, 'ul.productlist > li:nth-of-type(2) > h3 > a'),
'url_suffix': 'http://www.amplesdk.com/',
}, {
'locator': (By.CSS_SELECTOR, 'ul.productlist > li:nth-of-type(15) > h3 > a'),
'url_suffix': 'http://www.cyclone3.org/',
},
]
product_link_list_2 = [
{
'locator': (By.CSS_SELECTOR, 'ul.productlist > li:nth-of-type(16) > h3 > a'),
'url_suffix': 'http://www.webdevelopers.eu/',
}, {
'locator': (By.CSS_SELECTOR, 'ul.productlist > li:nth-of-type(17) > h3 > a'),
'url_suffix': 'http://developer.emusic.com/',
}, {
'locator': (By.CSS_SELECTOR, 'ul.productlist > li:nth-of-type(30) > h3 > a'),
'url_suffix': 'http://instantbird.com/',
},
]
#!/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 requests
import pytest
from pages.desktop.mozillabased import MozillaBasedPage
from unittestzero import Assert
from BeautifulSoup import BeautifulStoneSoup
class TestMozillaBasedPagePage:
@pytest.mark.nondestructive
@pytest.mark.parametrize('product_link_list', [product_link_list_1, product_link_list_2])
def test_product_link_urls_are_valid_alt(self, mozwebqa, product_link_list):
mozillabased_page = MozillaBasedPage(mozwebqa)
mozillabased_page.go_to_page()
bad_urls = []
for link in product_link_list:
url = mozillabased_page.link_destination(link.get('locator'))
response_code = mozillabased_page.get_response_code(url)
if response_code != requests.codes.ok:
bad_urls.append('%s is not a valid url - status code: %s.' % (url, response_code))
Assert.equal(0, len(bad_urls), '%s bad urls found: ' % len(bad_urls) + ', '.join(bad_urls))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment