在Windows中定义模块的路径(模块是正在运行的测试文件)

时间:2017-05-31 18:00:15

标签: python unit-testing selenium webdriver geckodriver

我试图运行一个简单的自动化测试脚本。我的代码如下:

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import os
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))
binary = FirefoxBinary('C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, executable_path=gecko+'.exe')


class PythonOrgSearch(unittest.TestCase):
def setUp(self):
    self.driver = driver

def test_search_in_python_org(self):
    driver = self.driver
    driver.get("http://www.python.org")
    self.assertIn("Python", driver.title)
    elem = driver.find_element_by_name("q")
    elem.send_keys("pycon")
    elem.send_keys(Keys.RETURN)
    assert "No results found." not in driver.page_source


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

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

当我运行它时,我收到错误:  查找' test_file.py'的模块规范时出错(AttributeError:module' test_file'没有属性' 路径')

我一直在搜索堆栈溢出,以了解如何解决此问题或定义路径。我是Windows操作系统和单元测试的新手,所以我很失落如何解决这个问题。如果您有任何见解,我们将不胜感激。

0 个答案:

没有答案