亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果發生某種異常,請重新啟動 selenium 中的測試

如果發生某種異常,請重新啟動 selenium 中的測試

慕森王 2023-08-04 17:41:33
我正在通過 kobiton 運行我的 selenium 移動測試,我不斷發現的一個問題是,當我使用公用電話時,當我嘗試運行測試時,它們可能正在使用中,我收到以下消息org.openqa.selenium.SessionNotCreatedException:沒有與所需功能匹配的設備我當前的代碼設置是@BeforeClasspublic void setup()throws Exception{    String kobitonServerUrl = "https://f:a15e3b93-a1dd3c-4736-bdfb- [email protected]/wd/hub";    this.driver = new RemoteWebDriver (config.kobitonServerUrl(), config.desireCapabilitites_iphone8());}我希望能夠嘗試    this.driver = new RemoteWebDriver (config.kobitonServerUrl(), config.desireCapabilitites_iphone9() )如果 iphone 8 不可用,所以我認為 if 和 else 可以工作,但我不知道如何針對特定異常執行此操作?
查看完整描述

2 回答

?
撒科打諢

TA貢獻1934條經驗 獲得超2個贊

如果我正確理解你的問題,你想要的東西類似于 if-else 但有例外,


一般來說,異常的“if-else”是“try-catch”。也就是下面的代碼片段


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

}


查看完整回答
反對 回復 2023-08-04
?
侃侃無極

TA貢獻2051條經驗 獲得超10個贊

單獨捕獲異常


@BeforeClass

public void setup()throws Exception{


   try {

    String kobitonServerUrl = "https://f:a15e3b93-a1dd3c-4736-bdfb- 

[email protected]/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

    }


 }

}


查看完整回答
反對 回復 2023-08-04
  • 2 回答
  • 0 關注
  • 181 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號