![](/img/trans.png)
[英]Is there a way to handle application session timeout for parallel selenium test execution?
[英]How to handle session timeout with selenium
我查看了类似问题的一些答案,但找不到满意的答案。
我正在构建自动化框架,我正在运行 200 个测试用例,完成大约需要 60 分钟。
应用程序的会话时间超过 30 分钟,所以当我的测试用例运行时,它在 30 分钟后注销,然后测试用例因为找不到所需元素而失败。
我想用什么登录来处理会话超时:
2.如果Current time - Test start time >= 30 minute
然后检查系统是否注销,如果是,则再次登录。 但是对于这个问题,就像我必须在每种方法或某些特定方法中调用它以每次检查是否注销一样。
所以我正在寻找一些解决方案,它从我的自动化开始就不断检查,如果找到注销窗口,则调用登录方法。
注意:我正在使用 selenium webdriver、Java、TestNG、Maven 和以下页面对象模式。
所以我假设您的登录页面与实际应用程序中的任何页面都有不同的 url。 如果您还没有带有 testng @BeforeTest 的方法,您可以创建一个方法并在新的或现有的 beforetest 方法中包含以下内容:
if (driver.getCurrentUrl() == "whatever.yourLoginPageUrl.is") {
//call login method or do whatever you have to do to login
//If you want to rerun the previous test that probably failed, do that here
}
一个稍微巧妙的方法(我认为)是实现 IRetryAnalyzer 接口并覆盖重试功能,例如像这样
public class MyRetry implements IRetryAnalyzer {
@Override
public boolean retry(ITestResult result) {
if (driver.getCurrentUrl() == "loginPageUrl") {
//call login function or do whatever you need to to login
return true;
}
return false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.