0

我已经在 Selenium WebDriver 中看到了使用 java 的数据驱动框架的示例。请给我一个使用 Selenium WebDriver python 绑定的数据驱动框架的例子。

4

2 回答 2

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
于 2013-02-11T13:25:33.647 回答
0

您可以查看用于 Selenium 的 Robot Framework

于 2013-02-14T03:56:33.810 回答