Created
April 17, 2013 07:21
-
-
Save billagee/5402386 to your computer and use it in GitHub Desktop.
Python unittest demo script that uses Selenium WebDriver and GhostDriver to perform a Google search.
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
#!/usr/bin/env python | |
import unittest | |
from selenium import webdriver | |
class TestGoogleGhostDriver(unittest.TestCase): | |
def setUp(self): | |
# The phantomjs executable is assumed to be in your PATH: | |
self.driver = webdriver.PhantomJS('phantomjs') | |
# Simple test that performs a google search | |
def testGoogleSearch(self): | |
self.driver.get("http://www.google.com") | |
self.assertEqual(u'Google', self.driver.title) | |
# Enter text into the search field | |
self.assertTrue(self.driver.find_element_by_name("q").is_displayed()) | |
self.driver.find_element_by_name("q").send_keys("selenium") | |
# Click the search button | |
self.driver.find_element_by_name("btnG").click() | |
print("current_url is now '%s'" % (self.driver.current_url)) | |
def tearDown(self): | |
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