Giter Site home page Giter Site logo

Comments (8)

juliemr avatar juliemr commented on May 6, 2024

I'd considered this and wasn't sure what would be most intuitive to people - truly wrapping the driver, or keeping both around. I take this as a vote for the former, and I think I prefer that as well. I'd love to hear others' votes, too.

from protractor.

geddski avatar geddski commented on May 6, 2024

I agree, I think keeping both around would be good. That way some e2e tests could simply use the driver for non-angular pages.

Currently when I try to use them side by side like so:

ptor.get("http://www.smashingmagazine.com");    
driver.getTitle().then(function(title) {...

It errors out:

UnknownError: Error Message => 'Detected a page unload event; asynchronous script execution does not work across page loads.'

After we fix that, maybe we just add a driver property to the ptor instance so it doesn't have to be passed around manually:

ptor.get("http://www.smashingmagazine.com");    
ptor.driver.getTitle().then(function(title) {...

Thoughts?

EDIT: looks like there already is a driver property on the instance. So just fixing the other issue may be sufficient.

from protractor.

juliemr avatar juliemr commented on May 6, 2024

Heya,

Added full wrapping on the 'wrapfix' branch with 40d8a7a. Does this look sane (and fix your issue?)

from protractor.

tbosch avatar tbosch commented on May 6, 2024

Hi Julie,
I don't know webdriver in detail, but maybe you also need to preserve the this pointer in the webdriver functions to point to the webdriver instance, e.g.

// Mix all other driver functionality into Protractor.
for (var foo in webdriver) {
   if(!this[foo]) {
     this[foo] = webdriver[foo].bind(webdriver);
   }
}

Furthermore, for chaining functions, your mixed in functions should return the protractor instance, and not the webdriver instance, e.g.

// Mix all other driver functionality into Protractor.
for (var foo in webdriver) {
   if(!this[foo]) {
     mixin(this, webdriver, foo);
   }
}

function mixin(self, webdriver, fnName) {
    self[fnName] = function() {
        var res = webdriver[fnName].apply(this, arguments);
        if (res===webdriver) {
            res = self;
        }
        return res;
    }
}

Does this make sense?
Tobias

from protractor.

juliemr avatar juliemr commented on May 6, 2024

Tobias - thanks for the comments, can't believe I forgot to fix the binding.

However, on second thought, it might be best to really just delegate to webdriver, since there aren't any non-function members of the webdriver object that I want to copy to the protractor object. For example:

for (var foo in webdriver) {
  if(!this[foo] && typeof webdriver[foo] == "function") {
    this[foo] = function() {
      return webdriver[foo](webdriver, arguments);
    };
  }
}

Any comments on this style?

from protractor.

juliemr avatar juliemr commented on May 6, 2024

Alternative B: Decorate the webdriver instance, instead of creating a separate protractor object.

Protractor.wrapDriver = function(webdriver) {
  webdriver.extend(Protractor.prototype);
};

from protractor.

juliemr avatar juliemr commented on May 6, 2024

Implemented Tobias's suggestion (minus chaining, since there is no chaining in webdriverjs) with 1ef76dc

from protractor.

juliemr avatar juliemr commented on May 6, 2024

Merged into master. Thanks for the comments, everyone!

from protractor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.