如何在python中按顺序运行多个Selenium Web驱动程序测试用例方法



我正在使用适用于python的Selenium Web驱动程序编写一个测试用例。测试用例有多种方法,例如:

class Test(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.driver1 = webdriver.Firefox()
        cls.driver1.maximize_window()
    def test_1(self):
        .....
        .....
    def test_2(self):
        ....
        ....
    @classmethod
    def tearDownClass(cls):
        cls.driver1.quit()

当我尝试从 pycharm 或终端运行文件时,它会随机执行方法。我想要顺序执行,所以 test_1() 应该在 test_2() 之前运行。请帮助我..提前谢谢。

在浏览器的单个实例中运行多个测试的语法是正确的;尽管它不以随机顺序运行测试,而是按数字或字母顺序运行测试。

前任:类测试(单元测试。测试用例):

@classmethod
def setUpClass(cls):
    .....
def test_1(self): #or def test_a
    print 'test1'
def test_3(self): #or def test_c
    print 'test2'
def test_2(self): #or def test_b
    print 'test3'
@classmethod
def tearDownClass(cls):
    .......

测试执行顺序:升序,即test_1(test_a)将首先执行>接下来是test_2(test_b),然后是test_3(test_c)....无论"def test_(self)"( - 字母或数字)都放在代码中。

o/p:test_1好的 test_2.....测试3好的 test_3.....测试2还行

使用黄瓜和Selenium,它具有功能文件,可以在其中给出步骤定义,并且所有步骤都像迷你测试一样,按编写顺序执行。它还具有非常外行可读的写作步骤格式,即小黄瓜格式。

应该像魅力一样工作。

下面是一个示例

Feature: User Placing an order via different methods
    Scenario: User tries to place an order for test item
        Given User is on Home Page
        When User Searches for test item
        Then Open the search item page
        And User adds the item to cart
        And User proceeds to book

这是链接

优先考虑你的测试方法,这个优先级是在方法定义之上给出的,至少在Java中是这样,当你将Selenium与TestNG一起使用时。不知道它在Python中是如何完成的。如果我们优先考虑这些定义,那么它们肯定会在执行时牢记方法的优先级。

最新更新