Skip to content

Instantly share code, notes, and snippets.

@kensykora
Last active August 29, 2015 14:09
Show Gist options
  • Save kensykora/a6356d057f90860c6eef to your computer and use it in GitHub Desktop.
Save kensykora/a6356d057f90860c6eef to your computer and use it in GitHub Desktop.
Selenium Test Script
# -*- coding: utf-8 -*-
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium import webdriver
import unittest
class TestGatherer(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(2)
self.base_url = "http://gatherer.wizards.com/"
self.verificationErrors = []
def test_gatherer(self):
driver = self.driver
driver.get(self.base_url)
driver.find_element_by_id("ctl00_ctl00_MainContent_Content_SearchControls_searchSubmitButton").click()
WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.ID, "ctl00_ctl00_MainContent_Content_SearchControls_CardSearchBoxParent_CardSearchBox")))
driver.find_element_by_id("ctl00_ctl00_MainContent_Content_SearchControls_CardSearchBoxParent_CardSearchBox").clear()
driver.find_element_by_id("ctl00_ctl00_MainContent_Content_SearchControls_CardSearchBoxParent_CardSearchBox").send_keys('Kongming, "Sleeping Dragon"')
driver.find_element_by_id("ctl00_ctl00_MainContent_Content_SearchControls_searchSubmitButton").click()
WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.ID, "ctl00_ctl00_ctl00_MainContent_SubContent_SubContent_nameRow")))
try:
self.assertEqual("Kongming, \"Sleeping Dragon\"",
driver.find_element_by_css_selector("#ctl00_ctl00_ctl00_MainContent_SubContent_SubContent_nameRow > div.value").text)
except AssertionError as e:
self.verificationErrors.append(str(e))
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment