【问题标题】:How to run a basic functional test with selenium webdriver from django如何使用 django 的 selenium webdriver 运行基本功能测试
【发布时间】:2014-02-19 05:42:06
【问题描述】:

我正在开发一个 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 表中。我不清楚如何最好地做到这一点。

【问题讨论】:

    标签: python django selenium selenium-webdriver


    【解决方案1】:

    我有时用于运行测试鼻子测试: https://nose.readthedocs.org/en/latest/

    【讨论】:

    • 感谢您的回答,我已经访问了链接并环顾四周,但我需要更具体的信息来了解在上述情况下该怎么做。谢谢,-比尔
    猜你喜欢
    • 2013-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    相关资源
    最近更新 更多