Created
August 1, 2013 19:02
-
-
Save fleaplus/6134212 to your computer and use it in GitHub Desktop.
Playing with python/selenium!
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
from selenium import webdriver | |
from selenium.common.exceptions import NoSuchElementException | |
import time | |
import unittest | |
class ATest(unittest.TestCase): | |
def setUp(self): | |
self.browser = webdriver.Firefox() # Get local session of firefox | |
def tearDown(self): | |
self.browser.close() | |
def test_atest(self): | |
self.browser.get("http://www.awwaterservice.com") # Load page | |
assert "A&W Water" in self.browser.title | |
elem = self.browser.find_element_by_link_text("Services").click() # Find the services link in the navbar and click it | |
time.sleep(0.2) # Let the page load, will be added to the API | |
try: | |
self.browser.find_element_by_xpath("//img[contains(@alt,'Company Information')]") # verify an element is on the page | |
except NoSuchElementException: | |
assert 0, "can't find Company Information image in Services section" | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use selenium with webdriver, maven and phantom js for unit testing (i believe thats the type of tests) for variables that occur when the page loads mainly in the dataLayer for adobe analytics tracking purposes for customer experience performance of pages at work. Was curious if there are benefits of using python vs using PhantomJS with selenium - bc I am currently looking at automating it and Jenkins seems to be more of a legacy platform to use for this (bc in the setup and class I took to learn about it the stack was PhantomJS (ghost driver), Maven, Selenium and Jenkins using a raspberry Pi for automated testing/crawling of pages to check for variables existing on pages). I'm not a developer or programmer by any means but was curious before I took this a step further to proactively check if you knew possibly if Python would be a better stack to use with it. Sorry if my communication skills on this are a little fuzzy/confusing! Thanks in advance!