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
Related
I'm working on some tests using Detox for my React-Native application, one of those test is a flow where I need to check that the user's session is secured. If not, I'm sending an SMS Verification Code.
Test : Success to mock the POST API Call api/sessions/:sessionId, {code : 123456}
Problem : Mirage is not catching the call, so of course my Saga return an error for the fake code 123456, where I want instead Mirage.JS to return true to continue the flow.
Here are the file (file.spec.js):
import { Server } from "miragejs"
import { makeServer } from "./server";
let server;
beforeEach(() => {
server = makeServer({ environment: "development" });
})
afterEach(() => {
server.shutdown()
})
describe('SecureFlow', () => {
it("should do nav to a project and start Investment Flow", async () => {
server.get("https://random-api.eu/sessions/:sessionId", () => {
return new Response( 200, {}, { ok: true });
});
await basicNavigation(); //randomNavigation until the secure part (Screen)
await element(by.id('Accept-andLend')).tap();
await element(by.id('textInput-SMSCode')).typeText("123456");
})
})
server.js
import { Server, Model, Factory } from "miragejs";
export function makeServer({ environment = "development" } = {}) {
let server = new Server({
environment,
models: {
},
routes() {
this.post("https://random-api.eu/sessions/:sessionId", schema => {
return [{ok: true}];
});
}
});
return server;
}
I have used the example from : https://github.com/SeleniumHQ/selenium/wiki/WebDriverJs#defining-multiple-flows
and trying to run the test parallelly so that each browser will be concurrently executed. Here is the script:
const {Builder, By, Key, until} = require('selenium-webdriver');
var browsers = [
{ browserName: 'chrome' },
{ browserName: 'firefox'},
];
browsers.map(browser => {
describe('Google Search', function() {
let driver;
beforeEach(async function() {
driver = await new Builder().forBrowser(browser.browserName).build();
}, 10 * 1000);
afterEach(async function() {
await driver.quit();
});
it('example', async function() {
await driver.get('https://www.google.com/ncr');
await driver.manage().setTimeouts({ implicit: 5000 })
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
}, 10 * 1000);
});
});
My knowledge in jest/jscript is limited. Apologies if there is anything fundamentally wrong.
I have tried both running locally and running against zalenium. In both cases, tests are running sequentially.
Thank you for the Help in making the script run parallelly.
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
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.
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);
})