Created
September 12, 2012 23:34
-
-
Save jsmoxon/3710768 to your computer and use it in GitHub Desktop.
Simple Python Test for use on Sauce Labs
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
import unittest | |
from selenium import webdriver | |
class Selenium2OnSauce(unittest.TestCase): | |
def setUp(self): | |
desired_capabilities = webdriver.DesiredCapabilities.IPHONE | |
desired_capabilities['version'] = '5.0' | |
desired_capabilities['platform'] = 'MAC' | |
desired_capabilities['name'] = 'Testing Selenium 2 in Python at Sauce' | |
self.driver = webdriver.Remote( | |
desired_capabilities=desired_capabilities, | |
command_executor="http://username:API_KEY@ondemand.saucelabs.com:80/wd/hub" | |
) | |
self.driver.implicitly_wait(30) | |
def test_sauce(self): | |
self.driver.get('http://saucelabs.com/test/guinea-pig') | |
self.assertTrue("I am a page title - Sauce Labs" in self.driver.title); | |
self.driver.find_element_by_id('comments').send_keys('Hello! I am some example comments. I should appear in the page after you submit the form') | |
self.driver.find_element_by_id('submit').click() | |
comments = self.driver.find_element_by_id('your_comments') | |
self.assertTrue('Your comments: Hello! I am some example comments. I should appear in the page after you submit the form' in comments.text) | |
body = self.driver.find_element_by_xpath('//body') | |
self.assertFalse('I am some other page content' in body.text) | |
self.driver.find_elements_by_link_text('i am a link')[0].click() | |
body = self.driver.find_element_by_xpath('//body') | |
self.assertTrue('I am some other page content' in body.text) | |
def tearDown(self): | |
print "Link to your job: https://saucelabs.com/jobs/%s" % self.driver.session_id | |
self.driver.quit() | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment