Closed iwiszhou closed 8 years ago
Looks like that was an error in the documentation. I fixed it now. You cannot call cdf obkect. Since this is a script that you write, you could refer to it in your script, without really needing a cfg
object.
for the new documentation, "browser.get('www.example.com')". However, how can I reference back the website I defined in browserPerf function. I think we should browser.get( the site we passed in browserPerf function) ?
browserPerf('http://mysite.com', function(err, res) { // res - array of objects. Metrics for this URL if (err) { console.log('ERROR: ' + err); } else { console.log(res); } }, options);
Can those not be saved in a variable and passed in at the two places ?
Hum...that may be not the case I want to test.
Let's say I have 2 page. Page 1 just introduction about my site. Page 2 is a login page with "Login" button. In page 1, there is a button "GO TO PAGE 2" will navigate user to Page 2, and login into the system.
Okay, now I want to test the button click "GO TO PAGE 2", then click "Login" button on Page 2.
If I called browser.get("http://mysite.com"), it seems it will navigate to http://mysite.com again, and execute all those button click actions. and when that one is done. It will go back to http://mysite.com again.
Problem is here. It should not navigate back to http://mysite.com when preScript is finished. It may caused by we called browser.get("http://mysite.com") which is not same instance when browserPerf( "browserPerf", ....).
In this specific case, you can pass null as the URL to browserPerf(null, {})
. This way, the only navigation will be on the preScript. Once the preScript is finished, there is no navigation.
I just tried. I got the following error..
ERROR PRINT OUT IN CONSOLE: ERROR: Error: [get("perf")] Error response status: 13, UnknownError - An unknown server-side error occurred while processing the command. Selenium error: unknown error: unhandled inspector error: {"code":-32603,"message":"Cannot navigate to invalid URL"} (Session info: chrome=50.0.2661.94) (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.11.4 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 1.65 seconds Build info: version: '2.40.0', revision: 'fbe29a9', time: '2014-02-19 20:54:28' System info: host: 'D2015100901', ip: '10.103.29.57', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.4', java.version: '1.8.0_91' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=/var/folders/94/1qt0mbvj0fldyd9xr60qmv2x4h6z82/T/.org.chromium.Chromium.NwUkzR}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=50.0.2661.94, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: debe4bdb0a1f1a5d72b7540a132981b0
CODE:
var browserPerf = require('browser-perf'); var testWebSitUrl = 'http://www.mysite.com'; var options = { selenium: 'http://localhost:4444/wd/hub', browsers: ['chrome'], preScript: function(browser) { return browser.get(testWebSitUrl).then(function() { console.log('Find sign in in discover'); return browser.elementByCssSelector('.signin-btn') }).then(function(el) { console.log('Clicking sign in'); return el.click(); }); } } browserPerf('perf', function(err, res) { // res - array of objects. Metrics for this URL if (err) { console.log('ERROR: ' + err); } else { console.log("result ----> "); console.log(res); } }, options);
The URL passed should be null. This code works
var browserPerf = require('browser-perf');
var testWebSitUrl = 'http://www.google.com';
var options = {
selenium: 'http://localhost:9515',
browsers: ['chrome'],
preScript: function (browser) {
return browser.get(testWebSitUrl).then(function () {
console.log('Find sign in in discover');
return browser.elementByCssSelector('.signin-btn')
}).then(function (el) {
console.log('Clicking sign in');
return el.click();
});
}
}
browserPerf(null, function (err, res) {
// res - array of objects. Metrics for this URL
if (err) {
console.log('ERROR: ' + err);
} else {
console.log("result ----> ");
console.log(res);
}
}, options);
Do you mind to add an "browserPerf.actions.login" example for perScript?
I tried using it inside the perScript without any luck....
I tried something like, no sure it is the correct approach.... preScript: function(browser) { return browser.get(testWebSitUrl).then(function() { console.log('Find sign in in mysite'); return browser.elementByCssSelector('.signin-btn') }) .then(function(el) { console.log('Clicking sign in'); return el.click(); }) .then(function(){ browserPerf.actions.login({ username: { field: 'form>ul>li:first-child>input', value: 'username' }, password: { field: 'form>ul>li:2th-child>input', value: 'password' }, submit:{ field: 'form>ul>li:3th-child>input' } }) })
Hi,
How can I access to 'cfg' object inside the preScript function ? (https://github.com/axemclion/browser-perf/wiki/Node-Module---API#prescript )
\ Example ** Here is the simple options object I created.
var options = { selenium: 'http://localhost:4444/wd/hub', browsers: ['chrome'], preScript: function(browser) { return browser.get(cfg.page).then(function() { console.log('Find sign in in discover'); return browser.elementByCssSelector('.signin-btn') }).then(function(el) { console.log('Clicking sign in'); return el.click(); }); } }