File Download Using Protractor to Config ChromeOptions - automation

I have created an e2e test that will need to be downloaded outside of my local.
In config.js file
var path = require('path');
var downloadsPath = path.resolve(__dirname, './downloads');
capabilities: {
'browserName': process.env.BROWSER || 'chrome',
'chromeOptions': {
prefs: {
'download': {
'prompt_for_download': false,
'default_directory': 'downloadsPath',
},
},
},
},
In my e2e test file
it('view formulary download all mapped meds test', function() {
var mappedMedsFile = '/full_hospital_seeded_all_mapped_medications.csv';
adminPage.viewFormulary.click();
adminPage.downloadMappedMeds.click();
browser.wait(function() {
return fs.existsSync(mappedMedsFile);
}, 30000).then(function() {
md5File(mappedMedsFile, (err, hash) => {
if (err) throw err
})
expect(md5File.sync(mappedMedsFile)).toEqual(viewFormularyResults.expectMappedMedsHash)
});
});
I was expecting this file to download correctly, but instead, I get the following error:
- Failed: Wait timed out after 30001ms

Related

winston logger writing in both files

This is writing in both log file success and error.log if i called with log.fail I would expect it should write in error-date.log file. I don't know what's wrong here
const fs = require('fs');
var winston = require('winston');
const env = process.env.NODE_ENV;
const logDir = 'logs';
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir);
}
const now = new Date();
var logger = winston.createLogger({
transports: [
new (require('winston-daily-rotate-file'))({
filename: `${logDir}/success-%DATE%.log`,
timestamp: now,
datePattern: 'DD-MM-yyyy',
prepend: true,
json: false,
level: 'info',
}),
new (require('winston-daily-rotate-file'))({
filename: `${logDir}/error-%DATE%.log`,
timestamp: now,
datePattern: 'DD-MM-yyyy',
prepend: true,
json: false,
level: 'error',
}),
],
exitOnError: false,
});
const log = {
fail: function (ee) {
logger.error(`${now.toISOString()} - ${JSON.stringify(ee)}`);
},
success: function (ee) {
logger.info(`${now.toISOString()} - ${JSON.stringify(ee)}`);
},
};
module.exports = log;

self-signed certificate configuration in Selenium Standalone and webdriverio

How does one set in the configuration to accept insecure self-signed certificates.
I'm using Selenium Standalone and webdriverio.
https://github.com/vvo/selenium-standalone
https://github.com/webdriverio/webdriverio
I cannot read anywhere how to do this.
I'm suing the code below:
const assert = require('assert');
const { promisify } = require('util');
const exec = promisify(require('child_process').exec);
const selenium = require('selenium-standalone');
const webdriverio = require('webdriverio');
selenium.installAsync = promisify(selenium.install);
selenium.startAsync = promisify(selenium.start);
let browser;
let seleniumChild;
before(async function () {
this.timeout(10 * 1000);
try {
// Remove any previous hanging sessions
await exec('pkill -f selenium-standalone');
} catch (error) {
if (error.cmd !== 'pkill -f selenium-standalone') {
console.error(error);
process.exit(1);
}
}
await selenium.installAsync({});
seleniumChild = await selenium.startAsync({});
const options = {
desiredCapabilities: {
browserName: 'chrome',
},
port: 4444,
};
browser = webdriverio.remote(options);
await browser.init();
await browser.url('http://google.com');
const title = await browser.getTitle();
console.log('Title ->', title);
await browser.end();
});
describe('test', function () {
it('test', async function () {
assert.ok(true);
});
});
Since it's starting a Selenium server, I'm expecting to be able to specify this through capabilities:
Did you tried using:
"acceptSslCerts": "true"
More on this topic you can find on the Selenium github page.

WebdriverIO - Get browser logs

I want to get the browser logs (console.logs) from chrome with WebdriverIO's log functionality but all I get is, that the function log is not a function.
var WebdriverIO = require('webdriverio');
var chai = require('chai');
var _ = require('lodash');
var chaiAsPromised = require('chai-as-promised');
var expect = chai.expect;
chai.use(chaiAsPromised);
var browser = {
host: '127.0.0.1',
port: 4444,
desiredCapabilities: {
browserName : 'chrome',
chromeOptions: {
args: [
'no-sandbox',
'use-fake-device-for-media-stream',
'use-fake-ui-for-media-stream',
'mute-audio',
]
},
loggingPrefs: {
'driver': 'INFO',
'browser': 'INFO'
}
},
};
var matrix = WebdriverIO.multiremote({
browserA: browser,
browserB: browser,
});
chaiAsPromised.transferPromiseness = matrix.transferPromiseness;
var browserA = matrix.select('browserA');
var browserB = matrix.select('browserB');
it('should initialize browsers', function() {
return matrix.init();
});
it('should open two browsers', function(done) {
browserA.url('https://127.0.0.1:3000/');
browserB.url('https://127.0.0.1:3000/');
matrix.timeouts('implicit', 15000);
matrix.sync().call(done);
});
it('should return logs', function(done) {
browserA
.log('browser', function(err, msg, a) {
console.log(msg);
})
.call(done);
});
Does someone know how to use this function properly? It also doesnt work when I just use one browser and not creating a Matrix like I did in the code snippet.
You are using the API wrong. You can not pass in a callback to the log method. The command returns a promise (if you use a standalone script like that) so you need to do:
browserA
.log('browser').then(function(msg) {
console.log(msg);
})

test is not executed - nightwatch with standard mocha and phantomjs

so i have a nodejs server and I want to start on some functional tests with nightwatch.
If I start selenium manually and I run it with mocha ( command: mocha ./test/functional/*.spec.js --compilers js:babel-register) it starts the node server and runs fine in firefox(default - by the way using standard mocha how can it be changed from default firefox to other browser?):
import nightwatch from 'nightwatch';
require('../../server');
describe('Functional', function wrapIt() {
const client = nightwatch.initClient({
silent: true,
});
const browser = client.api();
this.timeout(99999999);
beforeEach((done) => {
client.start(done);
});
it('should login', (done) => {
browser
.url('http://localhost:8441/')
.waitForElementVisible('button[name=login]', 1000)
.click('button[name=login]')
.pause(1000);
browser.expect.element('button').to.have.attribute('class').which.contains('theme__button');
browser.end();
client.start(done);
});
after((done) => {
browser.end();
client.start(done);
});
});
Now i want to put it on Bamboo and use phantomjs, selenium server starts, nodejs server starts but the test is not executed.
I have nightwatch.json:
{
"src_folders" : ["test/night"],
"output_folder": "reports",
"test_runner" : "mocha",
"selenium" : {
"start_process": true,
"server_path": ".//bin/selenium-server-standalone-2.53.1.jar",
"log_path": "./reports",
"host": "127.0.0.1",
"port": 4444
},
"test_settings" : {
"default" : {
"desiredCapabilities": {
"browserName": "phantomjs",
"phantomjs.cli.args" : ["--ignore-ssl-errors=true"],
"version":"latest",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
,nightwatch.conf.js is:
require('babel-core/register');
module.exports = require('./nightwatch.json');
and the test script in night folder:
require('../../server');
describe('Functional', function wrapIt() {
const client = this.client;
const browser = client.api();
this.timeout(99999999);
beforeEach((done) => {
client.start(done);
});
it('should login', (done) => {
browser
.url('http://localhost:8441/')
.waitForElementVisible('button[name=login]', 1000)
.click('button[name=login]')
.pause(1000);
browser.expect.element('button').to.have.attribute('class').which.contains('theme__button');
browser.end();
client.start(done);
});
after((done) => {
browser.end();
client.start(done);
});
});
So running it with nightwatch it starts the selenium server, also the nodejs server starts ok but then nothing happens.
I changed it using webdriver:
export const client = require('webdriverjs').remote({ // eslint-disable-line
// Settings
desiredCapabilities: {
// You may choose other browsers
// http://code.google.com/p/selenium/wiki/DesiredCapabilities
browserName: 'phantomjs',
},
// webdriverjs has a lot of output which is generally useless
// However, if anything goes wrong, remove this to see more details
logLevel: 'silent',
});
client.init();
and:
require('../../server');
const client = require('./client').client;
describe('Functional testing', function wrapIt() {
this.timeout(99999999);
before((done) => {
client.init().url('http://localhost:8441/', done);
});
describe('Check homepage', () => {
it('should login', (done) => {
client.waitFor('button[name=login]', 100, () => {
client.click('button[name=login]', () => {
client.element('.theme__button*');
client.waitForVisible(1000);
client.end();
});
});
done();
});
});
after((done) => {
client.end();
done();
});
});
and it works running mocha './test/funcTest.js' --compilers js:babel-register -t 10000
PS: selenium is already started local and on bamboo I added a commmand to start it

Testing angular services in rails

I'm trying to test my services with jasmine and I keep gettin and "Unknown provider: AuthServiceProvider <- AuthService in angular/angular.js on line 2683"
my service is defined:
app.factory( 'AuthService', ["$resource", "$rootScope", "apiPrefix", function($resource, $rootScope, apiPrefix) {
auth_resource = $resource(apiPrefix + "/session", {}, {
logout: {method:'GET'}
});
var currentUser;
return {
login: function(email, password, success, failure) {
auth_resource.save({}, {
email: email,
password: password
}, function(response){
currentUser = response
success()
}, function(response){
failure()
});
},
logout: function(success, failure) {
auth_resource.logout(
function(response){
currentUser = undefined
}, function(){
$scope.alerts.push({type: "success", msg: "Logged out" })
}, function(){
$scope.alerts.push({type: "error", msg: "Sorry, something went wrong" })
}
)
},
isLoggedIn: function(){ return currentUser !== undefined},
currentUser: function() { return currentUser; }
};
}]);
and my test:
describe("AuthService", function(){
var httpBackend;
beforeEach(inject(function($httpBackend, AuthService){
module('app');
httpBackend = $httpBackend;
AService = AuthService;
}));
it("should login the user", function(){
// test here
});
});
my jasmine config file is:
// This pulls in all your specs from the javascripts directory into Jasmine:
// spec/javascripts/*_spec.js.coffee
// spec/javascripts/*_spec.js
// spec/javascripts/*_spec.js.erb
//= require application
//= require_tree ./
This seems to be configured properly because I can test my controllers fine so I'm not sure why it doesn't recognize my services.
You can use $injector to get the service and then inject it to the actual test like this
describe("AuthService", function () {
var httpBackend, AService, apiPrefix;
beforeEach(module('app'));
beforeEach(function () {
angular.mock.inject(function ($injector) {
httpBackend = $injector.get('$httpBackend');
apiPrefix = angular.mock.module('apiPrefix'); // I assume you have apiPrefix module defined somewhere in your code.
AService = $injector.get('AuthService', {apiPrefix: apiPrefix});
})
});
it("should login the user", inject(function (AService) {
// test here
}));
});
I assume you have apiPrefix module defined somewhere in your code.