Вопрос

I want to get the amount of rows in a table on my page. I am trying to do this using .execute(function(){}) but how is it possible to get a variable out of the execute function and use it there. this isn't the counter yet, buy i can't even get a variable to work. i tried something like this:

.execute(function(){
    global.amountOfRows = 5;
})

.assert.numberOfElements('#content-list > tbody > tr', global.amountOfRows)

i tried the same using var amountOfRows = 5;

Any ideas?

Это было полезно?

Решение

Using jquery to return the number of row in your table body

$('#your_table_id tbody').find('tr').length;
http://api.jquery.com/length/ 

I tried this but it didnt work out as planned.

Другие советы

Using jquery to return the number of row in your table body

$('#your_table_id tbody').find('tr').length;

http://api.jquery.com/length/

unfortunately Dalek doesn't has the capability to do assertions on data you did get out of a execute statement at the moment, but there is a workaround for you ;)

.execute(function(){
    // store as a `data` var
    this.data('amountOfRows', 5);
})
// doSomeOtherStuff
.execute(function () {
  // using jquery here to keep it short
  var actualNumberOfRows = $(''#content-list > tbody > tr').length;
  // do an "in browser" assertion
  this.assert.ok((actualNumberOfRows === this.data('amountOfRows')), 'Amount of rows is as expected');
})
.done();

You can find further info on this undocumented API here: https://github.com/asciidisco/jsdays-workshop/blob/5-js/test/dalek/javascript.js#L16-L29

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top