First of all I'm a noob with e2e testing. What I've done is
installed protractor nmp install protractor
installed webdriver-manager
run webdriver-manager start from the directory where my angularjs app sits. it runs fine
run protractor tests/e2e/conf.js it also runs fine
However in few seconds it says Timed out waiting for page to load
Here are my files:
tests/e2e/conf.js:
// An example configuration file.
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['example_spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
tests/e2e/example_spec.js
var protr;
describe('addressBook homepage', function() {
var ptor;
beforeEach(function() {
ptor = protractor.getInstance();
});
it('should greet the named user', function() {
browser.get('/'); // <-- exception here
element(by.model('yourName')).sendKeys('Julie');
var greeting = element(by.binding('yourName'));
expect(greeting.getText()).toEqual('Hello Julie!');
});
});
I just can't understand where to define my webapp laypout/placement so protractor/webdriver knows which context to run.
With that setup protractor will be trying to navigate to "/". You need to either set the baseUrl property in the configuration file, or put an absolute url in the browser.get(). If all your tests are going to be on the same domain I'd recommend the first option.
Related
Hi all so I am trying to run headless chromium with protractor and jasmine. I have everything setup and working for both firefox and chrome with a head. When I run firefox headless it works... when I try running chromium headless it ends up timing out. Looking for some help to solve this problem.
The error I get is :
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Now I've read a million article online and have tried increasing the timeout time and adding done into the function as well...
Here is my current code:
Conf.js - this has a bunch of added args and settings that I've found online. I've tried pretty much every variation and had no success..
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
allScriptsTimeout: 5000000,
capabilities: {
'directConnect': true,
'browserName': 'chrome',
"goog:chromeOptions": {
args: ["--headless", "--remote-debugging-port=9222", "--verbose", "--disable-gpu", "--disable-web-security", "--window-size=800x600"],
'binary': "/usr/bin/chromium-browser"
}
}
};
Spec.js - straight off of their website with console.logs. All of the console.logs print out in the following order 3,1,2. This is something I'm unsure is correct? Should the describe be waiting for the it to finish? It almost feels like my it is never returning...
describe('angularjs homepage todo list', function() {
it('should add a todo', function(done) {
console.log("WOOO1");
browser.get('https://angularjs.org');
element(by.model('todoList.todoText')).sendKeys('write first protractor test');
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write first protractor test');
// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click();
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);
console.log("WOO2");
}, 15000);
console.log("WOO3");
});
Following this some other discoveries I have found... when I go to the localhost:9222 I see
Inspectable WebContents
data:text/html,<html></html>
The data:text/html,<html></html> is a link and if clicked on takes me to the remote chrome debugger that is loading ... data:text/html,. This is where I think the problem is. Why is this never actually loading the angular site?
Maybe I'm off base but does anyone know how to make sense of this?
EDIT:
Additional useful information.
I am using
chromium 79.0.3945.130
chromedriver 79.0.3945.36
jasmine v3.5.0
jasmine-core v3.5.0
Protractor 5.4.3
Thanks
Config that ended up working for me
exports.config = {
framework: 'jasmine',
allScriptsTimeout: 9000,
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
capabilities: {
'directConnect': true,
'browserName': 'chrome',
"goog:chromeOptions": {
args: ["--headless", "--remote-debugging-port=9222", "--verbose", "--disable-gpu", "--disable-web-security", "--window-size=800x600"],
'binary': "path to chrome"
}
}
};
add allScriptTimeOut in your configuration like this:
exports.config = {
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
specs: ['example_spec.js'],
allScriptsTimeout: 9000
};
hope this link will help you
https://www.protractortest.org/#/timeouts.
I have a Windows box and an Ubuntu box which I run my automated tests on. Currently, in my protractor.config.js file I have two seleniumAddress fields under my multiCapabilities: [{}] section and just comment out one or the other depending on which environment I would like to run in.
Is there a way to parameterize the seleniumAddress: so I can tell from my command line which environment to run in?
Something like this: gulp e2e --suite <suiteName> --baseUrl <URL>
--environment Windows
Here is my current multiCapabilities section from my protractor conf file:
multiCapabilities: [{
browserName: 'chrome',
// seleniumAddress: "URL to webdriver-manager Windows Box",
seleniumAddress: "URL to webdriver-manager Ubuntu Box",
platform: 'ANY',
version: 'ANY',
chromeOptions: {
args: ['--no-sandbox', '--test-type=browser', '--lang=en', '--window-size=1680,1050'],
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
},
download: {
prompt_for_download: false,
directory_upgrade: true,
default_directory: 'C:\\downloads\\'
},
},
}
// shardTestFiles: true,
// maxInstances: 2
}],
Protractor is run on Node.js, so you should be able to pass an argument (a little more complicated), or easier, set an environmental variable:
Protractor conf snippet from the Protractor website with environmental variable logic added:
// Use the Windows selenium if the environmental variable IS_WINDOWS is set.
const seleniumServer = process.env.IS_WINDOWS ?
'https://path/to/windows-silenium' : 'https://path-to-default-selenium';
exports.config = {
// The address of a running selenium server.
seleniumAddress: seleniumServer,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to the configuration file location passed
// to protractor (in this example conf.js).
// They may include glob patterns.
specs: ['example-spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
}
};
I'm not quite sure what you would want to choose from (and I don't use gulp), but for the snippet above, you would probably use:
IS_WINDOWS=true gulp e2e --suite <suiteName> --baseUrl <URL>
I am trying to write a code for tasting that I'm redirected to the index.html file using protractor .When I type in terminal protractor protractor.conf.js to execute the e2e tests. it shows me this error :
W/protractor - browser.getLocationAbsUrl() is deprecated, please use browser.getCurrentUrl instead.
Why is that happening?Isn't getLocationAbsUrl Protractor's words?
the code for Configuring Protractor
exports.config = {
allScriptsTimeout: 11000,
specs: [
'e2e/*.js'
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:3000/',
framework: 'jasmine',
directConnect: true,
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
Code for e2e test
'use strict';
describe('conFusion App E2E Testing', function() {
it('should automatically redirect to / when location hash/fragment is empty', function() {
browser.get('index.html');
expect(browser.getLocationAbsUrl()).toMatch("/");
});
As your error said, this function is deprecated. It means the use of this code is now discouraged. You should use getCurrentUrl().
From Protractor's Github:
browser.getLocationAbsUrl() is now deprecated, you should use
browser.getCurrentUrl() instead.
I know that Karma has a built-in autoWatch option that will cause my tests to be rerun when a test file changes:
var server = new karmaServer({
autoWatch: true,
autoWatchBatchDelay: 250,
});
server.start();
Is there a way to trigger this rerun manually? I would like to have more control over when my tests are rerun.
If you need to run it manually with gulp, just make a task from it (I assume that you want to re-run server.start):
var server = new karmaServer({
autoWatch: true,
autoWatchBatchDelay: 250,
});
gulp.task('runTests', function() {
server.start();
});
And then whenever you need to run test, run in command line:
gulp runTests
I learned a bit more about Karma and discovered karma.runner.run(), which triggers an already-running server (for example, a Karma server you started in a different command window) to rerun its tests. In my gulp task I now do something like this:
gulp.task('run-tests', function() {
gulp.watch('/glob/to/my/files').on('change', function() {
karma.runner.run({ configFile: 'karma.conf.js' });
});
});
Note that if you run this task from the same process that spawned your Karma server, you will see duplicate test results since both the server and the runner report their results to the command line. To only show one set of test results, you can start your Karma server in a background process using something like this.
I'm trying to test protractor on a vanilla.js app and when I run protractor basicConf.js
I am getting below error :
This webpage is not available ERR_CONNECTION_REFUSED
This is my test:
describe('foo', function() {
beforeEach(function() {
browser.get('index.html');
});
it('should return the same result as browser.findElement', function() {
$('#newItem').sendKeys('sdg');
element('#addBtn').click().then(function(){
});
});
})
And my protractor config:
// The main suite of Protractor tests.
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine2',
// Spec patterns are relative to this directory.
specs: [
'spec.js'
],
// Exclude patterns are relative to this directory.
exclude: [
'basic/exclude*.js'
],
capabilities: {'browserName': 'chrome'},
baseUrl: 'http://localhost:' + ( '8082'),
jasmineNodeOpts: {
isVerbose: true,
realtimeFailure: true
},
params: {
login: {
user: 'Jane',
password: '1234'
}
}
};
Any ideas what I need to do to start fixing this?
I have run both:
protactor npm install -g protractor
webdriver webdriver-manager update
Error connection gets refused if either the webdriver server isn't started or there is a configuration compatibility issue with your protractor and browser. Looking at your config file and config data, there is no such issue. However, you should start your webdriver before running your tests. Open a command prompt in windows or terminal in mac and then run the following command to start the selenium webdriver -
webdriver-manager start
Later run your protractor scripts with the command that you already have. Hope this helps.
Looking over your test I believe the issue originates from the address that you are passing to the browser.get() function. You'll want to either reference the baseUrl you setup in the config file and append the "index.html" piece in your test or adjust the baseUrl and reference that in your beforeEach function. Try one of the following:
...
baseUrl: 'http://localhost:8082',
...
browser.get(browser.baseUrl + '/index.html');
or
...
baseUrl: 'http://localhost:8082/',
...
browser.get(browser.baseUrl);
or
browser.get('http://localhost:8082/index.html');
Also you could try this:
...
baseUrl: 'http://localhost:8082/index.html');
...
browser.get(browser.baseUrl);