我已经在使用java的Selenium WebDriver中看到了数据驱动框架工作的示例。请给我一个使用Selenium WebDriver python绑定的数据驱动框架示例。
答案 0 :(得分: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
答案 1 :(得分:0)