protractor in connection with selenium keeps connecting to localhost - javascript

I have a setup of my angular-app and a separate selenium server as docker-compose setup
my protractor setting looks like this
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: false,
baseUrl: 'http://user-frontend:4200/',
seleniumAddress: 'http://selenium:4444/wd/hub',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
now I run the command to run the end2end tests using protractor:
ng e2e --no-serve
All my tests are failing, and when I debug the selenium server and take screenshots, I see it is trying to connect to itself (localhost) instead of back to the application host baseUrl: 'http://user-frontend:4200/',
any Idea what I am doing wrong here?

Are you sure that browser.baseUrl (or browser.get()) is not set elsewhere?

Related

Webdriverio debug BDD tests using WebStorm

Is there any way to debug Webdriverio tests using nodeJS and WebStorm?
I've found some conclusion here and this is actually my problem: Run WebdriverIO tests via Mocha in WebStorm
But this solution doesn't fit to my problem now;
I've set up Babel to compile my BDD tests
I've set tests.config.js
module.exports = { maxInstances: 1,
capabilities: [{ browserName: 'chrome' }],
execArgv: ['--inspect'] : [],
specs: ['**/some/spec.js']
mochaOpts: {
ui: 'bdd',
compilers: ['js:#babel/register'],
timeout: 150000
} }
and babel.conf.js
module.exports = {
presets: [
['#babel/preset-env', {
targets: {
node: 12
}
}]
]
}
then I've created nodeJS configuration like it said here at answer: Run WebdriverIO tests via Mocha in WebStorm
Set breakpoint at test
describe("test", function(){
it ("this is a BDD test",
function(){
breakpoint here>> do_some_action();
})
})
But when I try to launch my tests in debug mode nothing happens and I see "connnected to localhost:port" message. and I can't go to breakpoint; there are no errors;
there was problem with a wdio.conf.js file. If you don't set specs file >> there aren't no errors. But launching is incorrect. I've set config like this:
module.exports =
{
capabilities: [{
maxInstances: 6,
browserName: 'chrome',
baseUrl: "some-url/",
browserVersion: '67.0'}]
specs: [
'./this/is/spec.js']
mochaOpts: {
ui: 'bdd',
require: ['#babel/register'],
timeout: 150000
},
And debug works after this. It's not too har as I though :) If there are some questions - > I'm glad o answer

How to run multiCapabilities reading configuration parameters from the configuration file

I have one file of config which runs tests in one browser using capabilities.
Now I have created one more separate config file which contains multiCapabilites and will run same tests in multiple browsers.
I want to optimize configs so I second config file I write multiCapabilities for first config and used
delete firstConfig['capabilities'];
to ignore the capabilities from first config and use all other params from firstConfig and use multiCapabilities from 2nd config and run.
Expected result:
params in configs should not be duplicated in both configs, only multiCapabilities is the change, rest of config is same.
Use a base configuration file
Having a base configuration file and another file that extends from it might be a better approach. For this example, we will look at my base configuration file:
var env = require('./environment');
// This is the configuration for a smoke test for an Angular TypeScript application.
exports.config = {
seleniumAddress: env.seleniumAddress,
framework: 'jasmine',
specs: [
'ng2/async_spec.js'
],
capabilities: env.capabilities,
baseUrl: env.baseUrl,
allScriptsTimeout: 120000,
getPageTimeout: 120000,
jasmineNodeOpts: {
defaultTimeoutInterval: 120000
}
};
Create a second config from the base config
From there, we did something similar to your question where we removed the capabilities and added multicapabilities. (https://github.com/angular/protractor/blob/master/spec/ciNg2Conf.js). In addition, since we were running on Sauce Labs, we also decided to increase our timeouts.
exports.config = require('./angular2Conf.js').config;
exports.config.sauceUser = process.env.SAUCE_USERNAME;
exports.config.sauceKey = process.env.SAUCE_ACCESS_KEY;
exports.config.seleniumAddress = undefined;
// TODO: add in firefox when issue #2784 is fixed
exports.config.multiCapabilities = [{
'browserName': 'chrome',
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
'build': process.env.TRAVIS_BUILD_NUMBER,
'name': 'Protractor suite tests',
'version': '54',
'selenium-version': '2.53.1',
'chromedriver-version': '2.26',
'platform': 'OS X 10.11'
}];
exports.config.capabilities = undefined;
exports.config.allScriptsTimeout = 120000;
exports.config.getPageTimeout = 120000;
exports.config.jasmineNodeOpts.defaultTimeoutInterval = 120000;
I hope that helps.
Update:
Per comments below, setting the config.capabilities to undefined did not work; however, setting config.capabilities to false did work.
Prepare a capabilities provider to define vary capabilities, and exports a function to return a capabilities array according to the cmd line params.
// capabilities.provider.js
var capabilities = {
chrome: {
browserName: 'chrome'
},
chrome-headless {
browserName: 'chrome',
},
firefox: {
browsername: 'firefox'
},
...
};
exports.evaluate=function(){
var caps = 'chrome';
process.argv.slice(3).forEach(function(kvp){
if(kvp.includes('--caps=')) {
caps = kvp.split('=')[1] || caps;
}
})
var _caps = [];
caps.split(',').forEach(function(cap){
if(Object.keys(capabilities).includes(cap)) {
_caps.push(capabilities[cap])
}
})
return _caps;
};
protractor config.js
var capsProvider = require('./capabilities.provider');
exports.config = {
seleniumAddress: '',
framework: 'jasmine',
specs: [
'ng2/async_spec.js'
],
params: {
},
multiCapabilities: capsProvider.evaluate(),
baseUrl: env.baseUrl,
allScriptsTimeout: 120000,
getPageTimeout: 120000,
jasmineNodeOpts: {
defaultTimeoutInterval: 120000
}
};
Specify caps from cmd line:
protractor config.js --caps=chrome,firefox,ie,safari

How to run protractor suites with multiple users

Below is my config file that I use to run a single user and multiple test suite.Now, am having a issue where I want to run few protractor suites with User A and few protractor test suite with User B. I don't know how to achieve this in protractor.
exports.config = {
capabilities: {
browserName: 'chrome'
},
suites: {
loginAndNavigate: 'e2e/specFiles/LoginAndNavigateSpec.js',
homepage: 'e2e/specFiles/policiesList_HomepageSpec.js',
versionPage: 'e2e/specFiles/ER_VersionsPageSpec.js'
policyDetails: 'e2e/specFiles/policyDetailsPageSpec.js'
},
seleniumServerJar: '../node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-2.53.1.jar',
chromeDriver: '../node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.26',
baseUrl: 'https://shared.qa.com/EdgeAuth/logindirect.jsp',
params: {
login: {
user: ‘user ',
password: 'abc123'
}
},
onPrepare: function() {
global.EC = protractor.ExpectedConditions;
browser.getCapabilities().then(function(c) {
console.log(c.get('browserName'));
});
global.Utils = require('./e2e/utils.js');
require('./e2e/matchers.js');
require('./e2e/customLocators.js');
},
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 100000
}
};
You can provide new param (user details) and suite details when you run the test.
For the params object use --params.login.user "User B" etc etc to overwrite config file details.
For the suites you can use --suite=loginAndNavigate or if more than one then --suite=loginAndNavigate,homepage to choose what to run.
You will need the proper combination of these two to suit your needs.
https://github.com/angular/protractor/blob/master/lib/config.ts

Protractor Angular 2 Failed: unknown error: angular is not defined

I'm getting the following error:
Failed: unknown error: angular is not defined
This only happens when using angular specific selectors like "by.model". But selectors such as "by.css" work correctly . This is an Angular 2 app...
Test
it('should set focus', () => {
//This works
//var input = element(by.css('myclass'));
//This fails
var input = element(by.model('config.value'));
input.clear();
input.sendKeys('test');
input.sendKeys(Key.TAB);
input.click();
var highlightedText = browser.executeScript(function getSelectionText()
{
return window.getSelection().toString();
});
expect(highlightedText).toEqual('test');
});
exports.config = {
baseUrl: 'http://localhost:5555',
specs: [
'dist/dev/**/*.e2e.js'
],
exclude: [],
framework: 'jasmine2',
allScriptsTimeout: 110000,
jasmineNodeOpts: {
showTiming: true,
showColors: true,
isVerbose: false,
includeStackTrace: false,
defaultTimeoutInterval: 400000
},
directConnect: true,
capabilities: {
'browserName': 'chrome'
},
onPrepare: function() {
var SpecReporter = require('jasmine-spec-reporter');
jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: true}));
browser.ignoreSynchronization = false;
},
useAllAngular2AppRoots: true
};
chrome=49.0.2623.87
chromedriver=2.9.248315
platform=Windows NT 6.1 SP1 x86_64
node=5.9.1
I found the answer on the angular.io site under developer docs.
Upgrading from 1.x
Right now angular selectors by.model and by.binding are not supported. Its not clear if these are features that are possible or that they are working on for angular 2.

Intern with Phantomjs GhostDriver

I'm trying to setup Intern to run with PhantomJS on a Windows 7 machine
Since now my setup is as follows:
demo test root/unit/tests/phantom.js:
define([
'intern!object',
'intern/chai!assert'
], function(registerSuite, assert) {
registerSuite({
name: 'PhantomTest',
'dummy': function () {
assert(true, "Works!");
}
});
});
Configuration file root/unit/intern.config.js:
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
capabilities: {
'selenium-version': '2.30.0'
},
environments: [
{
browserName: 'phantom'
}
],
maxConcurrency: 3,
useSauceConnect: false,
webdriver: {
host: 'localhost',
port: 4444
},
// used here
loader: {
},
suites: [ 'unit/tests/phantom.js' ],
functionalSuites: [ /* 'myPackage/tests/functional' */ ],
excludeInstrumentation: /^tests\//
});
By running this test and config in a browser it just works.
To run Intern with PhantomJS i execute:
phantomjs --webdriver=4444
And:
cd root
node node_modules\intern\runner.js config=unit/intern.config
The console running Phantomjs then returns:
[INFO - 2013-07-01T21:29:07.253Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 42ba5b50-e295-11e2-86f7-e331eb8b922d
While the other one outputs the following message without any further log:
Defaulting to "runner" reporter
Listening on 0.0.0.0:9000
Initialised phantomjs 1.9.1 on windows-7-32bit
Any hint on what i'm missing?
The reason for this is https://github.com/ariya/phantomjs/issues/10522; phantomjs is using an extremely old version of JavaScriptCore that has no Function.prototype.bind. Your best bet at this moment is to switch to using the geezer version of Intern, which should work properly in this older environment.

Categories

Resources