P. H. Nabila
P. H. Nabila

Reputation: 45

How to count the number of rows in Protractor Jasmine which doesn't have an id?

Since I just started exploring protractor, I have zero knowledge on how to count the number of rows in protractor. Could anyone please help me find it?

After Logging in to a page, I am supposed to match the number of rows. Everything I tried gives a Timeout error.

Failed: Timed out waiting for Protractor to synchronize with the page after
11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/fa
q.md
Stack:
ScriptTimeoutError: asynchronous script timeout: result was not received in
11 seconds

The above is the error message I am getting..

  <table class="table table-bordered">
                      <thead>
                          <tr>

                              <th>Data Source</th><th>Server Name</th>
                              <th>Latest Source Refresh Date</th>
                              <th>QA Last Completed</th>
                              <th>Ran By</th>
                              <th><label><input type="checkbox">&nbsp;Include in QA</label></th>
                          </tr>
                      </thead>
                      <tbody>
                          <!--template bindings={}--><tr class="success">

                              <td>Austria</td><td>CDTSSQL580P.WHSVC_AT_M_IMS_1</td>
                              <td>
                                 <!--template bindings={}--><span> Mar 08, 17</span>
                                 <!--template bindings={}--> 

                              </td>
                              <td>Mar 02, 17, 11:28 AM</td>
                              <td>ims</td>
                              <td>
                                  <!--template bindings={}--><input type="checkbox">
                                  <!--template bindings={}-->
                              </td>
                          </tr><tr class="success">

                              <td>Bulgaria</td><td>CDTSSQL807P.WHSVC_BG_M_IMS_1</td>
                              <td>
                                 <!--template bindings={}--><span> Feb 22, 17</span>
                                 <!--template bindings={}--> 

                              </td>
                              <td>Feb 15, 17, 12:15 PM</td>
                              <td>ims</td>
                              <td>
                                  <!--template bindings={}--><input type="checkbox">
                                  <!--template bindings={}-->
                              </td>
                          </tr><tr class="success">

                              <td>Czech</td><td>CDTSSQL484P.WHSVC_CZ_M_IMS_1</td>
                              <td>
                                 <!--template bindings={}--><span> Mar 12, 17</span>
                                 <!--template bindings={}--> 

                              </td>
                              <td>Feb 15, 17, 4:44 AM</td>
                              <td>ims</td>
                              <td>
                                  <!--template bindings={}--><input type="checkbox">
                                  <!--template bindings={}-->
                              </td>
                          </tr><tr class="success">

                              <td>Germany</td><td>CDTSSQL826P.WHSVC_DE_M_IMS_1</td>
                              <td>
                                 <!--template bindings={}--><span> Mar 11, 17</span>
                                 <!--template bindings={}--> 

                              </td>
                              <td>Feb 15, 17, 4:40 AM</td>
                              <td>ims</td>
                              <td>
                                  <!--template bindings={}--><input type="checkbox">
                                  <!--template bindings={}-->
                              </td>
                          </tr><tr class="success">

                              <td>Italy</td><td>CDTSSQL350P.WHSVC_IT_M_IMS_1</td>
                              <td>
                                 <!--template bindings={}--><span> Mar 05, 17</span>
                                 <!--template bindings={}--> 

                              </td>
                              <td>Feb 15, 17, 4:45 AM</td>
                              <td>ims</td>
                              <td>
                                  <!--template bindings={}--><input type="checkbox">
                                  <!--template bindings={}-->
                              </td>
                          </tr><tr class="success">

                              <td>Serbia</td><td>CDTSSQL826P.WHSVC_SR_M_IMS_1</td>
                              <td>
                                 <!--template bindings={}--><span> Feb 20, 17</span>
                                 <!--template bindings={}--> 

                              </td>
                              <td>Feb 15, 17, 4:46 AM</td>
                              <td>ims</td>
                              <td>
                                  <!--template bindings={}--><input type="checkbox">
                                  <!--template bindings={}-->
                              </td>
                          </tr><tr class="success">

                              <td>Slovakia</td><td>CDTSSQL807P.WHSVC_SK_M_IMS_1</td>
                              <td>
                                 <!--template bindings={}--><span> Mar 11, 17</span>
                                 <!--template bindings={}--> 

                              </td>
                              <td>Feb 15, 17, 4:46 AM</td>
                              <td>ims</td>
                              <td>
                                  <!--template bindings={}--><input type="checkbox">
                                  <!--template bindings={}-->
                              </td>
                          </tr><tr class="success">

                              <td>Turkey</td><td>CDTSSQL484P.WHSVC_TR_M_IMS_1</td>
                              <td>
                                 <!--template bindings={}--><span> Mar 06, 17</span>
                                 <!--template bindings={}--> 

                              </td>
                              <td>Feb 15, 17, 4:46 AM</td>
                              <td>ims</td>
                              <td>
                                  <!--template bindings={}--><input type="checkbox">
                                  <!--template bindings={}-->
                              </td>
                          </tr><tr class="success">

                              <td>UK</td><td>CDTSSQL807P.WHSVC_UK_M_IMS_1</td>
                              <td>
                                 <!--template bindings={}--><span> Mar 08, 17</span>
                                 <!--template bindings={}--> 

                              </td>
                              <td>Feb 15, 17, 4:46 AM</td>
                              <td>ims</td>
                              <td>
                                  <!--template bindings={}--><input type="checkbox">
                              <!--template bindings={}-->
                          </td>
                      </tr>
                  </tbody>
              </table>

Upvotes: 0

Views: 4639

Answers (2)

Sudharsan Selvaraj
Sudharsan Selvaraj

Reputation: 4832

You can use count() method from ElementArrayFinder to get the number of elements for given locator.

expect(element.all(by.css("table tbody tr")).count()).toBeGreaterThan(0);

To avoid ScriptTimeOutError, increase the script timeout value in your conf.js. Add the below value to your configuration file. allScriptsTimeout : 60000.

Upvotes: 0

Surendra Jnawali
Surendra Jnawali

Reputation: 3240

 element.all(by.css('tbody tr')).then(function(totalRows) {
    console.log(totalRows.length);  
    //OR Any expect(...)
 });

Upvotes: 1

Related Questions