I'm using protractor with phantomjs and jasmine to test a very simple application, that does little more than a login/logout. Page response measured by node time are about 1-2 ms, but 9 tests with 11 assertion are taking 35 sec to complete.
I'm simply checking the login / logout are working sending some good/bad user credential, so I wonder if those test-timings are normal using protractor.
For comparison, always with phantomjs, client-unit test, with 232 tests and 1735 assertions are taking about 3.2 sec, while server-unit tests with 183 tests are taking 0.42 sec, and those are doing a lot of db query, transactions and so on. 23 Midway tests are taking 2.11 sec. All done with jasmine, karma, phantomjs.
So I don't understand where is the problem with protractor. Any suggestion?
Thanks
The slowness may be in your webpage - protractor waits for your page to stabilize before performing any action, so if it's slow loading any part of the page that will slow down your final tests.
Thanks julie,
it is a page with a pair of textbox, user and password necessary for login. I've measured response time from server and they are about 2-3 ms for page. There is no image or strange things... is there any way to understand where it is blocking?
We'd like to surface more information about timing - see #674. In the meantime - you might want to take a look at the ghostdriver logs to see if it's happening on the ghostdriver -> phantomJS side.
My protractor.conf.js contains:
capabilities: {
browserName: 'phantomjs', //chrome firefox phantomjs
'phantomjs.binary.path': './node_modules/phantomjs/bin/phantomjs.exe',
'phantomjs.cli.args': ['--debug=true', '--webdriver-logfile=webdriver.log', '--webdriver-loglevel=DEBUG']
// (loglevels supported: 'ERROR', 'WARN', 'INFO', 'DEBUG') (default 'INFO')
}
so I suppose I should have a webdriver.log file somewhere. I've searched for it in the entire disk without success. Or may be that parameter is not being considered. I'll continue investigating..
I have run into this issue, where retrieving data from a page is very slow, and I have come up with a much faster way -- see http://docs.espressologic.com/blog/letsspeedupprotractorsdatalookup
For whatever reason, WebDriver can sometimes be very slow when pulling some data from the DOM, so we go directly to the browser. It's a little bit hackish, but the performance difference is dramatic -- something that used to take 7 seconds now runs in 90ms.
In my case I've a simple login form with two textbox. I'll try getting value with a so injected script and I'll see what happens. But sincerely it seems to me too much work and little readability
I still don't get where it is blocking. I make a little example with some timings
var baseUrl = 'http://localhost:8888/',
nTest=1;
beforeEach(function (done) {
console.time('start'+ nTest);
browserGet(baseUrl);
done();
});
afterEach(function(done){
console.timeEnd('start'+ nTest);
nTest+=1;
done();
});
function elementById(id) {
console.time('start elementById ' + id);
var el = ptor.findElement(protractor.By.id(id));
console.timeEnd('start elementById ' + id);
return el;
}
function browserGet(url){
console.time('start browserGet' + url);
browser.get(url);
console.timeEnd('start browserGet' + url);
}
function getCurrentUrl() {
console.time('start getCurrentUrl' + nTest);
var u = ptor.getCurrentUrl();
console.timeEnd('start getCurrentUrl' + nTest);
return u;
}
it('/ should redirect to login page', function (done) {
browserGet(baseUrl);
expect(getCurrentUrl()).toBe(baseUrl + 'login');
expect(elementById('maincontainer').getText()).toContain('Please login');
done();
});
timings:
beforeEach browserGet(baseUrl): 6ms
it browserGet(baseUrl): 5ms
it getCurrentUrl() 2ms
it elementById() 3ms
time between beforeEach and afterEach: 10153ms
I wonder what was he doing in all that time.
Protractor uses promises - so all that the line getCurrentUrl() does is register a promise. The tests themselves actually wait until stuff completes - that's why they're much longer.
There isn't anything actionable from the issue that's not already captured in #674, so I'm going to go ahead and close. Hope some things were cleared up!
I did not get the reason why test last much longer in this case. Is there any explanation?
+1
@maxtardiveau I have a for loop that does 25 clicks to increment a counter. Just tried your solution on one of my tests and it went from 10 seconds to 2 seconds.
I know I'm probably creating a lot of promises in Protractor with the clicks but that's quite a performance difference!