def preconditionLoggedIn(self): '''Logs in member if he is logged out, otherwise do nothing.''' selenium = self.selenium selenium.open("/") selenium.wait_for_page_to_load("30000") hasUsername = selenium.is_element_present("//meta[@name='wrook.username']") if not hasUsername: self.doMemberLogsInWithEmailAddress()
def preconditionLoggedOut(self): '''Logs out the member if he is logged in, otherwise do nothing.''' selenium = self.selenium selenium.open("/") selenium.wait_for_page_to_load("30000") hasUsername = selenium.is_element_present("//meta[@name='wrook.username']") if hasUsername: self.doMemberLogout()
def login(self): selenium = self.selenium selenium.open("/") selenium.click("login") selenium.wait_for_page_to_load(5000) selenium.type("email", "*****@*****.**") selenium.click("submit-login") selenium.wait_for_page_to_load(5000)
def Initial(self): try: os.system(config_element.get("setting", "cancel_msta")) selenium.start() selenium.open("/CWMServer/index.jsp") selenium.window_maximize() print "The screen was open - PASS" except: raise Exception("The screen was not open - FAIL")
def do_run(self): selenium = self.selenium for i in range(0,10): selenium.open("/run/example/") self.failUnless(not selenium.is_text_present("Request information")) self.failUnless(selenium.is_text_present("registers")) self.failUnless(selenium.is_text_present("output")) self.failUnless(selenium.is_text_present("1 1 2 3 5 8 13 21 34 55"))
def testMemberVisitHisPublicProfile(self): '''Member visits his public profile. (Via URL)''' selenium = self.selenium self.preconditionLoggedIn() selenium.open("/") selenium.wait_for_page_to_load("30000") selenium.click("sidebarMenu-publicProfile") selenium.wait_for_page_to_load("30000") self.assertEqual("page-members-stories", selenium.get_attribute("//body@id"))
def testHalfBakedEdition(self): ''' Tests the "Half Baked Edition" content page. Test includes acces via the main navigation path from the home page. ''' selenium = self.selenium selenium.open("/") selenium.wait_for_page_to_load("30000") selenium.click("link-halfBaked") selenium.wait_for_page_to_load("30000") self.assertEqual("page-about-HalfBakedEdition", selenium.get_attribute("//body@id"))
def testWhoIsBehindWrook(self): ''' Tests the "Who is behind Wrook" content page. Test includes acces via the main navigation path from the home page. ''' selenium = self.selenium selenium.open("/") selenium.wait_for_page_to_load("30000") selenium.click("menuWho") selenium.wait_for_page_to_load("30000") self.assertEqual("page-about-who", selenium.get_attribute("//body@id"))
def testLinks(self): selenium = self.selenium selenium.open("/selenium-server/tests/html/test_click_page1.html") self.failUnless(selenium.get_text("link").find("Click here for next page") != -1, "link 'link' doesn't contain expected text") links = selenium.get_all_links() self.failUnless(len(links) > 3) self.assertEqual("linkToAnchorOnThisPage", links[3]) selenium.click("link") selenium.wait_for_page_to_load(5000) self.failUnless(selenium.get_location().endswith("/selenium-server/tests/html/test_click_page2.html")) selenium.click("previousPage") selenium.wait_for_page_to_load(5000) self.failUnless(selenium.get_location().endswith("/selenium-server/tests/html/test_click_page1.html"))
def testGoogle__4(self): selenium = self.selenium selenium.open("http://www.google.com/webhp?hl=en") #Verifies that the title matches self.assertEqual ("Google", selenium.get_title()) selenium.type("q", "Selenium OpenQA") #Verifies that it can find the Selenium website self.assertEqual("Selenium OpenQA", selenium.get_value("q")) selenium.click("btnG") selenium.wait_for_page_to_load("5000") self.assertEqual("Selenium OpenQA - Google Search", selenium.get_title())
def testGoogle__4(self): selenium = self.selenium selenium.open("http://www.google.com/webhp?hl=en") #Verifies that the title matches self.assertEqual("Google", selenium.get_title()) selenium.type("q", "Selenium OpenQA") #Verifies that it can find the Selenium website self.assertEqual("Selenium OpenQA", selenium.get_value("q")) selenium.click("btnG") selenium.wait_for_page_to_load("5000") self.assertEqual("Selenium OpenQA - Google Search", selenium.get_title())
def testKeyPress(self): selenium = self.selenium input_id = 'ac4' update_id = 'ac4update' selenium.open("http://www.irian.at/selenium-server/tests/html/ajax/ajax_autocompleter2_test.html") selenium.key_press(input_id, 74) time.sleep(0.5) selenium.key_press(input_id, 97) selenium.key_press(input_id, 110) time.sleep(0.5) self.failUnless('Jane Agnews' == selenium.get_text(update_id)) selenium.key_press(input_id, '\9') time.sleep(0.5) self.failUnless('Jane Agnews' == selenium.get_value(input_id))
def test_run(self): selenium = self.selenium self.login() self.do_run() #Reset selenium.open("/programs/") self.get_details() self.do_reset() self.do_run() #Reset selenium.open("/programs/") self.get_details() self.do_reset()
def testWrookIsOpenSource(self): ''' Tests the "Wrook is Open Source" content page. Test includes acces via the main navigation path from the home page. ''' selenium = self.selenium selenium.open("/") selenium.wait_for_page_to_load("30000") selenium.click("menu-openSourceLicense") selenium.wait_for_page_to_load("30000") self.assertEqual("page-about-OpenSourceLicense", selenium.get_attribute("//body@id")) selenium.click("menu-openSourceAttribution") selenium.wait_for_page_to_load("30000") self.assertEqual("page-about-openSourceAttribution", selenium.get_attribute("//body@id")) selenium.click("menu-CPAL10License") selenium.wait_for_page_to_load("30000") self.assertEqual("page-about-CPAL", selenium.get_attribute("//body@id"))
def Login(self): try: selenium.open(config_element.get("setting", "acs_address_sub")) selenium.type("id="+config_element.get("login", "username_id"), config_setting.get("setting", "username")) selenium.type("id="+config_element.get("login", "password_id"), config_setting.get("setting", "password")) selenium.click("id="+config_element.get("login", "login_Id")) selenium.wait_for_page_to_load( config_element.get("setting", "wait_time")) print "Login to the web - PASS" pyautogui.click(1000, 30) selenium.click( "xpath="+config_element.get("setting", "askey_logo")) print "Get the ASKEY image - PASS" except: raise Exception("No login to the web - FAIL")
def testMemberViewsAndEditsHisAccountSettings(self): ''' Member views and edits his account settings. Persistance is tested by changing the about field twice and verifying the saved input ''' selenium = self.selenium self.preconditionLoggedIn() selenium.open("/") selenium.wait_for_page_to_load("30000") selenium.click("sidebarMenu-accountSettings") selenium.wait_for_page_to_load("30000") self.assertEqual("page-account-view", selenium.get_attribute("//body@id")) selenium.click("btnEditAccount") selenium.wait_for_page_to_load("30000") self.assertEqual("page-account-edit", selenium.get_attribute("//body@id")) selenium.type("About", "Bonjour!") selenium.click("btnSave") selenium.wait_for_page_to_load("30000") self.assertEqual("page-account-view", selenium.get_attribute("//body@id")) self.assertEqual("Bonjour!", selenium.get_text("valAbout")) selenium.click("btnEditAccount") selenium.wait_for_page_to_load("30000")
from FlashSelenium import FlashSelenium from selenium import selenium url = "http://flashselenium.t35.com/colors.html" browserType = "*firefox" selenium = selenium("localhost", 4444, browserType, url) selenium.start() selenium.open(url) flashApp = FlashSelenium(selenium, "coloredSquare") flashApp.percent_loaded()
class main_script(unittest.TestCase): # for Firefox selenium = selenium("localhost", 5555, "*chrome", "http://google.co.in") selenium.start() selenium.open("/") # end of Firefox # for IE #driver = webdriver.Ie("C:\\Python34\\IEDriverServer.exe") #driver.close() # end of IE # for Chrome # chromedriver = "D:\\Work\\Drivers\\chromedriver" # os.environ["webdriver.chrome.driver"] = chromedriver # driver = webdriver.Chrome(chromedriver) # driver.get("http://stackoverflow.com") # driver.quit() # selenium.start() # End for Chrome # selenium.open("/") #display = Display(visible=0, size=(800, 600)) #display.start() #driver = webdriver.Chrome("D:\Work\Drivers\chromedriver.exe") #driver.get("http://www.google.com") #print driver.page_source.encode('utf-8') pass def test01_script(self): pass browser = self.selenium print "Open the google page" browser.type("q", "selenium RC") print "Enter the search test Selenium RC" browser.click("btnG") print "Click on Google Search button" browser.stop() @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") def test02_script(self): pass browser = self.selenium print "Open the google page" browser.type("q", "selenium RC") print "Enter the search test Selenium RC" browser.click("btnG") print "Click on Google Search button" browser.stop() @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") #@unittest.expectedFailure def test03_script(self): pass browser = self.selenium print "Open the google page" browser.type("q", "selenium RC") print "Enter the search test Selenium RC" browser.click("btnG") print "Click on Google Search button" browser.stop() def close_Chrome(self): self.driver.quit()
def doMemberLogout(self): selenium = self.selenium selenium.open("/Logout") selenium.wait_for_page_to_load("30000") self.assertEqual("page-home-visitor", selenium.get_attribute("//body@id"))
class main_script(unittest.TestCase): selenium = selenium("localhost", 4444, "*chrome", "http://google.co.in") selenium.start() selenium.open("/")