【问题标题】:webpage test with python selenium: really slow execution使用 python selenium 进行网页测试:执行速度真的很慢
【发布时间】:2015-03-19 23:59:10
【问题描述】:

我在 Python 中使用 Selenium 编写了一个非常简单的网页测试

这里是代码:

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')

它有效,但执行需要将近一分钟:

> 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 机器上)。 这似乎是原因。

直接从shell执行代码,耗时20秒:

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

OK

我能做些什么来加快执行速度?

【问题讨论】:

标签: python testing selenium selenium-webdriver


【解决方案1】:

以下内容应该会为您加快速度:

  • selenium升级到最新版本(当前为2.44.0

    pip3 install selenium --upgrade
    
  • firefox升级到最新版本(当前为35.0

升级前我的速度较慢,现在是:

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

OK

【讨论】:

  • 可能如你所说。很遗憾,我无法按照您建议的方式更新 selenium。
猜你喜欢
  • 1970-01-01
  • 2018-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-23
  • 2020-01-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多