Find a value in a grid with protractor - protractor

I use the FindRow function that I found here : How to test ag-grid with protractor?
but unfortunately when I execute the function, it returns me a known error message:
Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By(css selector, .ag-body-container > .ag-row)
this my test code :
it('My Test', async function() {
const rows = element.all(by.css('.ag-body-container > .ag-row'));
const row = await findRow(rows, 'Some Text');
expect(await row.getText()).toContain('Some Text');
});
this my function :
async function findRow(rows, matcher) {
const relevantRow = await rows.filter(row => {
return row.getText().then(text => {
return text.includes(matcher);
});
}).first();
return relevantRow;
}
I have already tried the following solution but without success :
var EC = protractor.ExpectedConditions;
browser.wait(EC.visibilityOf(rows), 500);
I know that this error message often comes up in e2e tests, but I can't find a solution.
if there is another solution that would allow me to find a value in a grid I am also interested

Related

Get data from DocumentReference flutter

I am trying to update a document using a Cloud Store trigger function. Below is the code but when I try to deploy the function I get this error:
119:30 error Parsing error: Unexpected token deviceDoc
✖ 1 problem (1 error, 0 warnings)
exports.onTrxnUpdate = functions.firestore.document('/trxns/{trxnId}').onUpdate((change, context) => {
const afterData = change.after.data();
const agentId = afterData.agentId;
console.log('agentId: ', afterData.agentId);
console.log('A transaction has been updated');
/**** GET DEVICE INFORMATION ****/
const deviceDoc = db.collection('device').doc(agentId);
console.log('deviceDoc: ', deviceDoc);
if (deviceDoc == null) {
console.log('No device document found');
}
const deviceData = await deviceDoc.get(); <<<< THIS IS THE PROBLEM CODE
});
The last line is the one that is causing the error but I don't know why. I use this same line in another function and it works there.
Please help!
Thanks
You need to add async to your callback like below:
exports.onTrxnUpdate = functions.firestore.document('/trxns/{trxnId}').onUpdate(async (change, context) => {
//... rest of the code
});

How to fix a Wait condition error?

I have a browser.wait() in an E2E test which is invoking a function defined in protractor.config.js file. When running the test, I get the following error:
Failed: Wait condition must be a promise-like object, function, or a Condition object
FYI - the function defined in protractor.config.js contains an If-condition which I need for two cases. When I remove the If-condition, the test runs fine. The function returns a: deferred.promise
What does this exactly means and how to fix it? Have been searching, but unfortunately can't anything related to it.
Function in protractor.config.js:
checkMail: function(user, subjectSent) {
const deferred = protractor.promise.defer();
var usermail;
var mailsubject;
var count = 0;
mailListener.on("mail", function(mail, seqno, attributes) {
var mailuid = attributes.uid;
var toMailbox = '[Gmail]/All Mail';
var i = ++count;
user = mail.to[0].address;
mailsubject = mail.subject;
if (i > 2) {
mailListener.stop();
return;
}
deferred.fulfill(mail);
});
if ((user === usermail) && (subjectSent === mailsubject)) {
return deferred.promise;
}
}
E2E it-function:
it("It should do xxxxxxx", (done) => {
browser.wait(browser.params.checkMail('user_email#yyyyy.com', 'Email subject'))
.then((email) => {
expect(email['subject']).toEqual("Email subject");
expect(email['headers'].to).toEqual( 'user_email#yyyyy.com' );
});
done();
});

Protractor- automate the error message on tab out when input field is empty

I have an angular2 application where I am trying to write end to end test cases to automate things.I have just begun with learning Protractor for this and trying to implement a negative test case for a form field where if any field is empty, the error message should be shown. I have tried something like below to automate the form and its working fine.
In my spec.ts-
import userDetailsPage from './userDetails.e2e-po;
it('should fill out User Details', () => {
const userDetail: IUserDetail = {
firstName: 'Lorem',
lastName: 'Ipsum'
};
userDetailsPage.populateUserDetails(userDetail);
});
In userDetails.e2e-po-
populateUserDetails(details: IUserDetail) {
this.fillFirstName(details.firstName)
.fillLastName(details.lastName)
return this;
}
I am writing the below code which automatically inputs the firstName and lastName field.
fillLastName(last: string) {
let el = element(by.css('input[name="lastName'));
el.clear().then(() => {
el.sendKeys(last);
});
return this;
}
The above scenario works fine. But I am also trying to achieve a scenario where I do not input either first name or last name field, should throw me an error message.Can someone let me know what else should I add to achieve this.
I am already handling the validation in my HTML.
Any help is much appreciated.
Instead of details.firstname and details.lastname put empty strings and then validate the error that occurs on the page.
I think you can try the following method as a reusable function
function formValidate(donefn){
newProjBtn.click().then(async function () {
var lastName_fld = element(by.css('input[name="lastName'));
await lastName_fld.sendKeys("", protractor.Key.TAB);
//browser.sleep(2000);
var elm = element(by.css(".error-message"));
elm.isPresent().then(function(result){
if(result){
console.log("Error message displayed")
//some more code to do like selecting the field and enter the test
return result;
}else{
console.log("Error message not displayed")
return result;
}
})
donefn();
})
I solved it in this way:
await input.sendKeys(protractor.Key.CONTROL, 'a');
await input.sendKeys(protractor.Key.BACK_SPACE);
await input.sendKeys(protractor.Key.TAB);
//then the error-message will appear

protractor first() is working and get(0) is not

There's a troncated code of a page Object in protractor
that code is working :
var HomePage = function() {
this.publishedShows = element.all(by.repeater('show in showsHomePage'));
this.getFirstShow = function(){
return this.publishedShows.first();
}
};
this one is not :
var HomePage = function() {
this.publishedShows = element.all(by.repeater('show in showsHomePage'));
this.getFirstShow = function(){
return this.publishedShows.get(0);
}
};
I get this error :
Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator by.repeater("show in showsHomePage")
Anyone can inlight me?
It is not about get(0) vs first() - they are absolutely the same in terms of implementation. It is probably about the timing, wait for the presence of the element before making any action with it:
var elm = myPageObject.getFirstShow();
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(elm), 5000);
// do smth with elm
alecxe does have a point about waiting for the element to be present and so you may want to the wait as mentioned or browser.waitForAngular();
What I have seen is that if you resolve a finder to a variable then this can get left in the unfulfilled promise state (even though the internals have resolved the query). What needs to be done is to resolve the promise and then you should be able to get the element you require:
So from your code:
`this.publishedShows = element.all(by.repeater('show in showsHomePage'));`
Will still be a promise and not publishedShows.
This returns items when I try your code (I have a slightly different repeater).
var HomePage = function() {
this.publishedShows = element.all(by.repeater('show in showsHomePage'));
this.getFirstShow = function() {
return this.publishedShows.then(function(items){
=>return items[0].getText();
});
}
};
var hp = new HomePage();
=>expect(hp.getFirstShow()).toEqual('hello');
Obviously change your expect to what you want to check for and also the return too. Marked with =>
Ensure also that if you use any track by statement then you should look at the by.exactRepeater command to have an exact match on only the repeater part.
This worked for me, note the resolved promise returns an array of finders.

Is there an efficient way to assert that all the elements of a PageObject are visible?

It's great how you can describe key elements of a page using the elements object in nightwatch's PageObject.
A very basic test of "is the page rendered correctly?" seems to consist of a string of asserts that every element is visible:
'Does it look right' : function (browser) {
browser.page.welcome()
.navigate()
.assert.title('My App')
.assert.visible('#header')
.assert.visible('#usernameField')
.assert.visible('#passwordField')
.assert.visible('#forgotPasswordLink')
.assert.visible('#signupButton')
Is there a more efficient way to do this?
You can run a script with your custom logic and then test against that
var script = function () {
//some logic or query selector test
return foo;
};
module.exports = {
'Test PCC': function (browser) {
var test;
browser
url('foo')
.waitForElementVisible('body', 1000)
.execute(script, [], function (response) {
console.log(response);
test = response.value;
})
//assert. test is something
.end();
}
};