@aftermethod拆除用于使用-Selenium 4运行整个班级
在运行整个班级时,我面临拆除问题(org.openqa.selenium.sessionnotcreatedexception)。测试是在索环上进行的。
当运行单个方法时,它的工作原理绝对可以,但是在运行整个班级或套件时,它不起作用。 而且,很少有其他方法在拆除时通过。 有什么可能性?
配置: Testng -7.4.0 Maven -3.8.4 硒-4.1.3
代码: 代码是多种多样的,但我们在下面将其用于所有方法(它在多个浏览器上运行)
private ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
public WebDriver getWebDriver() {
// Starts the ThreadLocal<Boolean> for checking the evidon banner as false
hasEvidonBeenChecked.set(false);
if (!BaseTest.isLocal) {
return webDriver.get();
} else {
return localWebDriver;
}
}
@org.testng.annotations.Test(dataProvider = "remoteBrowsers", priority = 1)
public void TestPractive(String browser, String version, String os, String platformversion,
String devicename, Method method) throws InterruptedException, OfferNotFoundException, IOException,
NullPointerException, IndexOutOfBoundsException, ArrayIndexOutOfBoundsException {
this.createDriver(browser, version, os, platformversion, devicename, method.getName());
WebDriver driver = this.getWebDriver();
this.setupImplicitWait(driver, 20);
错误 默认套件 总测试运行:9,传球:3,失败:3,跳过:3 配置失败:3,跳过:3
[asynchttpclient-1-8]错误org.asynchttpclient.netty.request.nettyrequestsender-无法写请求请求 [asynchttpclient-1-10]错误org.asynchttpclient.netty.request.nettyrequestsender-无法写请求 [asynchttpclient-1-9]错误org.asynchttpclient.netty.request.nettyrequestsender-无法写请求 java.io.io.ioexception:流封闭
失败配置:@aftermethod拆卸 java.lang.nullpoInterException:无法调用“ org.openqa.selenium.javascriptexecutor.executer.executescript(string,object []),因为“ java.lang.threadlocal.get()的返回值是null
org.openqa.selenium。 SessionNotCreatedException:无法启动新的会话。可能的原因是远程服务器或浏览器启动失败的无效地址。 构建信息:版本:'4.1.0',修订:'87802E897B' 系统信息:主机:'W105482ZY2',IP:'192.168.29.171',os.name:'Windows 10',os.ark:'amd64',os.version:'10 .0',java.version ' 驱动程序信息:org.openqa.selenium.remote.remotewebdriver Command: [null, newSession {capabilities=[Capabilities {browserName: MicrosoftEdge, browserVersion: latest-1, sauce:options:, desiredCapabilities=Capabilities {browserName: MicrosoftEdge, browserVersion: latest-1, sauce:options: , platformName: Windows 10 ,分辨率:1920x1080},Seleniumversion:4.1.0}}]] 功能{}
testng xml testng xml
I am facing tear down issues (org.openqa.selenium.SessionNotCreatedException) when running an entire class which holds many methods. Tests are ran on saucelabs.
when a single method is run, it works absolutely fine but while running the entire class or a suite, it is not working.
Also, few methods are passing while the others are going in tear down.
What could be the possibilities ?
Config:
TestNG - 7.4.0
Maven - 3.8.4
Selenium - 4.1.3
Code:
Codes are various but we are using this below for all the methods (it runs on multiple browsers)
private ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
public WebDriver getWebDriver() {
// Starts the ThreadLocal<Boolean> for checking the evidon banner as false
hasEvidonBeenChecked.set(false);
if (!BaseTest.isLocal) {
return webDriver.get();
} else {
return localWebDriver;
}
}
@org.testng.annotations.Test(dataProvider = "remoteBrowsers", priority = 1)
public void TestPractive(String browser, String version, String os, String platformversion,
String devicename, Method method) throws InterruptedException, OfferNotFoundException, IOException,
NullPointerException, IndexOutOfBoundsException, ArrayIndexOutOfBoundsException {
this.createDriver(browser, version, os, platformversion, devicename, method.getName());
WebDriver driver = this.getWebDriver();
this.setupImplicitWait(driver, 20);
Error
Default suite
Total tests run: 9, Passes: 3, Failures: 3, Skips: 3
Configuration Failures: 3, Skips: 3
[AsyncHttpClient-1-8] ERROR org.asynchttpclient.netty.request.NettyRequestSender - Can't write request
[AsyncHttpClient-1-10] ERROR org.asynchttpclient.netty.request.NettyRequestSender - Can't write request
[AsyncHttpClient-1-9] ERROR org.asynchttpclient.netty.request.NettyRequestSender - Can't write request
java.io.IOException: Stream closed
FAILED CONFIGURATION: @AfterMethod tearDown
java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.JavascriptExecutor.executeScript(String, Object[])" because the return value of "java.lang.ThreadLocal.get()" is null
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '4.1.0', revision: '87802e897b'
System info: host: 'W105482ZY2', ip: '192.168.29.171', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: MicrosoftEdge, browserVersion: latest-1, sauce:options:, desiredCapabilities=Capabilities {browserName: MicrosoftEdge, browserVersion: latest-1, sauce:options: , platformName: Windows 10, resolution: 1920x1080}, seleniumVersion: 4.1.0}}]
Capabilities {}
TestNG XML
testng xml
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Saucelab URL存在一个问题,该URL在几次会议后关闭了胎面。
实际: //启动远程浏览器并将其设置为当前线程
webdriver.set(new remotewebdriver(
new url(“ https://” +用户名 +“:” + accessKey +“@ondemand.saucelabs.com:443/wd/hub”),obsabilitions));
期望:
new URL(“ https://” +用户名 +“:” + accessKey +“@ondemand.us-west-1.saucelabs.com:443/wd/hub”),功能));
There was an issue with the saucelab url, which was closing the treads after few sessions.
Actual: // Launch remote browser and set it as the current thread
webDriver.set(new RemoteWebDriver(
new URL("https://" + username + ":" + accesskey + "@ondemand.saucelabs.com:443/wd/hub"),,capabilities));
Expected:
new URL("https://" + username + ":" + accesskey + "@ondemand.us-west-1.saucelabs.com:443/wd/hub"),capabilities));