Skip to content

Instantly share code, notes, and snippets.

@wlsf82
Created January 4, 2017 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wlsf82/428f8696c24d60ba3960c7377105398b to your computer and use it in GitHub Desktop.
Save wlsf82/428f8696c24d60ba3960c7377105398b to your computer and use it in GitHub Desktop.
// And here is the solution I'm trying to implement
// page object file
"use strict";
const defaultTimeout = 10000;
class RoomActivity {
constructor () {
this.activityList = element(by.css("room-activity"));
this.roomActivityButton = element(by.css(".roomactivity"));
this.favoriteRooms = this.activityList.element(by.css("favorite-rooms"));
this.favoritesTitle = this.favoriteRooms.element(by.css("h1"));
this.favoritesTitleIcon = this.favoritesTitle.element(by.css(".favorite-room-icon"));
this.favoritesExplanationParagraph = this.favoriteRooms.element(by.css("p.empty-list-message"));
this.favoritesItems = element.all(by.css("favorite-rooms ul li"));
this.listItems = element.all(by.css(".room-list-item-wrapper .room-name"));
this.refreshButton = element(by.css(".refresh-button"));
}
removeFirstItem() {
browser.executeScript('document.querySelector(".room-list-item-wrapper .close-button").click();');
}
waitForActivityListToHaveSpecificNumberOfItems(numberOfItems, timeout = defaultTimeout) {
browser.wait(this.activityListHasSpecificNumberOfItems(numberOfItems), timeout);
}
activityListHasSpecificNumberOfItems(numberOfItems) {
return this.listItems.count().then((numberOfItemsCounted) => {
return numberOfItemsCounted === numberOfItems;
});
}
}
module.exports = RoomActivity;
------------------------------------------------------------------------------------------
// spec.js file
"use strict";
const AppearInRoom = require("../page-objects/appearInRoom");
const Helper = require("../helper");
const RoomActivity = require("../page-objects/roomActivity");
const shortid = require("shortid");
describe("Activity list", () => {
const appearInRoom = new AppearInRoom();
const helper = new Helper();
const roomActivity = new RoomActivity();
let randomRoomName;
beforeEach(() => {
randomRoomName = shortid.generate();
appearInRoom.visit(randomRoomName);
helper.clickWhenClickable(roomActivity.refreshButton);
helper.sleepForNSeconds(3);
});
it("should remove item from the activity list", () => {
roomActivity.listItems.count().then((numberOfItemsBeforeRemoval) => {
roomActivity.removeFirstItem();
helper.waitForActivityListToHaveSpecificNumberOfItems(roomActivity.listItems, numberOfItemsBeforeRemoval - 1);
roomActivity.listItems.count().then((numberOfItemsAfterRemoval) => {
roomActivity.waitForActivityListToHaveSpecificNumberOfItems(numberOfItemsBeforeRemoval - 1);
expect(numberOfItemsAfterRemoval).toEqual(numberOfItemsBeforeRemoval - 1);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment