In my protractor tests I want to do something in a page (page1). After that in the same testscript I want to go to another page (page2) to check the results.
describe('something', function() {
describe('foo', function() {
browser.get(url_1);
it("should do something with elem1 on page1", function() {
var elem1 = element(by.css("..."));
...
});
});
describe('bar', function() {
browser.get(url_2);
it("should do something with elem1 on page2", function() {
var elem1 = element(by.css("..."));
...
});
});
});
As long as I not try to navigate to url_2, the tests from page1 are working. But in the above example the browser navigates to page1 and immediately navigates to page2. And I get a "Failed: No element found using locator" error for page1. I thought commands like browser.get and browser.setLocation should also become part of the controlFlow ?
How can I solve this problem?
You need to wrap the browser.get(url_2);
statement inside beforeAll()
method like below.
describe('something', function() {
describe('foo', function() {
beforeAll(function(){
browser.get(url_1);
})
it("should do something with elem1 on page1", function() {
var elem1 = element(by.css("..."));
...
});
});
describe('bar', function() {
beforeAll(function(){
browser.get(url_2);
})
it("should do something with elem1 on page2", function() {
var elem1 = element(by.css("..."));
...
});
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.