webpage test with python selenium: really slow execution
Asked Answered
S

1

2

I wrote, in Python, using Selenium, a very simple test of a webpage

Here the code:

from selenium import webdriver
import unittest
from selenium.webdriver.common.keys import Keys

class NewVisitorTest(unittest.TestCase):

    def setUp(self):
    # cose da fare prima dei test
        self.browser = webdriver.Firefox()  # Opera? credo sia usabile :D

    def tearDown(self):
    # cose da fare dopo dei test
        self.browser.quit()

    def test_yahoo(self):
        # browser = webdriver.Firefox() # Get local session of firefox
        pagina = "http://ricordandoti.net/it/app-per-scoprire-il-cimitero-del-poblenou/"
        self.browser.get(pagina)      # Load page
        self.browser.implicitly_wait(5)    # aspetto si carichi tutta la pagina
                                           # forzando di aspettare 3 s
        assert "Ricordandoti" in self.browser.title


if __name__ == '__main__':  # 7    
    unittest.main(warnings='ignore')

It works, but it takes almost a minute to be executed:

> Running: /home/.../tests/functional_tests_ricord.py (Wed Jan 21 13:32:05 2015)
> 
> .
> ---------------------------------------------------------------------- Ran 1 test in 60.798s
> 
> OK

I use ninja IDE to write the code (in a Ubuntu 14.04 machine). This seems to be the reason.

Executing code directly from shell, it takes 20 s:

> subu@VR46-U:~$ python3 "/home/.../tests/functional_tests_ricord.py"
.
----------------------------------------------------------------------
Ran 1 test in 20.865s

OK

What can I do to fast up the execution?

Sandwich answered 21/1, 2015 at 12:49 Comment(1)
what about waiting 5 second with the implicit wait command ? You can start by using an explicit wait command (see selenium.googlecode.com/git/docs/api/py/webdriver_support/…)Peloquin
T
1

The following should speed things up for you:

  • upgrade selenium to the latest version (currently 2.44.0)

    pip3 install selenium --upgrade
    
  • upgrade firefox to the latest version (currently 35.0)

It was slower on my end before the upgrades, now it is:

$ python3 test.py
.
----------------------------------------------------------------------
Ran 1 test in 6.258s

OK
Transgression answered 21/1, 2015 at 13:9 Comment(1)
May be is as you say. Unfortunatly I can't update selenium the way you suggest.Sandwich

© 2022 - 2024 — McMap. All rights reserved.