In e2e testing, blank page is opened in Chromium Edge (New Edge Browser) using Protractor - jasmine

1.Open the MS Chromium edge and type the command "edge://settings/help" to check the version
2. Download the MS Chromium edge webdriver and placed it into project directory
3. Set the desired capabilities in conf.js file
4. Start the server using command "webdriver-manager start --edge msedgedriver.exe"
5. Run the test using the "protractor conf.js"
Environment:
Chromium Edge Version = 83.0.478.37
Chromium web driver = 83.0.478.37
Selenium server version = 3.141.59
JDK =1.8.191
conf.js
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome',
'goog:chromeOptions': {
// Faked out chrome binary
'binary':'C:\\Program Files (x86)\\Microsoft\\Edge Beta\\Application\\msedge.exe'
}
},
//Path of Chromium edge driver
chromeDriver:'./msedgedriver.exe',
specs: ['spec.js'],
}
};
Also tried with using desired capabilities in spec.js file as well but still blank page is opened
describe('slow calculator', function() {
beforeEach(function() {
let options = new edge.Options();
options.setEdgeChromium(true);
//options.setBinaryPath("C:\\Program Files (x86)\\Microsoft\\Edge Beta\\Application\\msedge.exe");
let browser = edge.Driver.createSession(options);
browser.get('http://juliemr.github.io/protractor-demo/');
});
});

While starting webdriver-manager, ensure the path to msedgedriver is specified.
webdriver-manager start --edge "pathToEdgeDriver/msedgedriver.exe"
The capabilities object should have MicrosoftEdge as browserName.
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'MicrosoftEdge'
}

Related

How do I use protractor with firefox and local self-signed https?

I'm using protractor to test an application and webdriver-manager doesn't seem to want to install an appropriate Chrome driver, so I'm trying Firefox instead. However, the test gets stuck at the security warning page of my self-signed https:// test server. How do I configure protractor / selenium webdriver to skip the warning page?
Use this block in your protractor.conf.js to load Firefox, and ignore the certificate error presented by the test server's self-signed certificate. Note that if you're editing a Chrome config it's not enough to change browserName, you must remove any chromeOptions: { to avoid confusing the test runner.
capabilities: {
browserName: 'firefox',
'moz:firefoxOptions': {
// command line options could go here
},
'acceptInsecureCerts': true
},
In order to run protractor tests on multiple browsers, Protractor
offers a multiCapabilities configuration option. These options should
be defined as an array of objects.
1. Capabilities to be passed to the web driver instance.
capabilities: {
'browserName': 'firefox',
},
2. How to execute protractor tests on multiple browsers in parallel using multiCapabilities.
multiCapabilities: [
{'browserName': 'chrome'},
{'browserName': 'firefox'},
],
3. How we can do it using multiCapabilities.
multiCapabilities: [
{
'browserName': 'chrome',
'chromeOptions': {
'args': ['disable-infobars']
}
},
{
'browserName': 'firefox',
'moz:firefoxOptions': {
'args': ['--safe-mode']
}
}
],

how can i run all webdriver.io spec files in single browser session?

I'm using wdio to run tests. I reduced maxInstances to 1.But wdio logging indicates that it creates a new session before each spec file. How can i run all webdriver.io spec files in single browser session?Thank you in advance.
wdio.conf.js is:
exports.config = {
specs: ['./test/specs/**/*.js'],
maxInstances: 1,
capabilities: [{
maxInstances: 1,
browserName: 'chrome',
}],
sync: true,
logLevel: 'verbose',
coloredLogs: true,
screenshotPath: './errorShots/',
baseUrl: process.env.ROOT_URL,
waitforTimeout: 10000,
connectionRetryTimeout: 90000,
connectionRetryCount: 3,
services: ['chromedriver'],
framework: 'mocha',
reporters: ['dot', 'spec', 'allure'],
mochaOpts: {
ui: 'bdd',
timeout: 99999999
},
}
Try this workaround. It actually works for me with webdriverio v4
List all of your specs in a single file. You can take advantage of autocomplete feature of the IDE you are using, e.g.
specs.js
require('./test/specs/test1');
require('./test/specs/test2');
// etc.
require('./test/specs/testN');
In your wdio.conf.js file, list the above spec.js file as the only spec, i.e.
wdio.conf.js
exports.config = {
specs: ['./test/specs/specs.js'],
// etc.
}
WebdriverIO will run each test file in a different session. To run them all in the same session, you'd need to put all your tests in the same file.
If you're finding yourself needing to run all your tests in the same session, perhaps you should re-work your tests... Maybe use WebdriverIO's "before" hook if you need to do a common set up, like logging in to a site.

Protractor file download test fails when headless chrome

I am having an issue with a protractor test. It was working, but now (even thought nothing has changed) it is not.
The test is just opening the app (web application) and clicking on a button to download an image. The download should start straight away.
The problem is that the next instruction after the download event throws an exception, Failed: chrome not reachable. I am using the latest chrome and chrome driver versions.
The capabilites section for protractor is like this:
capabilities: {
browserName: 'chrome',
loggingPrefs: { browser: 'ALL' },
chromeOptions: {
args: ['--headless', '--window-size=1240,780'],
},
}
I am reading about using DevTools to enable downloads in headless mode (Page.setDownloadBehavior), but so far no luck.
Does anybody have this issue too? Any clue how to fix it?
Thanks.
There could be another easy way to do it, but this is what I have done in my test suite.
I used got library, however, you can use any library to send an HTTP post request.
Discussion about setting download directory in headless chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=696481
let got = require('got');
let session = await browser.getSession();
let sessionId = session['id_'];
let params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': downloadDir }}
await got.post('http://localhost:4444/wd/hub/session/'+ sessionId + '/chromium/send_command', {body: JSON.stringify(params)})
If you have not disabled ControlFlow in your protractor config, change ASync/Await to .then.
An easier solution is to add these lines to your protractor.conf.js:
exports.config = {
...
onPrepare() {
...
browser.driver.sendChromiumCommand('Page.setDownloadBehavior', {
behavior: 'allow',
downloadPath: downloadsPath
});
}
};
From: https://bugs.chromium.org/p/chromium/issues/detail?id=696481#c196
Appendix
If you are to lazy to find a Download Path just paste this at the top of your protractor.conf.js:
var path = require('path');
var downloadsPath = path.resolve(__dirname, './downloads');
It will download the file to the e2e/downloads folder. Just use the same code in your tests to find out if the file downloaded.
This works for me:
chromeOptions: {
'args': [
'--headless',
'--disable-gpu',
'--test-type=browser',
'--disable-extensions',
'--no-sandbox',
'--disable-infobars',
'--window-size=1920,1080',
//'--start-maximized'
"--disable-gpu",
],
prefs: {
'download.default_directory': 'C:\\downloads',
'download.prompt_for_download':false,
'download.directory_upgrade':true,
"safebrowsing.enabled":false,
"safebrowsing.disable_download_protection":true
},
},

No provider for Jasmine-jquery?

I'm using Yeoman+Angular Generator for my application and I have been running around hard to get along with Jasmine! This is where I am stuck. I want to be able to use jQuery selectors with Jasmine tests. I have installed the karma-jasmine and karma-jasmine-jquery packages. Then I installed it for bower (I'm new and I have no idea what should be installed for what!). I have manually added the path in my karma.conf.js, but I still get the message that says this:
Running "karma:unit" (karma) task
Warning: No provider for "framework:jasmine-jquery"! (Resolving: framework:jasmine-jquery) Use --force to continue.
This is how my karma config looks like:
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2014-09-12 using
// generator-karma 0.8.3
module.exports = function(config) {
'use strict';
config.set({
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// base path, that will be used to resolve files and exclude
basePath: '../',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine-jquery', 'jasmine'],
// list of files / patterns to load in the browser
files: [
'bower_components/jasmine-jquery/lib/jasmine-jquery.js',
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-touch/angular-touch.js',
'bower_components/angular-bootstrap/ui-bootstrap.js',
'app/scripts/**/*.js',
//'test/mock/**/*.js',
'test/spec/**/*.js',
'app/views/*.html'
],
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
'PhantomJS'
],
// Which plugins to enable
plugins: [
'karma-phantomjs-launcher',
'karma-jasmine',
'karma-ng-html2js-preprocessor'
],
preprocessors: {
'app/views/*.html': 'ng-html2js'
},
ngHtml2JsPreprocessor: {
stripPrefix: 'app/',
moduleName: 'views'
},
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
colors: true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
// '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
});
};
I had the same problem as this. Fixed it by adding karma-jasmine-jquery to the plugins array in karma.conf.js. This is my karma.conf in full.
module.exports = function(config) {
'use strict';
config.set({
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// base path, that will be used to resolve files and exclude
basePath: '../',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine-jquery', 'jasmine'],
// list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'app/scripts/**/*.js',
'test/mock/**/*.js',
'test/spec/**/*.js'
],
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
'PhantomJS'
],
// Which plugins to enable
plugins: [
'karma-phantomjs-launcher',
'karma-jasmine-jquery',
'karma-jasmine',
],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
colors: true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
// '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
});
};
The other change I made is that as per the jasmine-jquery docs it requires jasmine version of at least 0.2.0. The generator gives version of 0.1.5 (at least it did for me yesterday). So to fix this I ran 'npm install karma-jasmine#0.2.0 --save-dev'. The save dev should do this but make sure you have the correct packages listed in the devDependencies in the root package.json for me I have:
"karma-jasmine": "^0.2.0",
"karma-jasmine-jquery": "^0.1.1",
Obviously these should correspond with the actual packages in node-modules
Hope it helps
C

Can not load "teamcity", it is not registered! Perhaps you are missing some plugin?

I'm trying to run my karma (version v0.10.2) unit tests on teamcity (version 7.1).
When I run karma start --reporters teamcity --single-run I get the following error:
Can not load "teamcity", it is not registered! Perhaps you are missing some plugin?
I have installed the karma-teamcity-reporter module, but that hasn't helped.
The following are installed in my local node_modules folder:
karma
karma-chrome-launcher
karma-coffee-preprocessor
karma-coverage
karma-firefox-launcher
karma-html2js-preprocessor
karma-jasmine
karma-phantomjs-launcher
karma-requirejs
karma-script-launcher
karma-teamcity-reporter
Here is my karma.conf.js:
I'm running karma version v0.10.2. Here's my karma.conf.js:
module.exports = function(karma) {
karma.set({
// base path, that will be used to resolve files and exclude
basePath: '../../myapplication.web',
frameworks: ['jasmine'],
plugins: [
'karma-jasmine',
'karma-coverage',
'karma-chrome-launcher',
'karma-phantomjs-launcher'
],
// list of files / patterns to load in the browser
files: [
'Scripts/jquery/jquery-2.0.2.min.js',
'Scripts/jquery-ui/jquery-ui-1.10.3.min.js',
'Scripts/daterangepicker/daterangepicker.js',
'Scripts/angular/angular.js',
'Scripts/angular/restangular/underscore-min.js',
'Scripts/angular/restangular/restangular-min.js',
'Scripts/angular/angular-*.js',
'Scripts/angular/angular-test/angular-*.js',
'Scripts/angular/angular-ui/*.js',
'Scripts/angular/angular-strap/*.js',
'Scripts/angular/angular-http-auth/*.js',
'Scripts/sinon/*.js',
'Scripts/moment/moment.min.js',
'uifw/scripts/ui-framework-angular.js',
'app/app.js',
'app/**/*.js',
'Tests/unit/**/*.js'
],
// list of files to exclude
exclude: [
'Scripts/angular/angular-test/angular-scenario.js'
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters: ['progress', 'coverage', 'teamcity'],
preprocessors : {
'app/**/*.js': ['coverage']
},
coverageReporter : {
type: 'html',
dir: 'Tests/coverage/'
},
// web server port
port : 9876,
// cli runner port
runnerPort : 9100,
// enable / disable colors in the output (reporters and logs)
colors : true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel : karma.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch : true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout : 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun : true
});
};
If I run karma start karma.conf.js it runs correctly. What am I doing wrong?
Turned out I needed to add karma-teamcity-reporter to the plugins section to get this to work:
...
plugins: [
'karma-teamcity-reporter',
'karma-jasmine',
'karma-coverage',
'karma-chrome-launcher',
'karma-phantomjs-launcher'
],
...

Resources