2

If I have a single spec that is using page object model, how do I run multiple browser instance for that same spec?

For example I have spec:

it('should run multi browser', function() { browser.get('http://example.com/searchPage'); var b2 = browser.forkNewDriverInstance(); b2.get('http://example.com/searchPage'); var b3 = browser.forkNewDriverInstance(); b3.get('http://example.com/searchPage'); SearchPage.searchButton.click(); b2.SearchPage.searchButton.click(); //fails here b3.SearchPage.searchButton.click(); }); 

How do I reuse vars declared in the SearchPage page object for the other browser instances?

1
  • Has the answer helped to solve the issue? Thanks. Commented Jun 16, 2015 at 16:56

1 Answer 1

2

This is a really interesting question that is not covered in Using Multiple Browsers in the Same Test or in the interaction_spec.js.

The problem with page objects is that page object fields are usually defined with a globally available element or browser which in your case would always point to the first browser instance. But you basically need to call element() using a specific browser:

b2.element(by.id('searchInput')); 

instead of just:

element(by.id('searchInput')); 

FYI, element is just a shortcut for browser.element.


I am really not sure whether this is a reliable solution and would actually work, but you can redefine global element this way. Think about it as switching the search context to different browser instances:

SearchPage.searchButton.click(); global.element = b2.element; SearchPage.searchButton.click(); global.element = b3.element; SearchPage.searchButton.click(); global.element = browser.element; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.