我有一个功能测试“y1.py”,已从 selenium IDE 导出。它看起来像:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
class Y1(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://www.yahoo.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_y1(self):
driver = self.driver
driver.get(self.base_url)
driver.find_element_by_link_text("Weather").click()
driver.save_screenshot('out11.png')
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
我试图直接从 python/django 函数中调用它。在调查这个问题时我发现:AttributeError 'module' object has no attribute 'runserver' in django ,其中 Udi 指出:
Are you trying to run unitest and selenium from a view? You should consider launching a second process for that.
我该怎么做?
最佳答案
您可以使用 subprocess module 作为新进程启动 django 服务器.
关于python - 如何从 django View 运行unitest和selenium?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21472238/