【问题标题】:how to run multiple test cases in selenium python? [duplicate]如何在 selenium python 中运行多个测试用例? [复制]
【发布时间】:2020-10-04 04:31:49
【问题描述】:

导入单元测试

从硒导入网络驱动程序

从日期时间导入日期时间

类索引(unittest.TestCase):

@classmethod
def setUpClass(cls):
    chrome_options = webdriver.ChromeOptions()
    prefs = {"profile.default_content_setting_values.notifications": 2}
    chrome_options.add_experimental_option("prefs", prefs)
    chrome_options.add_argument("start-maximized")
    driver = webdriver.Chrome(chrome_options=chrome_options, executable_path= r'/home/sourav/Desktop/chromedriver')
    driver.maximize_window()

def test_all_links_test(self):
    now = datetime.now()
    date_time = now.strftime("%m%d%Y%H%M%S")
    self.driver.get("https://www.easemytrip.com/")
    links = []
    elems = self.driver.find_elements_by_xpath("//a[@href]")
    for elem in elems:
        href = elem.get_attribute("href")
        links.append(href)
    file1 = open("/home/sourav/PycharmProjects/" + date_time + ".xlsx", "x")
    file1.write("\n".join(links))
    file1.close()

def test_login(self):
    my_account = self.driver.find_element_by_id("spnMyAcc")
    print(my_account)

@classmethod
#def tearDown(self):
def tearDownClass(cls):
    #self.driver.close()
    cls.driver1.quit()

如果 name == "ma​​in": unittest.main()

我无法运行多个测试用例

【问题讨论】:

    标签: python-3.x selenium-webdriver automation


    【解决方案1】:

    在 selenium 中,您可以在称为 xml 文件的单个文件中运行多个测试类。 您可以从项目文件夹创建 xml 文件 我在这里提到了我的 xml 文件(类名是每个测试用例的测试类)

    [![See this xml file sample][1]][1]
    

    【讨论】:

    • ttp://testng.org/testng-1.0.dtd" rel="nofollow" target="_blank">testng.org/testng-1.0.dtd">
    猜你喜欢
    • 2011-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 2020-02-29
    • 1970-01-01
    • 2015-08-19
    • 1970-01-01
    相关资源
    最近更新 更多