Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python django: How to call selenium.set_speed() with django LiveServerTestCase

To run my functional tests i use LiveServerTestCase.

I want to call set_speed (and other methods, set_speed is just an example) that aren't in the webdriver, but are in the selenium object.

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

my subclass of 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()

How to get that? I can't call the constructor on selenium, i think.

like image 433
apelliciari Avatar asked Mar 30 '13 14:03

apelliciari


1 Answers

You don't. Setting the speed in WebDriver is not possible and the reason for this is that you generally shouldn't need to, and the 'waiting' is now done at a different level.

Before it was possible to tell Selenium, don't run this at normal speed, run it at a slower speed to allow more things to be available on page load, for slow loading pages or AJAX'ified pages.

Now, you do away with that altogether. Example:

I have a login page, I login and once logged in I see a "Welcome" message. The problem is the Welcome message is not displayed instantly and is on a time delay (using jQuery).

Pre WebDriver Code would dictate to Selenium, run this test, but slow down here so we can wait until the Welcome message appears.

Newer WebDriver code would dictate to Selenium, run this test, but when we login, wait up to 20 seconds for the Welcome Message to appearing, using explicit waits.

Now, if you really want access to "set" Selenium's speed, first off I'd recommend against it but the solution would be to dive into the older, now deprecated code.

If you use WebDriver heavily already, you can use the WebDriverBackedSelenium which can give you access to the older Selenium methods, whilst keeping the WebDriver backing the same, therefore much of your code would stay the same.

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

Second option is to dive into the old Selenium code and use it, this will change a lot of your existing code (because it is before the "WebDriver" concept was born).

The code for both Selenium RC & WebDriverBackedSelenium lives here, for the curious:

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

Something along the lines of:

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

You'd then get access to do this:

sel.setSpeed(5000)
like image 80
Arran Avatar answered Oct 23 '22 10:10

Arran