是否有可能为硒测试设置一个时间限制? [英] Is it possible to set a time limit for a Selenium test?
问题描述
sudo killall Xvfb
时(我们也可以终止测试过程),它们才会停止。是否可以为Selenium测试设置时间限制(15分钟),如果达到时间限制,测试将会失败?我试图设置页面加载超时,但它不能解决问题:$ p $ self_river = webdriver.Firefox(firefox_profile = firefox_profile)
time.sleep(30)
self.driver.set_window_size(width = 1920,height = 1080)
size = self.driver.get_window_size()
print( Window size:width = {} px,height = {} px。。format $ b
我们使用Selenium 2.45.0
。我们需要升级吗?
我的类继承自 unittest.TestCase
。
您可以尝试超时装饰器测试时间
导入timeout_decorator
@ timeout_decorator.timeout(5)
def mytest():
打印开始
(i, 10):
time.sleep(1)
print%d seconds have passed%i
$ b $ if if __name__ =='__main__':
mytest()
更多详情请参考: timeout-decorator
We develop extensions for Chrome, Firefox and Safari and we test our Chrome and Firefox extensions with Selenium. But the problem is, some of the Firefox tests get stuck for hours, and they only stop when we kill the display sudo killall Xvfb
(we could also kill the test process). Is it possible to set a time limit (15 minutes) for the Selenium tests, and the test will fail if it reached the time limit? I tried to set page load timeout but it doesn't solve the problem:
self.driver = webdriver.Firefox(firefox_profile=firefox_profile)
time.sleep(30)
self.driver.set_window_size(width=1920, height=1080)
size = self.driver.get_window_size()
print("Window size: width = {}px, height = {}px.".format(size["width"], size["height"]))
self.driver.set_page_load_timeout(time_to_wait=45)
We are using Selenium 2.45.0
. Do we need to upgrade?
My class inherits from unittest.TestCase
.
you can try timeout decorator for your test
import time
import timeout_decorator
@timeout_decorator.timeout(5)
def mytest():
print "Start"
for i in range(1,10):
time.sleep(1)
print "%d seconds have passed" % i
if __name__ == '__main__':
mytest()
For more detail refer: timeout-decorator
这篇关于是否有可能为硒测试设置一个时间限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!