Skip to content

Commit

Permalink
Fix Google page object example (#4118)
Browse files Browse the repository at this point in the history
  • Loading branch information
uditrajput03 authored Mar 16, 2024
1 parent d020318 commit d183d2a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/pages/google/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
consentModal,

searchBar: {
selector: 'input[name=q]'
selector: 'textarea[name=q]'
},

submitButton: {
Expand Down
13 changes: 8 additions & 5 deletions examples/pages/google/searchResults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const util = require('util');
const menuXpath = '//div[contains(@class, "hdtb-mitem")][contains(., "%s")]';

// starting xpath with './/' tells browser to begin search from the current element,
// while starting with '//' tells browser to begin search from the start of html document.
const menuXpath = './/span[contains(text(), "%s")]';

const menuCommands = {
productIsSelected: function (product, callback) {
Expand All @@ -18,15 +21,15 @@ module.exports = {
},
sections: {
menu: {
selector: '#hdtb-msb',
selector: 'div[role="navigation"] div[data-st-cnt="mode"]',
commands: [menuCommands],
elements: {
all: {
selector: util.format(menuXpath, 'All'),
maps: {
selector: util.format(menuXpath, 'Maps'),
locateStrategy: 'xpath',
index: 0
},
video: {
videos: {
selector: util.format(menuXpath, 'Videos'),
locateStrategy: 'xpath',
index: 0
Expand Down
22 changes: 1 addition & 21 deletions examples/tests/googlePageObject.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
describe('google search with consent form - page objects', function() {

this.disabled = this.argv.env !== 'chrome';

const homePage = browser.page.google.search();
const consentPage = browser.page.google.consent();

before(async () => homePage.navigate());

after(async (browser) => browser.quit());

it.only('should complete the consent form', async function (browser) {

// const consentForm = consentPage.section.consentForm;
// const submitButton = consentForm.element('@submitButton');

const oldElement = await browser.element('css selector', 'body');
const consentPresent = await homePage.isPresent('@consentModal');

if (consentPresent) {
await homePage.expect.section('@consentModal').to.be.visible;

const {consentModal} = homePage.section;
await consentModal.click('@rejectAllButton');
}
});

it('should find nightwatch.js in results', function (browser) {
homePage.setValue('@searchBar', 'Nightwatch.js');
homePage.submit();
Expand All @@ -37,6 +17,6 @@ describe('google search with consent form - page objects', function() {
resultsPage.expect.section('@menu').to.be.visible;

const menuSection = resultsPage.section.menu;
menuSection.expect.element('@all').to.be.visible;
menuSection.expect.element('@videos').to.be.visible;
});
});

0 comments on commit d183d2a

Please sign in to comment.