-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Support spawning additional browser instances #1537
Conversation
How does this work in practice? Wouldn't the actions across the two browser be completely out of sync since they're using different drivers' control flows? |
This is an automated message from the CLA checker script. Please sign CLA at https://developers.google.com/open-source/cla/individual Please make sure that the email associated with your PR is the same as the email you use to sign. |
@hankduan: you're right, the additional browser instances are not synced at all with the main browser. Instead, you would write test code like this: // ...
it('should receive email subscriptions', function(done) {
browser.get('apps/email.html#/' + email());
var altBrowser = browser.newInstance('apps/email.html#/' + email() + '/compose');
altBrowser.element(by.model('email.to')).sendKeys(email());
altBrowser.element(by.id('sendEmail')).click();
setTimeout(function() {
expect(element.all(by.repeater('email in emails')).count()).toBe(1);
done();
}, 1000);
});
// ... |
Actually I was wrong about that. All drivers share the same control flow now that I read through webdriverjs' code again. So, in this example
because both browser and altBrowser schedules into the same control flow, altBrowser would not actually run until browser finishes running. I think this is the behavior we want -- can't think of any reason to make multiple browsers act independent of each other since that makes the test indeterministic. That being said, I still don't like the fact that browsers don't close on their own and that you need to include runner inside protractor. Let me think on this a bit more. |
Hmm, yes, I think you're right; having the operations be serialized in the same control flow seems to be the expected behaviour. With regards to browsers not closing on their own, the easy fix is to have Runner call As to Runner being passed to Protractor, I agree that this is definitely not ideal. I don't feel like I know the Protractor code well enough to come up with a better alternative, so any input would be welcome. |
I think to deal with the runner issue, we need to go about the PR from another way. For the user this would mean having to define @jonhoo do you mind if I take this issue? |
Hmm, I'm not entirely sure that's a particularly good API to work with though. First of all, it means you need to know how many browsers to spawn before the tests are started. In most cases, that might be fine, but for some more dynamic tests, the number of browser instances could vary.. Also, if you ever add a test to a suite, and that test needs some larger number of browsers you have to remember to increment Furthermore, I'm not sure I like the
FWIW, I'm happy for you to take over the issue. |
Summarizing a conversation we had offline:
|
While it's probably true that people will be using relatively few browser instances (personally, I currently need three, but I don't envision needing many more), my objection about having to switch between browsers instead of just performing operations on one browser object or the other still hold. Being explicit about what browser you want to perform an operation on is both less error-prone and more obvious to a person reading the code than the corresponding I also feel very strongly that using numerical indices should be avoided if at all possible, as it makes it harder to recognize immediately which browser does what. |
CLAs look good, thanks! |
I see what you're saying about the browser.get() // this is the 'default' or 0th browser
element() // this works of the 0th browser
var browser2 = magicBrowserInstancesGlobal(1);
element2 = browser2.element;
$2 = browser2.$; Which is also messy. |
implemented as described: #1548 With regard to opening |
Continued in #1548. |
Many end-to-end application tests require having multiple browser instances (windows/tabs/etc.) open at the same time so that functionality across clients can be tested. This patch implements a
newInstance
method onProtractor.prototype
which returns a newProtractor
wrapping a new instance of the underlying driver.Drivers can advertise that they support this capability by exposing the
newDriverInstance
method (no arguments). This patch also implements this feature for thedirect
provider. Porting to other driver providers should be fairly straightforward, but has not been attempted.Notes about the patchset:
Protractor
now needs to have access to the driver provider, and not just the provider. It also needs access to certain parts of the config (fromRunner
) so that it can correctly set script timeouts. This has currently been solved by passing in the entireRunner
to prevent an excessive number of arguments. Perhaps a better approach would be to make a config object where the necessary parameters (includingbaseUrl
androotEl
) are contained.Runner
(and nowProtractor
). Would it not be better for this to always be done by the driver? Or maybe even now byProtractor
?newDriverInstance
be added to the driver provider interface overview?This PR fixes #381.