0

我有一个测试任务,需要https://testsheepnz.github.io/BasicCalculator.html使用 Selenium 测试函数,我使用 Python,这是编写测试用例的单元测试。这是我的代码

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
import time
from ddt import ddt,data,unpack
import csv
import HtmlTestRunner
def get_data(file_name):
    #Create an empty list to store row data
    rows = []
    data_file = open(file_name,'r')
    #Read the file and return a list of each line in the csv file, returning the value read per line as a list
    reader = csv.reader(data_file)
    next(reader,None)
    #Add each row of data to the list
    for row in reader:
        rows.append(row)
    return rows
@ddt
class AddTestCases(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome("./chromedriver.exe")
        self.driver.implicitly_wait(30)
        self.driver.get("https://testsheepnz.github.io/BasicCalculator.html")

    #Create a test case
    @data(*get_data("./Valid_Add.csv"))
    @unpack
    def test(self,first_num,second_num,integer_only,result):
        driver = self.driver
        

        button = driver.find_element_by_id('calculateButton')
        selectBuild = Select(driver.find_element_by_id("selectBuild"))

        result_box = driver.find_element_by_id("numberAnswerField")

        button = driver.find_element_by_id('calculateButton')
        num1 = driver.find_element_by_id("number1Field")
        num2 = driver.find_element_by_id("number2Field")


        selectBuild.select_by_value("1")# I want to insert builds from 1 -> 9 before inserting data
        num1.clear()
        num2.clear()
        num1.send_keys(first_num)
        num2.send_keys(second_num)
        button.click()
        time.sleep(0.5)
        self.assertEqual(result_box.get_attribute('value'), result, 'Failed')

        time.sleep(0.5)
    def tearDown(self):
        self.driver.close()
if __name__ == "__main__":
    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output="./"))

我的问题是:我想在开始测试之前选择构建,它的范围从 1 -> 9。所以首先,构建 1 开始,运行所有数据,然后构建 2 开始,再次运行所有数据......我怎么能做吗?谢谢!

4

0 回答 0