2017-02-10 9 views
-4

意図的に要素を変更して誤っているが、TestNGでテストが失敗しない。何か案は?私の「Waitメソッド」がTestNGテストケースで失敗しないのはなぜですか?

マイコード:

public void waitAndClickElement(WebElement element) throws InterruptedException { 
    try { 
     element.click(); 
    } catch (TimeoutException timeEx) { 
     this.wait.until(ExpectedConditions.elementToBeClickable(element)).click(); 
    } catch (StaleElementReferenceException elementUpdated) { 
     this.wait.until(ExpectedConditions.elementToBeClickable(element)).click(); 
    } catch (Exception e) { 
     System.out.println("Unable to wait and click on element, Exception: " + e.getMessage()); 
    } 
} 

@Test(priority = 2) 
public void clickOnDrivingExperiencePage() throws Exception { 
    basePage.waitAndClickElement(homepageHeader.link_DrivingExperiences); 
} 

enter image description here

新しいコードの変更:

public void waitAndClickElement(WebElement element) throws InterruptedException { 
    try { 
     this.wait.until(ExpectedConditions.elementToBeClickable(element)).click(); 
     System.out.println("Successfully clicked on the WebElement: " + "<" + element.toString() + ">"); 
    } catch (Exception e) { 
     System.out.println("Unable to wait and click on WebElement, Exception: " + e.getMessage()); 
     Assert.assertFalse(true, "Unable to wait and click on the WebElement, using locator: " + "<" + element.toString() + ">"); 
    } 
} 
+1

なぜ失敗するのですか?あなたは例外をキャッチし、それらを処理します....それは "それは失敗しない"というよりむしろあいまいです。あなたが期待していたことと、現在のコードでどのような結果が得られたのかを記述できますか? – n247s

+0

@ n247s添付の画像を参照してください。Web要素のロケータが間違っていることがわかってもテストに失敗しない – Gbru

+0

このメソッドには0.04秒しかかかりません。しかし、何を期待していたのですか?どんなコンソール出力、どのテスト結果、そして代わりに何を得るのですか?また、実際に何が起こっているかを見るためにデバッガを試してみましたか? – n247s

答えて

4
} catch (Exception e) { 
    System.out.println("Unable to wait and click on element, Exception: " + e.getMessage()); 
} 

あなたはすべての例外をキャッチしているので、テストは失敗しません。

+0

付属の画像を見てくださいwebelementロケータが間違っていてもテストが失敗しない場合でも – Gbru

+0

コンソールに例外が出力されますが、Assert.failを追加してテストケースに失敗した場合、TestNGに渡して表示されます – Gbru

+0

コンソール出力? Assert.failはどこに追加しますか? – juherr

関連する問題