2017-07-26 10 views
0

Seleniumでは、テストケースでステップが失敗した場合、失敗を報告して残りのステップを続行できますか?現在、例外が存在する場合、実行は停止します。これは私のテストケースがSeleniumでは、テストケースでステップが失敗した場合、失敗を報告して残りのステップを続行できますか?

public class TC002_abc extends OpentapWrappers 
{  

    @Test (description="Test") 
    public void main() 
    { 

     try 
     {    
      WebDriverWait wait=new WebDriverWait(driver, 60);  
      VerifyTitle(Constant.HomePage_Title); 
      Click(HomePage.link_Login(driver), "Login Link");   
      wait.until(ExpectedConditions.urlContains(Constant.LoginURL));  
      VerifyTextPopulated(CommunicationPref.lbl_EmailAddress_Input(driver), Constant.EmailAddress);  
      /* Validate Email Communications */     
      Click(CommunicationPref.link_EditEmailCommunications(driver),"Edit Email Communications"); 
      VerifyText(CommunicationPref.lbl_UnCheckedEmailCommunications(driver), Constant.UnCheckedEmailCommunications_Text); 
      Click(CommunicationPref.btn_EmailCommunicationsSave(driver), "Save");       
      VerifyText(CommunicationPref.lbl_CheckedEmailCommunications(driver), Constant.CheckedEmailCommunications_Text);    
     } 
     catch (NoSuchElementException e) 
     { 
      e.printStackTrace(); 
      Reporter.reportStep("NoSuchElementException" , "FAIL");   
     } 
    } 

    @BeforeClass 
    public void beforeClass() 
    { 
     browserName="firefox"; 
     testCaseName = "TC002_abc"; 
     testDescription = "Test"; 
    } 

} 

サンプル法 -

public static void VerifyTitle(String title){ 

    try 
    {  

     if (driver.getTitle().equalsIgnoreCase(title)) 
     {   
      Reporter.reportStep("Page is successfully loaded :"+title, "PASS");      
     } 
     else 

      Reporter.reportStep("Page Title :"+driver.getTitle()+" did not match with :"+title, "FAIL"); 

    } 
    catch (Exception e) 
    { 
     e.printStackTrace(); 
     Reporter.reportStep("The title did not match", "FAIL"); 
    } 

} 
+0

ステップの一つは、それが結果を変える可能性があるので、他のステップは、その失敗したテストにdependednentされていないことを確認して失敗しない場合だけ、スローされる例外をキャッチ。テストを分割して、より管理しやすい小さなテストに分割することもできます。つまり、1つが失敗しても他のテストを続けることができれば、各テストは独立して実行できるはずです。 – redp

+0

私は異なるTCについて話していません。同じテストケースで、私の4番目のステップが失敗して実行が中止し、残りのステップがスキップされたとすることができます。私はそれが4番目のステップの失敗を報告し、5番目のステップを実行し続けたい。出来ますか?現在、4番目のステップで例外がスローされた場合、その例外がキャッチされ、失敗が報告されますが、実行は継続されません。 –

+0

TCはUI検証用です。だから、私は実行を途中で止めさせたくないだけです。要素の1つがページに見つかりませんでした。明らかでないことがあれば教えてください。 –

答えて

0

あなたはTestNGのを使っているので、ソフトアサーションを実装

public void VerifyTitle(String title) 
{ 

    SoftAssert assertion = new SoftAssert(); 
    String returnedTitle = driver.getTitle(); 

    if (assertion.assertTrue(returnedTitle.contains(title))) 
    { 

      Reporter.reportStep("Page is successfully loaded :" + title, "PASS"); 

    } else 
    { 

     Reporter.reportStep("Page Title :" + driver.getTitle() + " did not match with :" + title, "FAIL"); 
    } 
} 

like-に見えるものであるこのことができますなら、私を知ってみましょう。

+0

ifはboolean値とアサーションvoidを返します。だからそこにエラーを取得している - booleanを無効にすることはできません –

+0

私は通常のアサートを試みました。問題を解決しない –

関連する問題