def setup(browser): global driver option = Options() option.add_argument("--disable-infobars") option.add_argument("start-maximized") option.add_argument("--disable-extensions") # Pass the argument 1 to allow and 2 to block option.add_experimental_option("prefs", { "profile.default_content_setting_values.notifications": 2 }) if browser =='chrome': driver = webdriver.Chrome(chrome_options=option,executable_path="C://chromedriver.exe") elif browser== 'firefox': driver = webdriver.Firefox(executable_path="C:\\geckodriver.exe") else: driver = webdriver.Ie() driver.implicitly_wait(200) driver.maximize_window() if __name__ == "__main__": HTMLTestRunner.main() return driver
class LoginTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome('C:/RaghuChekuri/SelmServer/chromedriver') self.driver.get("http://google.com/") def testPythonScript(self): driver=self.driver driver.maximize_window() driver.implicitly_wait(60) driver.get_screenshot_as_file(../Screenshots/ss1.png) driver.find_element_by_xpath("(//a[contains(@href,'contact-us')])[1]").click() driver.find_element_by_name("name").send_keys("shubham") driver.find_element_by_id("contactemail").send_keys("*****@*****.**") driver.find_element_by_css_selector("#contact_form > div:nth-child(3) > div:nth-child(3) > input").send_keys( "389198318312") driver.find_element_by_name("company").send_keys("myname") driver.get_screenshot_as_file(../Screenshots/contactus.png) print driver.title assert "Hello" in driver.title print "execution ends" def testPythonFailScript(self): driver=self.driver driver.find_element_by_name("notExist").send_keys("done") def tearDown(self): driver = self.driver driver.quit(); if __name__ == "__main__": HTMLTestRunner.main()
class Notification(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.get("http://qa1.contus.us/products/P051/admin") self.driver.maximize_window() def test_notification(self): driver = self.driver usernameFieldElement = WebDriverWait( driver, 10).until(lambda driver: driver.find_element_by_xpath( "//input[@id='username']")) usernameFieldElement.send_keys("admin") passFieldElement = WebDriverWait( driver, 10).until(lambda driver: driver.find_element_by_xpath( "//input[@name='login[password]']")) passFieldElement.send_keys("admin123") submitButtonElement = WebDriverWait( driver, 10).until(lambda driver: driver.find_element_by_xpath( "//button[@class='action-login action-primary']")) submitButtonElement.click() notiButtonElement = WebDriverWait( driver, 10).until(lambda driver: driver.find_element_by_xpath( "//a[@title='Notifications']")) notiButtonElement.click() def is_element_present(self, how, what): try: self.driver.find_element(by=how, value=what) except NoSuchElementException as e: return False return True self.assertTrue( self.is_element_present( By.XPATH, ".//*[@id='html-body']/div[2]/header/div[1]/div/h1")) # try: # # nothButtonElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(".//*[@id='html-body']/div[2]/header/div[1]/div/h1")) # # assert nothButtonElement.text == 'Notifications' # # assert "Notifications" in self.driver.find_element_by_xpath(".//*[@id='html-body']/div[2]/header/div[1]/div/h1").text # print('Notifications are displayed successfully') # except Exception as e: # print('Notifications are not displayed', format(e)) def tearDown(self): self.driver.quit() if __name__ == '__main__': HTMLTestRunner.main()
class Sele1(unittest.TestCase): class Settings: driver = webdriver.Firefox() def setUp(self): self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) self.base_url = "http://*****:*****@dev.supplified.com/buy-online/metro-load-carrying-helmet-sh-1206-(yellow)/sh-1206-yellow-chin-strap-load-carrying-helmet-hdpe---high-density-polyethylene/6746" #self.base_url = "http://*****:*****@dev.supplified.com/online-buy/safety-&-security/147", self.verificationErrors = [] def test_sele1(self): driver = self.driver driver.maximize_window() handle_httpstatus_list = [302] driver.get(self.base_url) #product = driver.find_element_by_xpath('/html/body/div[5]/section/div[2]/div[2]/div[3]/div[5]/div[15]/a[2]').click() location = driver.find_element_by_xpath('//*[@id="currentLocs"]/a/span').click() # time.sleep(2) lo = driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div/div[2]') lo.click() try: adtocart = driver.find_element_by_xpath('//*[@id="addcartbtn1"]').click() except: pass try: check_product = driver.find_element_by_xpath('/html/body/div[5]/section/div[2]/div[2]/div[2]/div/ul/span').text print ">>>",check_product except: pass title = driver.find_element_by_xpath('//h1[@class="ptSansBold"]').text print "product name---",title price = driver.find_element_by_xpath('//span[@itemprop="price"]') print"product price---",price.text desc = driver.find_element_by_xpath('//*[@id="specification"]/table').text print"specification desc-----",desc for keyfeatures in driver.find_element_by_xpath('//div[@id="keyFeature"]/ul'): print "keyfeatures---",keyfeatures.text for descriptions in driver.find_element_by_xpath('//div[@id="productDescription"]'): print"descriptions-----", descriptions.text for category in driver.find_elements_by_xpath('//div[@class="col-md-10 pull-left prodbreadcrumb"]/div//a'): print"category---",category.text #driver.refresh() # lo.click() # # check_product = driver.find_element_by_xpath('//ul[@class="pull-left col-md-10"]//span[@style="font-family:PTSans-Bold;font-size:20px;color:red;"]') # # if check_product: # # check_product.text if __name__ == "__main__": HTMLTestRunner.main()
class AdminSettings(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.get("http://qa1.contus.us/products/P051/admin") self.driver.maximize_window() def test_adminsettings(self): driver = self.driver usernameFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//input[@id='username']")) usernameFieldElement.send_keys("admin") passFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//input[@name='login[password]']")) passFieldElement.send_keys("admin123") submitButtonElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//button[@class='action-login action-primary']")) submitButtonElement.click() adminButtonElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//a[@title='My Account']")) adminButtonElement.click() accstingButtonElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//a[@title='Account Setting']")) accstingButtonElement.click() usrnameFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//input[@id='username']")) usrnameFieldElement.clear() usrnameFieldElement.send_keys("admin") fstnameFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//input[@id='firstname']")) fstnameFieldElement.clear() fstnameFieldElement.send_keys("Contus") lstnameFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//input[@id='lastname']")) lstnameFieldElement.clear() lstnameFieldElement.send_keys("Solutions") emilFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//input[@id='email']")) emilFieldElement.clear() emilFieldElement.send_keys("*****@*****.**") vrfypwFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//input[@id='current_password']")) vrfypwFieldElement.send_keys("admin123") savButtonElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//button[@title='Save Account']")) savButtonElement.click() def tearDown(self): self.driver.quit() if __name__ == '__main__': HTMLTestRunner.main()
from selenium.webdriver.support.ui import WebDriverWait import unittest import HTMLTestRunner class Signin(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.get("http://qa1.contus.us/products/P051/admin") self.driver.maximize_window() def test_Login(self): driver = self.driver usernameFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//input[@id='username']")) usernameFieldElement.send_keys("admin") passFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//input[@name='login[password]']")) passFieldElement.send_keys("admin123") submitButtonElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//button[@class='action-login action-primary']")) submitButtonElement.click() def tearDown(self): self.driver.quit() if __name__ == '__main__': HTMLTestRunner.main()
duration1=parser.get('billing','dur') duration=duration1.split() rate=float(parser.get('billing','cost')) #*******executino starts from here*********# class Billing(unittest.TestCase): pass def test_generator(dur): def test(self): API.updatecsv() a=sqldb.getDBbalance(MSISDN) print a makecall.Call(dur) b=sqldb.getDBbalance(MSISDN) print b c=format(a-b, '.2f') m1=mbilling.billingcalc(dur,rate) m2=format(m1, '.2f') self.assertEqual(float(c),float(m2)) return test if __name__ == '__main__': for i in range(len(duration)): test_name='test_%s_sec_duration' %duration[i] test =test_generator(duration[i]) setattr(Billing,test_name,test) HTMLTestRunner.main()
print("Main image is displayed") else : print("Main image is not displayed") roundtrip = WebDriverWait(driver,10).until(lambda driver : driver.find_element_by_xpath(".//label[contains(.,'Round-trip')]")) if roundtrip.is_selected() : print("Round Trip is selected by default") else : print("Round Trip is not selected") Oneway = WebDriverWait(driver,10).until(lambda driver : driver.find_element_by_xpath(".//label[contains(.,'One-way')]")) if Oneway.is_selected() : print("Error") else : print("Good to go") print(driver.current_url) bottom_options = WebDriverWait(driver,10).until(lambda driver : driver.find_element_by_xpath(".//*[@class='corp-images-container']")) bottom_iter = bottom_options.find_elements_by_tag_name('span') options_list = [x for x in bottom_iter] print(options_list) footer_options = WebDriverWait(driver,10).until(lambda driver : driver.find_element_by_xpath(".//*[@class='inline footer-link-list last-link-list']")) footer_iter = footer_options.find_elements_by_tag_name('a') for x in footer_iter : print(x.text) def tearDown(self): self.driver.quit() if __name__ == "__main__":HTMLTestRunner.main()
self.xmldict =xmltodict.XmlDictConfig(root) # sends xml request to with parameter request and verify the xml response def test_createUser_myapp_v1(self): self.sendRESTRequest(self.target_urls['target_url_local_v1'], self.xmlrestrequest ) self.procesRESTResponse() self.assertEqual(self.xmldict['success'], "true") self.result.close() """ @data('target_url_liveV1','target_url_liveV2','target_url_liveV3') def test_CreateUserRest_01(self, value): self.sendRESTRequest(self.target_urls[value], self.xmlrequest['1']) self.procesRESTResponse() self.assertEqual(self.xmldict['success'], "true") self.result.close() """ # self.assertEquals(self.temp, "true") if __name__ == '__main__': HTMLTestRunner.main() suite = unittest.TestLoader().loadTestsFromTestCase(TestCreateUserRest) outfile = open("../reports/apireport.html", "w") runner = HTMLTestRunner.HTMLTestRunner( stream=outfile, title='MyApp API Test Report', description='API Automation: createUser') runner.run(suite)
raise RuntimeException('some problem happened') class SampleCase2(SampleCase1): # 3 cases from SampleCase1 def test_23(self): pass class SampleCase3(unittest.TestCase): def test_30(self): pass class SelfTest(unittest.TestCase): def setUp(self): self.suite = unittest.TestSuite() self.suite.addTests([SampleCase1,SampleCase2,SampleCase3]) def test1(self): buf = StringIO.StringIO() runner = HTMLTestRunner.HTMLTestRunner(buf) runner.run(self.suite) print buf ############################################################################## # Executing this module from the command line ############################################################################## if __name__ == "__main__": # HTMLTestRunner.main(['toollib.TestHTMLRunner.SelfTest']) HTMLTestRunner.main(module=None)
def setUp(self): self.driver = webdriver.Chrome( executable_path= "C:\Users\Ram\PycharmProjects\untitled2\divers\chromedriver.exe") def test_Method(self): driver = self.driver driver.get("http://www.arre.co.in/") driver.maximize_window() print driver.title time.sleep(5) hover_over_element(driver, "html/body/header/div[1]/nav/ul/li[1]/a") time.sleep(5) dirc = os.getcwd() print dirc dateTimeStamp = time.strftime('%Y%m%d_%H_%M_%S') print dateTimeStamp def tearDown(self): self.driver.close() if __name__ == "__main__": HTMLTestRunner.main( HTMLTestRunner.HTMLTestRunner( stream='TestReport', title='My unit test', description='This demonstrates the report output by HTMLTestRunner.' ))
driver.find_element_by_id("FirstName").send_keys(self.FirstName) driver.find_element_by_id("LastName").clear() driver.find_element_by_id("LastName").send_keys(self.LastName) driver.find_element_by_id("Company").clear() driver.find_element_by_id("Company").send_keys(self.Company) driver.find_element_by_id("Email").clear() driver.find_element_by_id("Email").send_keys(self.Email) driver.find_element_by_id("Phone").clear() driver.find_element_by_id("Phone").send_keys(self.Phone) Select(driver.find_element_by_id("Function__c")).select_by_visible_text("IT / Security") driver.find_element_by_id("Title").clear() driver.find_element_by_id("Title").send_keys(self.Title) Select(driver.find_element_by_id("Country")).select_by_visible_text("US") Select(driver.find_element_by_id("State")).select_by_visible_text("CA") driver.find_element_by_link_text("Get Started").click() def tearDown(self): self.driver.quit() if __name__ == '__main__': HTMLTestRunner.main(verbosity=2) # if __name__ == "__main__": unittest.main()