我正在通过kobiton运行我的selenium移动测试,我一直发现的一个问题是,当我使用公共电话时,当我尝试运行测试时,它们可能在使用,我得到了以下消息
org.openqa.selenium.SessionNotCreatedException:没有匹配所需功能的设备
我当前的代码设置是
@BeforeClass
public void setup()throws Exception{
String kobitonServerUrl = "https://f:a15e3b93-a1dd3c-4736-bdfb-
006221ezz8c2a2cz@api.kobiton.com/wd/hub";
this.driver = new RemoteWebDriver (config.kobitonServerUrl(),
config.desireCapabilitites_iphone8());
}我想要能够尝试
this.driver = new RemoteWebDriver (config.kobitonServerUrl(), config.desireCapabilitites_iphone9() )如果iphone 8不可用,所以我认为if和else可以工作,但我不知道如何处理特定的例外情况?
发布于 2019-09-17 15:04:54
如果我正确地理解了你的问题,你想要的东西类似于如果
通常情况下,异常的“如果-其他”是“尝试-捕获”。也就是说,下面的代码片段
try{
this.driver = new RemoteWebDriver (config.kobitonServerUrl(), config.desireCapabilitites_iphone8());
} catch(Exception e){
// Do something if any exception is thrown
}将执行try中的内容,如果抛出任何异常(在try中),则在catch中执行代码。
对于特定的异常,您也可以指定异常,假设您已经导入了异常,如下所示
try{
this.driver = new RemoteWebDriver (config.kobitonServerUrl(), config.desireCapabilitites_iphone8());
} catch(SessionNotCreatedException e){
// Do something if SessionNotCreatedException is thrown
}发布于 2019-09-17 15:11:48
单独捕获异常
@BeforeClass
public void setup()throws Exception{
try {
String kobitonServerUrl = "https://f:a15e3b93-a1dd3c-4736-bdfb-
006221ezz8c2a2cz@api.kobiton.com/wd/hub";
this.driver = new RemoteWebDriver (config.kobitonServerUrl(),
config.desireCapabilitites_iphone8());
}
catch (SessionNotCreatedException e){
this.driver = new RemoteWebDriver (config.kobitonServerUrl(), config.desireCapabilitites_iphone9() )
}
// if you want to use if else
catch (Exception other){
if ( other.getMessage().contains("SessionNotCreatedException ") )
{
// do something
}
}}
https://stackoverflow.com/questions/57976548
复制相似问题