pm.test('Check if employee filled their skills', function() {
jsonData.forEach(function(item) {
expect(item.MainEmployeeSkills).to.be.not.empty;
if (item.MainEmployeeSkills.length < 1) {
console.log(item.fullName + " doesn't have skills");
}
})
})
After expect code is unreachable. But I want to know that test failed and log results.
Please, help
var jsonData = [2, 2, 3, 2, 2]
jsonData.forEach(function (a) {
pm.test("Your test name", function () {
if (item.MainEmployeeSkills.length < 1) {
console.log(item.fullName + " doesn't have skills");
}
pm.expect(a).to.eql(2);
});
})
you should print it before the pm.expect as it throws an exception and nexyt line won't be executed.
Also there is no point of having for loop inside pm.text as the loop exists for the first except itself ( unless this is what you want )
If you are looking way to print descriptive assertion message yu don't havr to do this. Instead use:
pm.test('Check if employee filled their skills', function() {
jsonData.forEach(function(item) {
pm.expect(item.MainEmployeeSkills,item.fullName + " doesn't have skills").to.be.not.empty;
})
})
Related
I have created a simple script on protractor but for me the script is not running correctly. Please find the code and output
it('Test#5.5 - Select top 5 Email Dumps', async () => {
let testId = 5.5;
let timeKey = 'Select top 5 Email Dumps';
console.time(timeKey);
log.info('\n', 'Selecting top 5 Email Dumps one after one')
// let email_dumps_list = await element.all(by.xpath('//*[contains(#data-selenium,"email_dump_item")]')).count();
// log.info('list of email dumps are ' + email_dumps_list);
for (let i = 0; i < 5; i++) {
let email_dump_item = await element.all(by.xpath('//*[contains(#data-selenium,"email_dump_item")]/div/span')).get(i);
selectElementAndCheckText(email_dump_item, testId + '_' + i)
}
});
async function selectElementAndCheckText(obj, testId) {
// const email_dump_0 = await element.all(by.xpath('//*[contains(#data-selenium,"email_dump_item")]/div/span')).get(element);
let email_dump_name = await obj.getText()
log.info('Clicking on ' + email_dump_name + ' email dump')
obj.click().then(async function(){
const email_header_name = element(by.css('div[data-testid="data-dump-page"] > * .MuiToolbar-gutters'));
if (browser.wait(EC.visibilityOf(email_header_name), 5000)) {
checkText(email_dump_name, await email_header_name.getText(), 'Email details shown doesn\'t match with the selected Dump', testId)
log.info("Pass")
return true;
}
else {
log.error('Email dump details not loaded')
return false;
}
});
}
async function checkText(actualText, expectedText, errorMessage, testId) {
try {
assert.equal(actualText, expectedText, errorMessage, '\n')
} catch (error) {
console.log(error);
}
}
Output
Selecting top 5 Email Dumps one after one
[1028/234735.013:INFO:CONSOLE(1)] "true SORT", source: https://webapp-dev-raven.ocp-nonprod.com/static/js/main.88ddd1a0.chunk.js (1)
Clicking on Selenium email dump email dump
Clicking on 10k email upload test email dump
Clicking on 191 emails test email dump
Clicking on another 100 emails email dump
Clicking on simulated 100 emails email dump
AssertionError [ERR_ASSERTION] [ERR_ASSERTION]: Email details shown doesn't match with the selected Dump
at checkText (C:\Users\webapp\test\e2e\email-dumps-test.js:270:14)
at C:\Users\webapp\test\e2e\email-dumps-test.js:114:7
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: 'Selenium email dump',
expected: 'simulated 100 emails',
operator: '=='
}
Pass
AssertionError [ERR_ASSERTION] [ERR_ASSERTION]: Email details shown doesn't match with the selected Dump
at checkText (C:\Users\webapp\test\e2e\email-dumps-test.js:270:14)
at C:\Users\webapp\test\e2e\email-dumps-test.js:114:7
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: '10k email upload test',
expected: 'simulated 100 emails',
operator: '=='
}
Pass
AssertionError [ERR_ASSERTION] [ERR_ASSERTION]: Email details shown doesn't match with the selected Dump
at checkText (C:\Users\webapp\test\e2e\email-dumps-test.js:270:14)
at C:\Users\webapp\test\e2e\email-dumps-test.js:114:7
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: '191 emails test',
expected: 'simulated 100 emails',
operator: '=='
}
Pass
If you notice the output, the for loop is executing first before going in to obj.click().then function and so its printing the log and then doing the actual test. Can you please let me know if I am doing anything wrong here.
Because your function selectElementAndCheckText() and selectElementAndCheckText () are Async, so you need to prefix await when call them.
await should be added into following place:
for (let i = 0; i < 5; i++) {
let email_dump_item = await element.all(by.xpath('//*[contains(#data-selenium,"email_dump_item")]/div/span')).get(i);
await selectElementAndCheckText(email_dump_item, testId + '_' + i)
....
if (browser.wait(EC.visibilityOf(email_header_name), 5000)) {
await checkText(email_dump_name, await email_header_name.getText(), 'Email details shown doesn\'t match with the selected Dump', testId)
The example from github doesn't work for me.
https://github.com/nightwatchjs/nightwatch/issues/369
This is my code.
When('I open a new browser window', () => {
var host = 'http://www.google.com';
client
.windowHandle(function(wh){console.log(wh.value)})
.url(host)
.waitForElementVisible('#hplogo', 1000)
.execute(function(newWindow){
window.open('http://www.twitter.com', null, "height=1024,width=768");
}, [host])
.assert.urlContains('google')
.window_handles(function(result) {
var temp = result.value[1];
this.switchWindow(temp);
})
.windowHandle(function(wh){console.log(wh.value)})
.assert.urlContains('twitter')
.end();
});
Both console.log before and after .switchWindow print out the same string.
Does anyone have any ideas please...?
EDIT
I've changed the code a bit taking into account what pcalkins said.
This is the code now:
When('I open a new browser window', () => {
var host = 'http://www.google.com';
client
.windowHandle(function(wh){console.log("\nBEFORE: " + wh.value)})
.url(host)
.waitForElementVisible('#hplogo', 1000)
.execute(function(newWindow){
window.open('http://www.twitter.com', null, "height=1024,width=768");
}, [host])
.pause(3000)
.window_handles(function(result) {
console.log("\n\nHANDLE: " + result.value + "\n");
var temp = result.value[0];
this.switchWindow(temp);
console.log("\n\ntemp0: " + temp + "\n");
temp = result.value[1];
this.switchWindow(temp);
console.log("\n\ntemp1: " + temp + "\n");
})
.pause(2000);
});
When run, this is the result:
BEFORE is the handle for the original window.
HANDLE is both windows.
temp0 and temp1 are the two different windows in sequence. Clearly temp1 is the window I want, and yet the final this.switchWindow is not doing its job.
AFTER is the current window handle at the next test step.
Does anyone know a way I can automatically rerun a Nightwatch test a set number of times?
I have the following code:
module.exports = {
'Log into system - create order': function (client) {
client
.url('XXXX')
.waitForElementVisible('body', 1000)
.assert.title('Reach - Log in')
.assert.visible('#UserName')
.setValue('#UserName', 'XXXX')
.assert.visible('#Password')
.setValue('#Password', 'XXXX')
.assert.visible('input[value="Login"]')
.click('input[value="Login"]')
.waitForElementVisible('img.test', 1000)
.assert.visible('li[title="XXXX"] a[tabindex="5"]')
.click('li[title="Sales"]')
.assert.cssClassPresent('li[title="XXXX"]', 'active')
.click('a[href="/Quotes/Add"]')
.waitForElementVisible('#s2id_CustomerId_Remote', 1000)
.click('#s2id_CustomerId_Remote')
.assert.visible('#s2id_autogen2_search')
.setValue('#s2id_autogen2_search', 'bik')
.waitForElementVisible('.select2-highlighted', 1000)
.click('.select2-highlighted')
.waitForElementVisible('#customerNotes', 1000)
.click('#s2id_ProductId_Remote')
.assert.visible('#s2id_autogen3_search')
.setValue('#s2id_autogen3_search', '123XP')
.pause(5000)
.assert.visible('.select2-highlighted')
.click('.select2-highlighted')
.pause(5000)
.assert.visible('.ui-sortable > tr')
.setValue('#Quote_PONumber', 'abc123')
.click('input[value="Create Order"]')
.waitForElementVisible('.ac-order-number', 1000)
.assert.visible('a[data-value="abc123"]')
.pause(5000)
.end()
}
}
rather than .end() the test I'd like to .rerun() the test say 30 times. I can't see an option to do this anywhere in the docs.
Many thanks in advance.
You can wrap your commands in a client.perform() and a for loop
client.perform(function(){
for (i = 0; i < 29; i++) {
client
.url('XXXX')
.
.
.
.end();
}
})
What you need is a little of async iteration logic and client.perform() function :
module.exports = {
'Log into system - create order': function (client) {
var currentIteration = 0,
iterationCount = 30;
function runTest() {
client
.url('XXXX')
// ... YOUR CODE HERE, WITHOUT .end()
.perform(function() {
if (++currentIteration < iterationCount) {
return runTest();
}
client.end(); // After passing 30 iterations end the session
});
}
runTest();
}
};
If you want to repeat he test with different inputs ? then you can do something like this
module.exports = {
"Login Fail Cases": function(browser) {
let dataSet = [
{ username: "madhus", pass: "madhus" },
{ username: "admin", pass: "admin" }
];
//will run for 2 times as length of dataset is 2
dataSet.forEach(function(data) {
browser
.url("https://localhost:3000/")
// you tests here
}, this);
// note: end the test outside the loop once all tests are executed
browser.end();
}
};
We have observed that at certain times accessing the JSONStore API's hangs for long time, to make it work we have to call the function again or app has to be taken to background & bring to foreground again.
NOTE : when application faces this issue, behaviour is same until we reinstall the app or reboot the device.
There doesn't appear to be any proper scenarios for this, we have searched many articles but did not find any solution, any solutions are welcome.
We observed this issue on Android devices like S5 and S4.
Here is my code Snippet:
function getWidgets(w_id, getWidgetsSuccessCallback, getWidgetsFailureCallback) {
var query = { user_id : w_id };
var options = {};
WL.JSONStore.get(StorageCollections.widgets).find(query, options)
.then(function(arrayResults) {
var count = arrayResults.length;
Logger.debug("getWidgets: success, count: " + count);
...
getWidgetsSuccessCallback(widgets);
})
.fail(function(errorObject) {
Logger.error("getWidgets: failed, error: " + JSON.stringify(errorObject));
getWidgetsFailureCallback(errorObject);
});}
Logs when everything works fine http://pastebin.com/NVP8ycTG
Logs when accessing JSON store hangs, it will work only when app taken to background & bring back to foreground again http://pastebin.com/eYzx57qC
JSON store is initialised as below
var collections = {
// User
user: {
searchFields: {
user_id : 'string',
user_name : 'string',
first_name : 'string',
last_name : 'string',
}
}
}};
// Storage encryption
var options = {};
if (key) {
options.password = key;
options.localKeyGen = true;
}
// Open the collection
var promise = WL.JSONStore.init(collections, options)
.then(function() {
Logger.debug("initializeAppStorage: " + JSON.stringify(collections) + " completed");
initAppStorageSuccessCallback(true);
return true;
})
// Handle failure
.fail(function(errorObject) {
Logger.error("initializeAppStorage: failed, error: " + errorObject.toString());
initAppStorageFailureCallback(errorObject.toString());
return false;
});
return promise;
Thanks.
Try this one :
function getWidgets(w_id, getWidgetsSuccessCallback, getWidgetsFailureCallback) {
var query = { key : w_id };
var options = {};
WL.JSONStore.get(StorageCollections.widgets).find(query, options)
.then(function(arrayResults) {
var count = arrayResults.length;
Logger.debug("getWidgets: success, count: " + count);
...
getWidgetsSuccessCallback(widgets);
})
.fail(function(errorObject) {
Logger.error("getWidgets: failed, error: " + JSON.stringify(errorObject));
getWidgetsFailureCallback(errorObject);
});}
Hi I have a question to the azure mobile Service custom API script.
I have a custom script to create a JSON Response.
First step was to get flat objects.
Thsi is my code:
var sql = "SELECT [Project].[id] AS [ID]," +
"[Project].[Name] AS [Name]," +
"FROM [Project]";
request.service.mssql.query(sql, [], {
success: function(results) {
if (results.length === 0) {
response.json(statusCodes.OK, results);
return;
}
var resultSet = [];
results.forEach(function(poi) {
resultSet.push(
{
ID: poi.ID,
Name: poi.Name,
RelatedObjects:
{
[
**???**
]
},
});
})
response.json(statusCodes.OK, resultSet);
}
});
This works very well. Now I want to extend my result objects by some sub objects from a releated table. But not simple singel sub properties (this is easy via join), I want to add collections of sub properties selected from another table.
But I don't know how to get the second query into my code? :(
I think it has to be on "???" marked position.
I want to use this JSON self creating code because my result sets are much more complex as the example shows.
Please help!
Ok I solve it with this messi code...
I'm sure there is a more elegant way to do this but I don't found it yet.
var sql = "SELECT [Project].[ID]" +
",[Project].[Name]" +
"FROM [Project]";
var sql2 = "SELECT [ID]" +
",[UniqueSN]" +
",[Name]" +
"FROM [DataLogger]" +
"WHERE [DataLogger].[ProjectID] = ?";
request.service.mssql.query(sql, [id], {
success: function(results) {
var resultSet = [];
results.forEach(function(poi) {
var loggerResultSet = [];
request.service.mssql.query(sql2, [poi.ID], {
success: function(results2) {
results2.forEach(function(logger) {
loggerResultSet.push(
{
ID: logger.ID,
Name: logger.Name,
UniqueSN: logger.UniqueSN,
});
})
resultSet.push(
{
ID: poi.ID,
Name: poi.Name,
Logger: loggerResultSet,
});
response.json(statusCodes.OK, resultSet);
console.log(JSON.stringify(resultSet));
}
});
})
}
});