selenium/standalone-chrome:2.53.1: When using this open page is blank - selenium

I am using selenium/standalone-chrome-:2.53.1 docker image for nightwatch.conf.js to execute test cases.
Below is the configuration for nightwatch.conf.js
'use strict';
const path = require('path');
const nightwatchCucumber = require('nightwatch-cucumber');
const cucumberConfig = {
stepDefinitions: path.resolve(__dirname, 'features/step-definitions'),
};
module.exports = {
src_folders: [nightwatchCucumber(cucumberConfig)],
output_folder: 'reports',
custom_commands_path: '',
custom_assertions_path: '',
globals_path: '',
live_output: false,
page_objects_path: path.resolve(__dirname, 'page-objects'),
parallel_process_delay: 10,
disable_colors: false,
test_workers: false,
test_settings: {
default: {
launch_url: 'any URL',
selenium_host: 'localhost',
selenium_port: 4444,
silent: false,
disable_colors: true,
screenshots: {
enabled: true,
on_failure: true,
path: path.resolve(__dirname, 'screenshots'),
},
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--no-sandbox']
},
//acceptSslCerts: true,
//javascriptEnabled: true,
},
globals: {
user: {
username: 'user1',
password: 'password1',
},
hrUser: {
username: 'user2',
password: 'password2',
},
}
},
When I execute test cases, they fail. In console log :
Timed out while waiting for element <.AppLoginTest> to be present
for 5000 milliseconds. - expected "visible" but got: "not found"
at Object.<anonymous> (/home/<user>/automation-tests/features/step-definitions/login.js:19:8)
at next (native)
If I execute above test case using normal chrome then it passes.
Problem is coming only with when I run test case using chrome headless browser.
I do not know why this error is coming with headless browsers? I have even used phantomJS and found same issue.
Can some one point out what could be the issue?

Related

When I use #walletconnect/web3 provider in Vue, the following error occurs on the browser console

This is the TS code:
import WalletConnectProvider from "#walletconnect/web3-provider";
export const provider = new WalletConnectProvider({
infuraId: "e4ea80f8c3764a1ea0a582a4846d708c"
});
The browser console reports the following error:
Try adding this to vue.config.js:
module.exports = {
...
configureWebpack: {
resolve: {
fallback: {
assert: false,
stream: false,
os: false,
url: false,
http: false,
https: false,
buffer: require.resolve('buffer')
}
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: [ 'buffer', 'Buffer' ]
})
],
}
};

How to call the Nightwatch.runTests correctly?

When I call the Nightwatch.runTests method from the code, I get an error:
/ Connecting to 127.0.0.1 on port 4444...
POST /wd/hub/session - ECONNREFUSED
‼ Error connecting to 127.0.0.1 on port 4444.
_________________________________________________
Error: An error occurred while retrieving a new session: "Connection refused to 127.0.0.1:4444". If the Webdriver/Selenium service is managed by Nightwatch, check if "start_process" is set to "true".
at Socket.socketErrorListener (_http_client.js:407:9)
at emitErrorNT (internal/streams/destroy.js:84:8)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
The documentation here and here says that the method accepts two parameters: [testSource] and [settings].
As [testSource] I specify the path to the folder with the tests. For [settings], I specify a json object equivalent to the contents of the nightwatch.json file. As stated in the error, the parameter "start_process" is set to true.
Here is the code to reproduce:
const Nightwatch = require('nightwatch');
const seleniumServer = require('selenium-server-standalone-jar');
const chromedriver = require('chromedriver');
const settings = {
src_folders: ['tests'],
output_folder: 'reports',
detailed_output: true,
live_output: true,
selenium: {
start_process: false,
"server_path": seleniumServer.path,
"log_path": "logs",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"trustAllSSLCertificates": true,
"webdriver.chrome.driver": chromedriver.path
}
},
test_settings: {
default: {
silent: true,
disable_error_log: false,
screenshots: {
enabled: false,
path: 'screenshots',
on_failure: true
},
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true,
chromeOptions: {
w3c: false
}
}
}
}
};
Nightwatch.runTests('tests', settings).then(function() {
// Tests finished
}).catch(function(err) {
// An error occurred
});
In my project I use "nightwatch": "^ 1.3.6" and "selenium-server-standalone-jar": "^ 3.141.59".
I also changed the settings object, in accordance with the structure of the auto-generated file "nightwatch.conf.js":
const settings = {
src_folders: ['tests'],
output_folder: 'reports',
detailed_output: true,
live_output: true,
test_settings: {
default: {
disable_error_log: false,
launch_url: 'https://nightwatchjs.org',
screenshots: {
enabled: false,
path: 'screens',
on_failure: true
},
desiredCapabilities: {
browserName: 'chrome'
},
webdriver: {
start_process: true,
server_path: chromedriver.path
}
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: []
}
},
webdriver: {
start_process: true,
port: 9515,
server_path: chromedriver.path,
cli_args: []
}
},
selenium: {
selenium: {
start_process: true,
port: 4444,
server_path: seleniumServer.path,
cli_args: {
'webdriver.chrome.driver': chromedriver.path
}
}
},
'selenium.chrome': {
extends: 'selenium',
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
w3c: true
}
}
}
}
};
but this did not help, the error continues to arise.
I would be grateful if anyone could help solve this problem.
Instead of start_process: false you need to set start_process: true,
and instead of w3c: false you need to set w3c: true effectively:
const settings = {
src_folders: ['tests'],
output_folder: 'reports',
detailed_output: true,
live_output: true,
selenium: {
start_process: true,
.
.
"cli_args": {
"trustAllSSLCertificates": true,
"webdriver.chrome.driver": chromedriver.path
}
and
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true,
chromeOptions: {
w3c: true
}
}
}

I am facing a syntax related problem while setting codeceptjs using webdriver.io for my test automation

The problem is with the config file where I'm setting port to open up chrome. I am following 1) https://codecept.io/webdriver/#what-is-selenium-webdriver and ran a test using: npx codeceptjs run.
const { setHeadlessWhen } = require('#codeceptjs/configure');
// turn on headless mode when running with HEADLESS=true environment variable
// HEADLESS=true npx codecept run
setHeadlessWhen(process.env.HEADLESS);
exports.config = {
tests: './*_test.js',
output: './output',
helpers: {
WebDriver: {
url: 'www.fb.com',
browser: 'chrome'
host:'127.0.0.1',
port: 4444,
restart: false,
windowSize: '1920x1680',
desiredCapabilities: {
chromeOptions: {
args: [ /*"--headless",*/ "--disable-gpu", "--no-sandbox" ]
}
},
},
}
include: {
I: './steps_file.js'
},
bootstrap: null,
mocha: {},
name: 'codecepjs',
plugins: {
wdio: {
enabled: true,
services: ['selenium-standalone']
}
retryFailedStep: {
enabled: true
},
screenshotOnFail: {
enabled: true
}
}
};
const { setHeadlessWhen } = require('#codeceptjs/configure');
// turn on headless mode when running with HEADLESS=true environment variable
// HEADLESS=true npx codecept run
setHeadlessWhen(process.env.HEADLESS);
exports.config = {
tests: './*_test.js',
output: './output',
helpers: {
WebDriver: {
url: 'www.github.com',
browser: 'chrome',
host:'127.0.0.1',
port: 4444,
restart: false,
keepBrowserState: true,
keepCookies: true,
windowSize: '1920x1680',
desiredCapabilities: {
chromeOptions: {
args: [ /*"--headless",*/ "--disable-gpu", "--no-sandbox" ]
}
},
},
},
include: {
I: './steps_file.js'
},
bootstrap: null,
mocha: {},
name: 'codecepjs',
plugins: {
wdio: {
enabled: true,
services: ['selenium-standalone']
},
retryFailedStep: {
enabled: true
},
screenshotOnFail: {
enabled: true
}
}
};

karma+webpack+typescript+mocha require is not defined

I try to configure my environment to run tests on node.
This my my webpack.config.test.js
const serverConfig = {
module: {
loaders: [
{test: /\.tsx?$/, loader: 'ts-loader' }
]
},
target: 'node',
externals:[nodeExternals()],
resolve: {
extensions: ['.ts', '.tsx', '.js']
}
};
module.exports = serverConfig;
karma.config.js
// Karma configuration
// Generated on Tue Jun 27 2017 07:20:43 GMT-0500 (Hora est. Pacífico, Sudamérica)
const webpackConfig=require('./config/webpack/webpack.test');
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha','es6-shim'],
plugins:[
require("karma-es6-shim"),
'karma-webpack',
'karma-jsdom-launcher',
'karma-mocha',
'karma-spec-reporter',
'karma-jsdom-launcher',
'karma-coverage',
'karma-chrome-launcher',
"karma-phantomjs-launcher",
'karma-htmlfile-reporter'
],
files: [
'test/**/*.spec.ts'
],
coverageReporter: {
webpackMiddleware: {
stats: "errors-only"
},
dir: 'build/coverage/',
reporters: [
{ type: 'html' },
{ type: 'text' },
{ type: 'text-summary' }
]
},
// list of files to exclude
exclude: [
],
preprocessors: {
'test/**/*.spec.ts':["webpack","coverage"]
},
webpack:webpackConfig,
reporters: ['spec','progress','html'],
htmlReporter: {
outputFile: 'tests/units.html',
// Optional
pageTitle: 'Unit Tests',
subPageTitle: 'A sample project description',
groupSuites: true,
useCompactStyle: true,
useLegacyStyle: true
},
// web server port
port: 9876,
colors: true,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false,
concurrency: Infinity
})
}
test1
import { DBCONFIG } from './../src/config/db.config';
import { CONEXION } from './../src/config/database/mongo';
import { expect } from 'chai';
describe("#DATABASE",()=>{
it("Esta conectado",()=>{
CONEXION("hola",DBCONFIG.MONGO_URL_LOCAL)
.then(()=>{
expect(1).to.be("1");
})
.catch((e)=>{
expect(1).to.be(e);
})
})
});
test2
import { expect } from 'chai';
describe("#User",()=>{
it("use2r",()=>{
expect(1).to.equal("1");
})
})
When I run mocha + webpack with mocha-webpack, there is no problem the tests are running.
package.json
"test-server": "mocha-webpack --timeout 1000 --webpack-config config/webpack/webpack.test.js test/**/*.spec.ts",
"test":"karma start"
When I do it from karma depending on which browser I use to display the messages I throw similar errors, when I throw it with jsdom or PhantomJS I throw the following
require is not defined o Cannot find
Looking in git, the only answer that solved the problem, is to put in the processors of karma the following.
'test/**/*.spec.ts':["webpack","coverage"]
It is the same way and I have varied, but the error continues.

Karma setup for Angular 2.

I am trying to setup Karma with Jasmine for testing my Angular2 app. Karma fails to append extensions for imports in spec files. For example my spec file has import {TileComponent} from './tiles.component';
When I run Karma I get the following error: http://localhost:9876/base/wwwroot/app/tiles/tiles.component 404 (Not Found)
If I try to go to this link and manually apend js at the end it will load my file.
karma.conf.js:
module.exports = function (config) {
var appBase = 'wwwroot/app/';
var appAssets = '/base/app/';
config.set({
basePath: '',
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-htmlfile-reporter')
],
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
files: [ 'node_modules/systemjs/dist/system.src.js',
'node_modules/core-js/client/shim.js',
'node_modules/reflect-metadata/Reflect.js',
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/zone.js/dist/async-test.js',
'node_modules/zone.js/dist/fake-async-test.js',
// RxJs.
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
{ pattern: 'node_modules/#angular/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/#angular/**/*.js.map', included: false, watched: false },
{ pattern: 'systemjs.config.js', included: false, watched: false },
//{ pattern: 'karma-test-shim.js', included: false, watched: false },
//'systemjs.config.js',
'karma-test-shim.js',
{ pattern: appBase + '**/*.js', included: false, watched: true },
{ pattern: appBase + '**/*.html', included: false, watched: true },
{ pattern: 'wwwroot/styles/**/*.css', included: false, watched: true },
{ pattern: 'app/**/*.ts', included: false, watched: false },
{ pattern: appBase + '**/*.js.map', included: false, watched: false }
],
proxies: {
"/app/": appAssets
},
exclude: [],
preprocessors: {},
reporters: ['progress', 'html'],
htmlReporter: {
outputFile: '_test-output/tests.html',
pageTitle: 'Unit Tests',
subPageTitle: __dirname
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
})
}
karma-test-shim.js
// /*global jasmine, __karma__, window*/
Error.stackTraceLimit = Infinity;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
__karma__.loaded = function () {
};
function isJsFile(path) {
return path.slice(-3) === '.js';
}
function isSpecFile(path) {
return /\.spec\.js$/.test(path);
}
function isBuiltFile(path) {
var builtPath = '/base/wwwroot/';
return isJsFile(path) && (path.substr(0, builtPath.length) === builtPath);
}
var allSpecFiles = Object.keys(window.__karma__.files)
.filter(isSpecFile)
.filter(isBuiltFile);
System.config({
baseURL: '/base',
packageWithIndex: true, // sadly, we can't use umd packages (yet?)
map: {
'http://localhost:9876/base/wwwroot/app/app.component': 'http://localhost:9876/base/wwwroot/app/app.component.js'
}
});
System.import('systemjs.config.js')
.then(function () {
return Promise.all([
System.import('#angular/core/testing'),
System.import('#angular/platform-browser-dynamic/testing')
])
})
.then(function (providers) {
var testing = providers[0];
var testingBrowser = providers[1];
testing.setBaseTestProviders(
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
})
.then(function () {
// Finally, load all spec files.
// This will run the tests directly.
return Promise.all(
allSpecFiles.map(function (moduleName) {
return System.import(moduleName);
}));
})
.then(__karma__.start, __karma__.error);
The problem was that I was importing system.config.js twice. I removed import from karma.conf.js file.
I also did some minor path changes.