2012-11-03 77 views

回答

0

我得到了上述問題的答案。看到下面

` 
class VCGadminlogin(unittest.TestCase): 
def setUp(self): 
    driver = webdriver.Firefox() 
    self.driver.implicitly_wait(30) 
    self.base_url = "http://example.in" 
    self.verificationErrors = [] 

def test_Login(self): 
    driver=self.driver 
    driver.get(self.base_url +"/") 
    driver.set_window_size(1920, 1080) 
    wb=xlrd.open_workbook('/login.xlsx') 
    sheetname = wb.sheet_names() #Read for XCL Sheet names 
    sh1 = wb.sheet_by_index(0) #add login details 
    i=1 
    while (i<6): 
     rownum=(i) 
     rows = sh1.row_values(rownum) 
     driver.find_element_by_xpath("//*[@id='form-div']/form/input[1]").clear() 
     print "1.enter user name in username text field" 
     driver.find_element_by_xpath("//*[@id='form-div']/form/input[1]").send_keys(rows[0]) 
     driver.find_element_by_xpath("//*[@id='form-div']/form/input[2]").clear() 
     print "2.enter password in password text field" 
     driver.find_element_by_xpath("//*[@id='form-div']/form/input[2]").send_keys(rows[1]) 
     print " 3.Click login button. it has to go corresponding example admin home page" 
     driver.find_element_by_xpath("//*[@id='form-div']/form/input[3]").click() 
     try: 
      driver.find_element_by_xpath("//*[@id='navigation']/li[1]/a").click() 
      driver.save_screenshot('loginpage'+ str(i) +'.png') 
      driver.find_element_by_xpath("//*[@id='contact']/ul/li[2]/a").click() 
     except: 
      error=driver.find_element_by_xpath(".//*[@id='form-div']/form/span[2]") 
      print error.text 
      print "login failled" 
      self.fail('login failed') 
      driver.save_screenshot(''_loginpageerror'+ str(i) +'.png') 
     i=i+1 
相關問題