2

TestCase: Verify the table ROW contains text.

To verify text present in Table Row, i tried Using "expect.gettext().toContain(datefinal)".
But ouput returns "Expected '7/18/17' to contain undefined."

HTML Code:

<table class="table" width="100%" cellspacing="0" cellpadding="0">
     <tbody>
     <tr class="tableheader">
     <tr>
     <td nowrap="true" align="left">
     <a 
href="/internal/servlet/internalAccountPartner&command=edit"
[email protected]</a>
      </td>
      <td align="left">7/18/17</td>

CODE:

 var dateString = "";
 var newDate = new Date();
 // Get the month, day, and year.
 dateString += (newDate.getMonth() + 1) + "/";
 dateString += newDate.getDate() + "/";
 dateString += newDate.getFullYear() - 2000;
 var datefinal = console.log(dateString);
 expect(cells.get(6).getText()).toContain(datefinal);

OUTPUT:

Expected '7/18/17' to contain undefined.

2 Answers 2

3

You are assigning datefinal to the result of the console.log() call - which is undefined, hence the error. You meant to assert against dateString string:

expect(cells.get(6).getText()).toContain(dateString);
2
  • I tried the above answer and it is giving me the below error Error: Invalid Chai property: toContain. Did you mean "contain"?
    – RRR
    Nov 14, 2018 at 12:37
  • (toConatin) is from Jasmine assertion library. It is correct.
    – Bustaq
    Nov 14, 2018 at 12:57
0

This is the function I've been working on. It takes an event name and searches for it in a grid (no paging to worry about). When found, returns the row# for use elsewhere.

verifyEventInGrid(eventName: string) {
        const names = element.all(by.className('ng-star-inserted'));
        names.count().then(function(count) {
            let rowFound = false;
            let i = 0;
            console.log('row count: ', count);
            names.get(i).getText().then(function(rowEventName) {
                do {
                    if (expect(rowEventName).toContain(eventName)) {
                        console.log(i, 'rowEventName:', rowEventName);
                        rowFound = true;
                        return i;
                    }
                    i++;
                } while (i <= count);
                console.log('row found:', i);
            });
        });
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.