dalekjs / dalek

[unmaintained] DalekJS Base framework
MIT License
695 stars 63 forks source link

Retrieve Value from Browser #85

Open justrhysism opened 10 years ago

justrhysism commented 10 years ago

This is a feature request. Similar to this on StackOverflow http://stackoverflow.com/questions/22160407/dalekjs-retrieve-value-from-browser

I would like to be able to do something like this:

// Non-working example
module.exports = {
  'My Test': function(test) {
    var foo;

    test
    .open('http://localhost/mysite')
    .execute(function(){
      foo = document.getElementById('bar');
    })
    .assert.text('#myField').is(foo)
    .done();
  }
}

I have a use case where I actually need to go to a new page in between, which is why the work around listed on SO isn't suitable.

asciidisco commented 10 years ago

Hi @justrhysism,

yep this is one of the most anticipated features for the 0.1.0 (btw.: I gave up estimating a date for it...).

At the moment there is one workaround for that issue, but it isn't that cool:

module.exports = {
  'My Test': function(test) {
    var foo;

    test
    .open('http://localhost/mysite')
    .execute(function(){
      foo = document.getElementById('bar').innerText;
      this.data('foo', foo);
    })
    .execute(function () {
      this.assert.ok( (document.getElementById('myField').innerText === this.data('foo')), 'Text is correct');
    })
    .done();
  }
}

Should also work with a page load in between.