Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{Draft} Refactor: Test cases #4

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
10 changes: 5 additions & 5 deletions lib/pages/api/method/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = {
url: '/api/:apiMethod.html',
url: '/api/clearValue.html',
vaibhavsingh97 marked this conversation as resolved.
Show resolved Hide resolved

sections: {
container: {
selector: '#apimethod-page',
elements: {
header: '.page-header h2'
}
}
}
header: '.page-header h2',
},
vaibhavsingh97 marked this conversation as resolved.
Show resolved Hide resolved
},
},
};
6 changes: 3 additions & 3 deletions lib/pages/api/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {

sections: {
apiContainer: {
selector: '#api-container'
}
}
selector: '#api-container',
},
},
};
35 changes: 19 additions & 16 deletions lib/pages/examples/window.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
module.exports = {
//url: '/__e2e/window/',
url: 'https://nightwatchjs.org/__e2e/window/',
commands: [{
login() {
this
.waitForElementVisible('form', 3000)
.setValue('@email', '[email protected]')
.clearValue('#exampleInputPassword1')
.setValue('#exampleInputPassword1', 'password');
commands: [
{
login() {
this.waitForElementPresent('form', 5000)
.setValue('@email', '[email protected]')
.clearValue('@password')
.setValue('@password', 'password');

this.api.pause(700)
.elements('css selector', 'body', res => {
this.clearValue('#exampleInputPassword1')
})
.click('button[type=submit]');
}
}],
this.api
.pause(700)
.elements('css selector', 'body', () => {
this.clearValue('@password');
})
.click('button[type=submit]');
},
},
],

elements: {
container: '#releases-container',
openWindowBttn: '#openWindowBttn',
email: '#exampleInputEmail1'
}
email: '#exampleInputEmail1',
password: '#exampleInputPassword1',
},
};
36 changes: 17 additions & 19 deletions lib/pages/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,33 @@ module.exports = {
url: '/',
commands: [],
elements: {
indexContainer: '#index-container'
indexContainer: '#index-container',
},
sections: {
navigation: {
selector: '#navigation',

sections: {
navbarHeader: {
selector: '.navbar-header',
index: 2,

elements: {
versionDropdown: 'select.version-dropdown',
versionDropdownOption: 'select.version-dropdown option'
}
}
}
},
navbarHeader: {
selector: '.navbar-nav.ml-md-auto.nav.navbar-right',
index: 1,

elements: {
versionDropdown: '#bd-versions',
versionDropdownOption: {
selector: '.dropdown-item',
},
},
},
indexContainer: {
selector: '#index-container',
sections: {
download: {
selector: '.download',
elements: {
installButton: '.btn-download'
}
}
}
}
}
installButton: '.btn-download',
},
},
},
},
},
};
11 changes: 5 additions & 6 deletions test/apimethod-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ module.exports = {
this.apiPage.navigate();
},

'navigate to an individual api method page' (client) {
'navigate to an individual api method page': function (client) {
this.apiMethodPage.navigate({
apiMethod: 'clearValue'
apiMethod: 'clearValue',
});

client.expect.title().to.startWith('clearValue');
client.pause(1000).expect.title().to.startWith('clearValue');
vaibhavsingh97 marked this conversation as resolved.
Show resolved Hide resolved

this.apiMethodPage.section.container
.expect.element('@header').text.to.contain('.clearValue()');
this.apiMethodPage.section.container.expect.element('@header').text.to.contain('.clearValue()');
},

after(client) {
client.end();
}
},
};
13 changes: 6 additions & 7 deletions test/examples/form-input.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
module.exports = {
start(client) {
this.page = client.page.examples.window();
this.page
.navigate()
.assert.elementPresent('@container');
this.page.navigate().assert.elementPresent('@container');
},

demoAsync: async function(browser) {
demoAsync: async function (browser) {
const result = await browser.getText('#releases-container h1');
browser.assert.equal(result.value, 'Sample E2E Tests');
},

'demo switch window and login form': function(browser) {
// TODO: fix safari case failing
'demo switch window and login form': function (browser) {
this.page.click('@openWindowBttn');

browser.windowHandles(function(result) {
browser.windowHandles(function (result) {
browser.assert.strictEqual(result.value.length, 2);
browser.switchWindow(result.value[1]);
});

this.page.login();
},

after: client => client.end()
after: (client) => client.end(),
};
15 changes: 8 additions & 7 deletions test/homepage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ module.exports = {
this.homepage = client.page.home();
},

startHomepage: function(c) {
startHomepage: function () {
this.homepage.navigate();
this.homepage.expect.section('@indexContainer').to.be.visible;
},

'check if version dropdown is enabled and contains the correct version' (client) {
const navigation = this.homepage.section.navigation;
const navbarHeader = navigation.section.navbarHeader;
'check if version dropdown is enabled and contains the correct version': function () {
const navbarHeader = this.homepage.section.navbarHeader;

navbarHeader.expect.element('@versionDropdown').to.be.enabled;
navbarHeader.expect.element('@versionDropdownOption:first-child').text.to.equal(client.globals.nightwatchVersion);
this.homepage.expect.section('@navbarHeader').to.be.enabled;
navbarHeader.expect.element('@versionDropdown').to.be.visible;
navbarHeader.expect.element('@versionDropdown').text.to.equal('1.6.2');
navbarHeader.expect.elements('@versionDropdownOption').count.to.equal(5);
},

after(client) {
client.end();
}
},
};
64 changes: 42 additions & 22 deletions test/issues/1996-elementIdElements.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
'@tags': ['vaibhav'],
before(client) {
this.homepage = client.page.home();
},
Expand All @@ -7,39 +8,58 @@ module.exports = {
this.homepage.navigate();
this.homepage.expect.section('@indexContainer').to.be.visible;

const topElementResult = await client.element('css selector', '#navbar-toprightindex select');
client.assert.ok(client.WEBDRIVER_ELEMENT_ID in topElementResult.value, `The Webdriver Element Id ${client.WEBDRIVER_ELEMENT_ID} is found in the result`);
const topElementResult = await client.element('css selector', '.nav-item.dropdown');

this.topElementId = topElementResult.value[client.WEBDRIVER_ELEMENT_ID];
},
let key = Object.keys(topElementResult.value)[0];
let elementID = topElementResult.value[key];

client.assert.ok(key in topElementResult.value, `The Element Id ${key} is found in the result`);

'check if elementIdElements works as expected': async function(client) {
const dropdownResult = await client.elementIdElements(this.topElementId, 'css selector', 'option');
client.assert.equal(dropdownResult.value.length, 2, 'There are two option elements in the drop down');
this.topElementId = elementID;
},

'check if elementIdElement (single) works as expected': async function(client) {
const dropdownResult = await client.elementIdElement(this.topElementId, 'css selector', 'option');
client.assert.ok(client.WEBDRIVER_ELEMENT_ID in dropdownResult.value, `The Webdriver Element Id ${client.WEBDRIVER_ELEMENT_ID} is found in the dropdown result`);
'check if elementIdElements works as expected': async function (client) {
const dropdownResult = await client.elementIdElements(
this.topElementId,
'css selector',
'a[class="dropdown-item"]'
);
client.assert.equal(dropdownResult.value.length, 4, 'There are two option elements in the drop down');
},

'check if elementIdElements works as expected on page objects': async function() {
const navigation = this.homepage.section.navigation;
const navbarHeader = navigation.section.navbarHeader;
'check if elementIdElement (single) works as expected': async function (client) {
const dropdownResult = await client.elementIdElement(this.topElementId, 'css selector', 'a[class="dropdown-item"]');

const result = await navbarHeader.api.elementIdElements('@versionDropdown', 'css selector', 'option');
navbarHeader.assert.equal(result.value.length, 2, 'There are two option elements in the drop down');
let key = Object.keys(dropdownResult.value)[0];

client.assert.ok(key in dropdownResult.value, `The Webdriver Element Id ${key} is found in the dropdown result`);
},

'check if elementIdElement (single) works as expected on page objects': async function(client) {
const navigation = this.homepage.section.navigation;
const navbarHeader = navigation.section.navbarHeader;
// TODO:: Fix after fixing page object
// 'check if elementIdElements works as expected on page objects': async function (client) {
// const navbarHeader = this.homepage.section.navbarHeader;

const result = await navbarHeader.api.elementIdElement('@versionDropdown', 'css selector', 'option');
client.assert.ok(client.WEBDRIVER_ELEMENT_ID in result.value, `The Webdriver Element Id ${client.WEBDRIVER_ELEMENT_ID} is found in the result`);
},
// navbarHeader.source((res) => console.log(res));
// const result = await navbarHeader.api.elementIdElements(
// '@versionDropdown',
// 'css selector',
// 'a',
// (res) => console.log(res)
// );
// navbarHeader.assert.equal(result.value.length, 2, 'There are two option elements in the drop down');
// },

// 'check if elementIdElement (single) works as expected on page objects': async function (client) {
// const navbarHeader = this.homepage.section.navbarHeader;

// const result = await navbarHeader.api.elementIdElement('@versionDropdownOption', 'css selector', 'a');
// client.assert.ok(
// client.WEBDRIVER_ELEMENT_ID in result.value,
// `The Webdriver Element Id ${client.WEBDRIVER_ELEMENT_ID} is found in the result`
// );
// },
Comment on lines +41 to +59
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beatfactor I need help here,
const result = await navbarHeader.api.elementIdElement('@versionDropdownOption', 'css selector', 'a');
I am getting empty value whenever I run this case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image


after(client) {
client.end();
}
},
};