python硒测试网页:确实执行缓慢 [英] webpage test with python selenium: really slow execution
问题描述
我用Python用Selenium编写了一个非常简单的网页测试
I wrote, in Python, using Selenium, a very simple test of a webpage
这里的代码:
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
我使用ninja IDE编写代码(在Ubuntu 14.04计算机中). 这似乎是原因.
I use ninja IDE to write the code (in a Ubuntu 14.04 machine). This seems to be the reason.
直接从shell执行代码,需要20 s:
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?
推荐答案
以下内容将为您加快速度:
The following should speed things up for you:
-
将
selenium
升级到最新版本(当前为2.44.0
)
upgrade
selenium
to the latest version (currently2.44.0
)
pip3 install selenium --upgrade
将firefox
升级到最新版本(当前为35.0
)
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
这篇关于python硒测试网页:确实执行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!