我正在研究python / django项目,并希望使用selenium webdriver合并一些功能测试。我使用了selenium IDE firefox插件来生成一个看起来像的测试:
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 Gtest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://www.google.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_g(self):
driver = self.driver
driver.get(self.base_url + "google.com")
# ERROR: Caught exception [ERROR: Unsupported command [selectWindow | null | ]]
driver.find_element_by_id("gbqfq").clear()
driver.find_element_by_id("gbqfq").send_keys("stack")
driver.find_element_by_css_selector("b").click()
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
关注http://www.realpython.com/blog/python/django-1-6-test-driven-development/#.Uucu0sAo6Z4我将上面的脚本放入“gtest.py”中,然后将其放入名为“ft”的项目根级别目录中。
我希望能够从我的django项目中的函数调用此测试,并将结果(传递/失败)存储到db表。我不清楚如何最好地做到这一点。