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

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
}
}
};

Related

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
}
}
}

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.

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

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?

How to enable sourcemaps with grunt, browserify, and babelify

I'd like to generate sourcemaps for jsx files that are transpiled with babelify and browserify. It seems that some sourcemaps are being generated as a base64 encoded comment at the bottom of my output file, but stacktraces do not honor them.
My grunt task looks like the following:
browserify: {
options: {
browserifyOptions: {
debug: true
},
debug: true,
transform: ['babelify']
},
app: {
src: 'src/app.jsx',
dest: 'dist/app.js'
}
},
This works for me:
browserify: {
dev: {
options: {
browserifyOptions: {
debug: true
},
transform: [["babelify"]]
},
files: {
"dist/bundle.js": "src/index.js"
}
}
},
Going to need to use grunt-exorcise to extract the map from the bundle.
Browserify recommends it
browserify: {
options: {
browserifyOptions: {
debug: true
},
debug: true,
transform: ['babelify']
},
app: {
src: 'src/app.jsx',
dest: 'dist/app.js'
}
},
exorcise: {
app: {
options: {},
files: {
'dist/app.js.map':['dist/app.js'],
}
}
},

grunt-recess not failing for noUnderscores option

I have a LESS file (test.less) with the following class:
.bad_class {
color: #fff
}
I linting and compiling my files with the grunt-recess plugin.
My Grunt options for recess are:
recess: {
options: {
noUnderscores: true
},
test: {
files: {
'assets/css/test.css': [
'assets/less/test.less'
]
}
}
}
When I run recess, it doesn't fail.
I tried without setting the noUnderscores option at all - didn't work.
I even tried setting noUnderscores: false, but that didn't work.
What's am I doing wrong?
Try this
recess: {
build: {
src: [ 'assets/less/test.less' ],
dest: 'assets/css/test.css',
options: {
compile: true,
compress: true,
noUnderscores: false,
noIDs: false,
zeroUnits: false
}
}
}
If above is not working try the below code
recess: {
build: {
src: [ 'assets/less/test.less' ],
dest: 'assets/css/test.css',
options: {
compress: false,
noUnderscores: false,
noIDs: false,
zeroUnits: false
}
},
compliefile:{
src: [ 'assets/less/test.less' ],
dest: 'assets/css/test.css',
options: {
compile: true
}
}
}