Python django:如何使用django LiveServerTestCase调用selenium.set_speed()

ape*_*ari 7 python django selenium binding webdriver

要运行我的功能测试我使用LiveServerTestCase.

我想调用set_speed(和其他方法,set_speed只是一个例子)不在webdriver中,但是在selenium对象中.

http://selenium.googlecode.com/git/docs/api/py/selenium/selenium.selenium.html#module-selenium.selenium

我的子类 LiveServerTestCase

from selenium import webdriver

class SeleniumLiveServerTestCase(LiveServerTestCase):

    @classmethod
    def setUpClass(cls):

        cls.driver = webdriver.Firefox()
        cls.driver.implicitly_wait(7)

        cls.driver.maximize_window()

        # how to call selenium.selenium.set_speed() from here? how to get the ref to the selenium object?

        super(SeleniumLiveServerTestCase, cls).setUpClass()
Run Code Online (Sandbox Code Playgroud)

怎么做到的?我想,我不能在selenium上调用构造函数.

Arr*_*ran 8

你没有.在WebDriver中设置速度是不可能的,其原因是您通常不需要,并且"等待"现在在不同的级别完成.

在可以告诉Selenium之前,不要以正常速度运行它,以较慢的速度运行它以允许在页面加载时有更多的东西,用于缓慢加载页面或AJAX的页面.

现在,你完全废除了它.例:

我有一个登录页面,我登录并登录后看到"欢迎"消息.问题是欢迎消息没有立即显示,并且是一个时间延迟(使用jQuery).

Pre WebDriver Code会指示Selenium,运行此测试,但在这里放慢速度,以便我们可以等到Welcome消息出现.

较新的WebDriver代码将指示Selenium运行此测试,但是当我们登录时,请等待最多20秒以使用显式等待显示欢迎消息.

现在,如果你真的想要访问"设置"Selenium的速度,首先我会推荐它,但解决方案是深入研究旧的,现已弃用的代码.

如果您已经大量使用WebDriver,您可以使用WebDriverBackedSelenium它来访问旧的Selenium方法,同时保持WebDriver支持相同,因此您的大部分代码将保持不变.

https://groups.google.com/forum/#!topic/selenium-users/6E53jIIT0TE

第二种选择是深入研究旧的Selenium代码并使用它,这将改变你现有的许多代码(因为它是在"WebDriver"概念诞生之前).

为了好奇,Selenium RC和WebDriverBackedSelenium的代码都在这里生活:

https://code.google.com/p/selenium/source/browse/py/selenium/selenium.py

有点像:

from selenium import webdriver
from selenium import selenium
driver = webdriver.Firefox()
sel = selenium('localhost', 4444, '*webdriver', 'http://www.google.com')
sel.start(driver = driver)
Run Code Online (Sandbox Code Playgroud)

然后,您可以访问以下内容:

sel.setSpeed(5000)
Run Code Online (Sandbox Code Playgroud)