Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Selenium/Python/Nose时浏览器实例化两次_Python_Unit Testing_Selenium_Selenium Webdriver_Nose - Fatal编程技术网

使用Selenium/Python/Nose时浏览器实例化两次

使用Selenium/Python/Nose时浏览器实例化两次,python,unit-testing,selenium,selenium-webdriver,nose,Python,Unit Testing,Selenium,Selenium Webdriver,Nose,我正在使用Selenium和python绑定创建一个示例测试,并使用nose运行它。我知道我做错了,因为测试会打开两个浏览器(安装程序运行时,一个Firefox窗口会立即打开和关闭,然后当测试运行driver.get时,另一个窗口会打开)。我有以下项目: /test_project /config config.ini /pages __init__.py test_page.py /test_scripts

我正在使用Selenium和python绑定创建一个示例测试,并使用nose运行它。我知道我做错了,因为测试会打开两个浏览器(安装程序运行时,一个Firefox窗口会立即打开和关闭,然后当测试运行driver.get时,另一个窗口会打开)。我有以下项目:

/test_project
    /config
        config.ini
    /pages
        __init__.py
        test_page.py
    /test_scripts
        script.py
    __init__.py
    base.py
    config_parser.py
config.ini:

[Selenium]
browser: firefox
base_url: http://www.google.com/
chromedriver_path:
base.py

from selenium import webdriver
from config_parser import Config


class TestCase(object):

    def setup(self):
        self.config = Config()

        if self.config.read_config('Selenium', 'browser').lower() == 'firefox':
            self.driver = webdriver.Firefox()
        elif self.config.read_config('Selenium', 'browser').lower() == 'chrome':
            self.driver = webdriver.Chrome(self.config.read_config('Selenium', 'chromedriver_path'))

    def teardown(self):
        self.driver.quit()
from config_parser import Config

class TestPage(object):

    def __init__(self, driver):
        self.driver = driver
        self.config = Config()

    def open(self):
        self.driver.get(self.config.read_config('Selenium', 'base_url'))
        import time
        time.sleep(3)
from pages import test
from base import TestCase


class RandomTest(TestCase):

    def test_foo(self):
        x = test.TestPage(self.driver)
        x.open()
        assert 1 == 1
测试页面.py

from selenium import webdriver
from config_parser import Config


class TestCase(object):

    def setup(self):
        self.config = Config()

        if self.config.read_config('Selenium', 'browser').lower() == 'firefox':
            self.driver = webdriver.Firefox()
        elif self.config.read_config('Selenium', 'browser').lower() == 'chrome':
            self.driver = webdriver.Chrome(self.config.read_config('Selenium', 'chromedriver_path'))

    def teardown(self):
        self.driver.quit()
from config_parser import Config

class TestPage(object):

    def __init__(self, driver):
        self.driver = driver
        self.config = Config()

    def open(self):
        self.driver.get(self.config.read_config('Selenium', 'base_url'))
        import time
        time.sleep(3)
from pages import test
from base import TestCase


class RandomTest(TestCase):

    def test_foo(self):
        x = test.TestPage(self.driver)
        x.open()
        assert 1 == 1
script.py

from selenium import webdriver
from config_parser import Config


class TestCase(object):

    def setup(self):
        self.config = Config()

        if self.config.read_config('Selenium', 'browser').lower() == 'firefox':
            self.driver = webdriver.Firefox()
        elif self.config.read_config('Selenium', 'browser').lower() == 'chrome':
            self.driver = webdriver.Chrome(self.config.read_config('Selenium', 'chromedriver_path'))

    def teardown(self):
        self.driver.quit()
from config_parser import Config

class TestPage(object):

    def __init__(self, driver):
        self.driver = driver
        self.config = Config()

    def open(self):
        self.driver.get(self.config.read_config('Selenium', 'base_url'))
        import time
        time.sleep(3)
from pages import test
from base import TestCase


class RandomTest(TestCase):

    def test_foo(self):
        x = test.TestPage(self.driver)
        x.open()
        assert 1 == 1
有人能帮我理解为什么有两个浏览器窗口打开,以及我能做些什么来纠正这个问题吗


提前感谢您。

这是因为您的基本
TestCase
类也被nose test runner识别为测试

用decorator标记它:

from selenium import webdriver
from config_parser import Config
from nose.tools import nottest

@nottest
class TestCase(object):
    ...