This article will show how flaky tests are handled using allure. Flaky tests sometimes pass and sometimes fail without any changes to the system under test.
Allure Report is a test reporting tool that can be used to visualize the results of automated tests.
Mark flaky tests: Use the @Flaky annotation to mark the flaky tests in your test code.
package week4.day2;
import java.awt.Dimension;
import java.awt.Toolkit;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
import io.qameta.allure.Flaky;
public class Play {
@Test
@Flaky
public void alluPlay() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int) screenSize.getWidth();
int height = (int) screenSize.getHeight();
Playwright playwright = Playwright.create();
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
// BrowserContext newContext = browser.newContext(
// new
// Browser.NewContextOptions().setRecordVideoDir(Paths.get("Videos/")).setRecordVideoSize(1280,
// 720));
BrowserContext newContext = browser.newContext(new Browser.NewContextOptions().setViewportSize(width, height));
Page page = newContext.newPage();
page.navigate("http://www.programsbuzz.com");
Locator body = page.locator("body");
String bodyText = body.textContent();
Assert.assertFalse(bodyText.contains("Spam Message"), "Spam Text Not Found!!");
// newContext.close();
// playwright.close();
}
}
- Let us mark this test as flaky using the annotation and see how it is reflected in the report.
- Here, we filtered out the flaky test, which is indicated with a ticking bomb icon.
- Log in to post comments