Skip to content

Instantly share code, notes, and snippets.

@stevgouws
Last active March 27, 2020 15:59
Show Gist options
  • Save stevgouws/0d8599c218302b5ad847f8faca27d24c to your computer and use it in GitHub Desktop.
Save stevgouws/0d8599c218302b5ad847f8faca27d24c to your computer and use it in GitHub Desktop.
Automation Sneek Peek

Example of Test

Below shows a normal jest test file with:

  • DriverFor helper to setup and configure specific browsers
  • TicketMasterTestBundle which holds all TM specific tests
  • EventPageTestBundle example of how you can just pull in another test bundle (this one for example is used in basic flow as well)
  • You can specify individual tests to run, or all to simply run all the tests in that bundle
const TicketmasterTestBundle = require("../testBundles/ticketmasterTestBundle");
const EventPageTestBundle = require("../testBundles/searchPageTestBundle");

const DriverFor = require("../../utils/driverFor");

describe("Ticketmaster", () => {
  // Helper for configuring different browser setups
  let driver = new DriverFor("safari", {
    width: 320,
    height: 567,
  });
  afterAll(() => driver.quit());
  // Ticketmaster specific tests
  new TicketmasterTestBundle({
    driver,
    run: ["eventTitleIsNotClickable", "showSendMethods"],
    forMobile: true,
  });
  // Example of pulling in another bundle to extend your tests
  new EventPageTestBundle({
    driver,
    run: "all",
    forMobile: true,
  });
});

Example of Test Bundle

A test bundle holds your individual tests.

  • You can define multiple methods to split up your tests as required for re-use elsewhere.
  • You can have multiple it blocks per test if they depend on each other.
  • Jest setup and teardown methods are retained via class methods with the same name, eg. beforeEach etc.
const SearchResultsPage = require("../../pageObjectModels/testQa/searchResults/searchResultsPage");
const criteria = require("../../testCriteria/testCriteriaNoBasketing");
const EventPage = require("../../pageObjectModels/testQa/event/eventPage");
const SeatsReviewPage = require("../../pageObjectModels/testQa/seatsReview/seatsReviewPage");
const TestBundle = require("./testBundle");

class TestEventPageBundle extends TestBundle {
  constructor({ driver, run: testList }) {
    super(testList, TestEventPageBundle);
    this.eventPage = new EventPage(driver, criteria.eventPage.url);
    this.seatsReviewPage = new SeatsReviewPage(
      driver,
      criteria.seatsReviewPage.url
    );
    this.searchPage = new SearchResultsPage(
      driver,
      criteria.searchResultsPage.url
    );
  }

  async beforeAll() {
    console.log("-----> before ALL");
    const events = await this.searchPage.getEventList();
    events[0].click();
  }

  beforeEach() {
    console.log("before EACH"); // etc
  }

  showCtaButton() {
    it("should display call-to-action button, text content - `Find Tickets`, and href pointing to booking page", async () => {
      const callToActionText = await this.eventPage.getFindTicketsBtnText();
      const callToActionHref = await this.eventPage.getFindTicketsBtnHref();
      expect(callToActionText).toEqual(
        criteria.eventPage.eventPageFindTicketsText
      );
      expect(callToActionHref).toEqual(criteria.bookingPage.url);
    });
  }

  showSeatsReviewPageLink() {
    it("should display link to seats review page", async () => {
      const venueLinkHref = await this.eventPage.getVenueLinkHref();
      expect(venueLinkHref).toEqual(criteria.seatsReviewPage.url);
    });
  }

  clickSeatsReviewPageLink() {
    it("should redirect to seats review page when clicked the seats review link", async () => {
      await this.eventPage.clickVenueLink();
      const currentUrl = await this.seatsReviewPage.getCurrentUrl();
      expect(currentUrl).toEqual(criteria.seatsReviewPage.url);
    });
  }
}

module.exports = TestEventPageBundle;

Other examples

Because we can extract test bundles, we can avoid having to have separate tests for basketing and non-basketing (or for that matter any other control panel config). So instead of having basicFlowNoBasketing.test.js and basicFlowBasketing.test.js you could just do something like

basicFlow.test.js

...

process.env.BASKETING 
  ? new BasketingBookingPageTestBundle({ driver, run: "all" });  
  : new NoBasketingBookingPageTestBundle({ driver, run: "all" });

You also don't have to convert everything in a test to bundles immediately as bundles and normal it blocks can co-exist eg,

... 
new IndexPageTestBundle({ driver, run: "performSearch" });
new SearchPageTestBundle({ driver, run: "all" });
new EventPageTestBundle({
  driver,
  run: [
    "showCtaButton",
    "showSeatsReviewPageLink",
    "clickSeatsReviewPageLink",
  ],
});

describe("seats review page", () => {
  it("should display correct venue title", async () => {
    await driver.sleep(500);
    const venueTitleText = await seatsReviewPage.getVenueTitleText();

    expect(venueTitleText).toEqual(criteria.seatsReviewPage.venueName);
  });

  it("should display seats review tab as page loaded", async () => {
    const tabs = await seatsReviewPage.getNavTabs();
    const tabClass = await tabs[1].getAttribute("class");

    expect(tabClass).toContain("active");
  });

  it("should display seats review content", async () => {
    const seatsReviewContainer = await seatsReviewPage.getSeatsReviewContainer();
    const seatsReviewIsDisplayed = await seatsReviewContainer.isDisplayed();

    expect(seatsReviewIsDisplayed).toEqual(true);
  });

  it("should display correct seats review title", async () => {
    const seatsReviewTitleText = await seatsReviewPage.getSeatsReviewTitleText();

    expect(seatsReviewTitleText).toEqual(
      criteria.seatsReviewPage.seatsReviewTitle
    );
  });
});

new NoBasketingBookingPageTestBundle({ driver, run: "all" }); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment