Allure не сообщает о сбоях должным образом - PullRequest
0 голосов
/ 26 марта 2019
  1. krGlobalPage.softAssertionTestCall2(softAssertion); должен работать даже после сбоя krGlobalPage.softAssertionTestCall1(softAssertion); из-за

nosuchelementexception

Испытание должно быть провалено с КРАСНЫМ цветным индикатором в отчете Allure.
@Test(description = "softAssert")
public void softAssert(Method method) {
SoftAssert softAssertion = new SoftAssert();
KrGlobalPage krGlobalPage = new KrGlobalPage(prop, driver, wait);
krGlobalPage.softAssertionTestCall1(softAssertion);
krGlobalPage.softAssertionTestCall2(softAssertion);
softAssertion.assertAll();
}

assertions.assertEquals("msg1", "msg2", "msg1&msg2 not equal"); - работает нормально и правильно сообщает об ошибках.

    @Test(description = "softAssert")
    public void softAssert(Method method) {
        SoftAssert softAssertion = new SoftAssert();
        KrGlobalPage krGlobalPage = new KrGlobalPage(prop, driver, wait);
        krGlobalPage.softAssertionTestCall1(softAssertion);
        krGlobalPage.softAssertionTestCall2(softAssertion);
        softAssertion.assertAll();
    }

    @Step("SoftAssertion test1")
    public void softAssertionTestCall1(SoftAssert assertions) {
        Allure.step("softAssert Method Was Started", Status.SKIPPED);
        assertions.assertTrue(false);
    }

    @Step("SoftAssertion test2")
    public void softAssertionTestCall2(SoftAssert assertions) {
        Allure.step("softAssert Method Was Started", Status.SKIPPED);
    }

См. НижеСкриншот.enter image description here

Но когда nosuchelementexception на assertions.assertEquals((driver.findElement(By.xpath("(//nav[@class='topline']//nav[@class='without-seperator1']/a)[1]").getAttribute("href")), "www.cort.com");, krGlobalPage.softAssertionTestCall2(softAssertion) не выполняется.Пожалуйста, смотрите скриншот.

Как запустить krGlobalPage.softAssertionTestCall2(softAssertion); даже после сбоя krGlobalPage.softAssertionTestCall1(softAssertion); из-за nosuchelementexception и неудачного теста с красным цветным индикатором, как показано на первом скриншоте?

Почему assertions.assertTrue(false); работает как положено?

Почему assertions.assertEquals((driver.findElement(By.xpath("(//nav[@class='topline']//nav[@class='without-seperator1']/a)[1]").getAttribute("href")), "www.cort.com") не работает должным образом?

    @Test(description = "softAssert")
    public void softAssert(Method method) {
        SoftAssert softAssertion = new SoftAssert();
        KrGlobalPage krGlobalPage = new KrGlobalPage(prop, driver, wait);
        krGlobalPage.softAssertionTestCall1(softAssertion);
        krGlobalPage.softAssertionTestCall2(softAssertion);
        softAssertion.assertAll();
    }

    @Step("SoftAssertion test1")
    public void softAssertionTestCall1(SoftAssert assertions) {
        Allure.step("softAssert Method Was Started", Status.SKIPPED);
        assertions.assertEquals((driver.findElement(By.xpath("(//nav[@class='topline']//nav[@class='without-seperator1']/a)[1]").getAttribute("href")), "www.cort.com");
    }

    @Step("SoftAssertion test2")
    public void softAssertionTestCall2(SoftAssert assertions) {
        Allure.step("softAssert Method Was Started", Status.SKIPPED);
    }

enter image description here

1 Ответ

0 голосов
/ 26 марта 2019

Мягкие утверждения TestNG и любые ошибки / исключения в вашем коде, включая все ошибки Selenium (NoSuchElementException, ElementNotVisibleException, ...), не связаны друг с другом.

Если вы не хотите потерпеть неудачу из-за ошибок Selenium, обходите их.

@Step("SoftAssertion test1")
public void softAssertionTestCall1(SoftAssert assertions) {
    Allure.step("softAssert Method Was Started", Status.SKIPPED);

    // Use find elements to bypass NoSuchElementException error, if there is no such element. 
    // findElements list with size=0 if there is no element without any exception, and > 0 if element exist
    List<WebElement> mylinks = driver.findElements(By.xpath("(//nav[@class='topline']//nav[@class='without-seperator1']/a)[1]");

    // Assert if mylinks size > 0, using TestNG soft assertions
    assertions.assertTrue(mylinks.size() > 0, "Link with without-seperator1 class exist");

    // Assert if link has "www.cort.com" href
    if (mylinks.size() > 0)
        assertions.assertEquals(mylinks.get(0).getAttribute("href"), "www.cort.com");
}

Вы можете найти здесь , как проверить, существует ли элемент.

...