Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
#85 - Added setting exitOnPageError with value false to avoid crashin…
Browse files Browse the repository at this point in the history
…g tests on webkit;

- Refactored tests with new demo site.
  • Loading branch information
ernestas-zekas committed Feb 4, 2021
1 parent ab2e55b commit 620be43
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 50 deletions.
33 changes: 14 additions & 19 deletions example/tests/elementActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,30 @@ describe("Element Actions", () => {

it("should double click an element", async () => {
//Arrange
await page.goto("http://demo.guru99.com/test/simple_context_menu.html");
const doubleClickButton = new Element("#authentication > button");
var alertIsShown = false;
var alertMessage = null;
page.on("dialog", async dialog => {
alertMessage = dialog.message();
alertIsShown = true;
await dialog.dismiss();
});
await page.goto("https://demoqa.com/buttons");
const doubleClickButton = new Element("#doubleClickBtn");
const doubleClickMessage = new Element("#doubleClickMessage");

//Act
await doubleClickButton.doubleClick();

//Assert
expect(alertIsShown).toBeTruthy();
expect(alertMessage).toEqual("You double clicked me.. Thank You..");
await expect(doubleClickMessage.exists()).resolves.toBeTruthy();
expect(await doubleClickMessage.text()).toEqual("You have done a double click");
});

it("should right click an element", async () => {
//Arrange
await page.goto("http://demo.guru99.com/test/simple_context_menu.html");
const rightClickButton = new Element("span.context-menu-one");
const contextMenu = new Element("#context-menu-layer");
await page.goto("https://demoqa.com/buttons");
const rightClickButton = new Element("#rightClickBtn");
const rightClickMessage = new Element("#rightClickMessage");

//Act
await rightClickButton.rightClick();

//Assert
await expect(contextMenu.exists()).resolves.toBeTruthy();
await expect(rightClickMessage.exists()).resolves.toBeTruthy();
expect(await rightClickMessage.text()).toEqual("You have done a right click");
});

it("should check if element exist", async () => {
Expand Down Expand Up @@ -253,7 +248,7 @@ describe("Element Actions", () => {

//Assert
expect(await toolTip.isVisible()).toBe(true);
expect(await toolTip.text()).toEqual("series-2: 55");
expect(await toolTip.text()).toContain("series-2: 55");
expect(await sliceToClick.getAttributeValue("selected")).toEqual(selectedAttr);
expect(await sliceToClick.getAttributeValue("data:pieClicked")).toEqual(pieClickedAttr);

Expand Down Expand Up @@ -293,9 +288,9 @@ describe("Element Actions", () => {
it("should get coordinates of element", async () => {
//Arrange
const expectedXCoordinate = 640; //width: default viewport 1280px / 2
const expectedYCoordinate = 34; //height: top container 68px / 2
const rectangleCanvas = new Element(".w3-container.top");
await page.goto("https://www.w3schools.com/");
const expectedYCoordinate = 25; //height: top bar 50px / 2
const rectangleCanvas = new Element(".top-bar__network._fixed");
await page.goto("https://stackoverflow.com/users/login");

//Act
const coordinates = await rectangleCanvas.getCoordinates();
Expand Down
55 changes: 31 additions & 24 deletions example/tests/interceptor.test.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,78 @@
import { Element, Helpers, Interceptor } from "test-juggler";

const DemoGuruSite = "http://demo.guru99.com/test/radio.html";
const DemoQaSite = "https://demoqa.com/books";
const DemoOpenCartSite = "https://demo.opencart.com/";
const successMessage = new Element(".alert-success");
const addToCartButton = new Element(".product-layout:nth-child(1) > div button:nth-child(1)");
const loadingWrapper = new Element("#loading-wrapper");
const booksWrapper = new Element(".books-wrapper");

describe("Interceptor", () => {
beforeEach(async () => {
console.log(`Running test: '${jasmine["currentTest"].fullName}'`);
//this is workaraound to avoid 'Request is already handled!' error. Shoud be removed when https://github.com/smooth-code/jest-puppeteer/issues/308 defect is fixed.
page = await browser.newPage();
await Helpers.pageSetup(page);
const context = await browser.newContext();
page = await context.newPage();
});

it("should block requests by any url fragment while test case running", async () => {
it("should block requests by any url fragment using Regex pattern while test case running", async () => {
//Arrange
const navBar = new Element(".navbar");
const requestUrlFragment = "**/topmenu.*";

await Interceptor.abortRequests(requestUrlFragment);
const requestUrlRegex = /BookStore/;
await Interceptor.abortRequests(requestUrlRegex);

//Act
await page.goto(DemoGuruSite);
await page.goto(DemoQaSite);
await loadingWrapper.waitUntilVisible();

//Assert
await expect(navBar.exists()).resolves.toBeFalsy();
await expect(booksWrapper.exists()).resolves.toBeFalsy();

//Act
await page.reload();
await loadingWrapper.waitUntilVisible();

//Assert
await expect(navBar.exists()).resolves.toBeFalsy();
await expect(booksWrapper.exists()).resolves.toBeFalsy();
});

it("should block requests by any url fragment after abort method is used", async () => {
it("should block requests by any url fragment using Glob pattern after abort method is used", async () => {
//Arrange
const navBar = new Element(".navbar");
const requestUrlFragment = "**/topmenu.*";
const requestUrlGlob = "**/BookStore/**";

//Act
await page.goto(DemoGuruSite);
await page.goto(DemoQaSite);
await loadingWrapper.waitUntilInvisible();

//Assert
await expect(navBar.exists()).resolves.toBeTruthy();
await expect(booksWrapper.exists()).resolves.toBeTruthy();

//Act
await Interceptor.abortRequests(requestUrlFragment);
await Interceptor.abortRequests(requestUrlGlob);
await page.reload();
await loadingWrapper.waitUntilVisible();

//Assert
await expect(navBar.exists()).resolves.toBeFalsy();
await expect(booksWrapper.exists()).resolves.toBeFalsy();
});

it("should block request by any url fragment after action", async () => {
//Arrange
const navBar = new Element(".navbar");
const requestUrlFragment = "**/topmenu.*";
await Interceptor.abortRequestsAfterAction(page.goto(DemoGuruSite), requestUrlFragment);

const requestUrlGlob = "**/BookStore/**";
await Interceptor.abortRequestsAfterAction(page.goto(DemoQaSite), requestUrlGlob);

//Assert
await loadingWrapper.waitUntilVisible();

//Assert
await expect(navBar.exists()).resolves.toBeFalsy();
await expect(booksWrapper.exists()).resolves.toBeFalsy();

//Act
await page.reload();
await loadingWrapper.waitUntilInvisible();

//Assert
await expect(navBar.exists()).resolves.toBeTruthy();
await expect(booksWrapper.exists()).resolves.toBeTruthy();
});

it("should block any request after action", async () => {
Expand All @@ -83,7 +90,7 @@ describe("Interceptor", () => {

//Assert
await expect(successMessage.isVisible()).resolves.toBeFalsy();
expect(alertMessage).toEqual("\nerror\nundefined");
expect(alertMessage).toContain("error", "undefined");
});

it("should count all requests", async () => {
Expand Down
10 changes: 3 additions & 7 deletions jest-playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ module.exports = {
// Describe which browsers we want to run

browsers: ["chromium", "firefox", "webkit"],

exitOnPageError: false,
launchOptions: {

// If we want to run browsers in headless mode or not,

headless: false,
headless: true,

// If we want to have opened devtools from start

devtools: false,

devtools: false
}

};

0 comments on commit 620be43

Please sign in to comment.