蟒蛇多重测试案例 [英] python selenium multiple test cases

查看:150
本文介绍了蟒蛇多重测试案例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python中有以下代码:

$ se

  selenium import webdriver $ b $ se from selenium.webdriver.common.by导入通过selenium.webdriver.support.ui导入
导入从selenium.common.exceptions中导入选择
导入NoSuchElementException $ b $ from from unittestzero导入从selenium.webdriver.support.ui中导入
导入WebDriverWait
from selenium.common.exceptions import ElementNotVisibleException
import unittest,time,re
$ b $ class HomePageTest(unittest.TestCase):
expected_title =some title here
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url =https://somewebsite.com
self.verificationErrors = []

def test_home_page(self):
driver = self.driver
driver.get(self.base_url)
打印在这里测试一些东西




def test_whatever(self):
打印在这里测试更多的东西

def tearDown(self):
self.driver.quit()


if __name__ == __main__:
unittest.main()

我的问题是函数test_home_page firefox实例关闭并再次打开下一个test_whatever函数。我怎样才能做到这一点,以便所有的测试用例都是从同一个firefox实例中执行的。 __ init __ :

$ p $ class HomePageTest(unittest.TestCase):
def __init __(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url =https://somewebsite.com
self.verificationErrors = []

...

def tearDown(self):
self.driver.quit()


I have the following code in python

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from unittestzero import Assert
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import ElementNotVisibleException
import unittest, time, re

class HomePageTest(unittest.TestCase):
    expected_title="  some title here "
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "https://somewebsite.com"
        self.verificationErrors = []

    def test_home_page(self):
        driver=self.driver
        driver.get(self.base_url)
        print "test some things here"




    def test_whatever(self):
        print "test some more things here"

    def tearDown(self):
        self.driver.quit()


if __name__ == "__main__":
    unittest.main()

My problem is after the function test_home_page, the firefox instance closes and opens again for the next test_whatever function. How can I do his so that all the test cases are executed from the same firefox instance.

解决方案

Initialize the firefox driver in __init__:

class HomePageTest(unittest.TestCase):
    def __init__(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "https://somewebsite.com"
        self.verificationErrors = []

    ...

    def tearDown(self):
        self.driver.quit()

这篇关于蟒蛇多重测试案例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆