I'm trying to create grunt tasks using grunt-protractor-runner with my protractor-cucumber framework. Below is how the Gruntfile.js looks like:
grunt.initConfig({
protractor: {
options: {
//configFile: "./config/config.js",
keepAlive: true,
noColor: false,
},
chrome: {
options: {
configFile: "./config/config.js",
args: {
autoConnect: false,
seleniumServerJar: './node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar',
chromeDriver: './node_modules/webdriver-manager/selenium/chromedriver.exe',
specs: [
'../features/calendar.feature',
'../features/deal.feature',
'../features/entitlement.feature',
'../features/filter.feature',
'../features/product.feature'
],
capabilities: {
browserName: 'chrome',
chromeOptions: {
useAutomationExtension: false,
args: ['–disable-gpu'],
}
}
}
}
}
},
});
grunt.registerTask('test', ['protractor:chrome']);
If I run command grunt test it opens the chrome browser and closes with the below log:
Running "protractor:chrome" (protractor) task
[17:22:57] I/launcher - Running 1 instances of WebDriver
[17:22:57] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
0 scenarios
0 steps
0m00.000s
This doesn't pick any scenarios to run. Can you help me to understand what's the issue here? My config.conf looks like this:
const Reporter = require('../support/Reporter.js');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
autoConnect: false,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
restartBrowserBetweenTests: false,
SELENIUM_PROMISE_MANAGER: true,
ignoreUncaughtExceptions: true,
onPrepare: function () {
browser.ignoreSynchronization = false;
browser.manage().timeouts().setScriptTimeout(40 * 1000);
browser.manage().timeouts().implicitlyWait(4 * 1000);
browser.manage().window().maximize();
require('babel-register');
},
cucumberOpts: {
strict: true,
format: ['json:./reports/json/cucumber_report.json'],
require: ['../support/*.js', '../stepDefinitions/*.js', '../stepDefinitions/*.ts'],
tags: 'not #Ignore', //(#CucumberScenario or #ProtractorScenario) and (not #Ignore)
retry: 3
},
params: {
env: 'test',
test: {
url: '',
users: {
BankerRO: '',
BankerRW: '',
BusinessRiskRW: '',
RiskRW: '',
RO: '',
},
db: {
server: '',
port: '',
name: '',
userId: '',
password: '',
}
}
},
onComplete: function () {
Reporter.moveReportToArchive();
Reporter.createHTMLReport();
}
};
I finally found out the root-cause, if I keep spec[] part in the Gruntfile, grunt fails to pick the scenarios even from config.js. When I removed spec from Gruntfile and kept it in the config.js, it started working fine. I'm not sure this is how it works or a potential bug with grunt-protractor-runner
Conclusion: Looks like grunt-protractor-runner looks for specs in config.js file and ignores if you keep it in Gruntfile.js
I have raised this as an issue: https://github.com/teerapap/grunt-protractor-runner/issues/197#issue-537600108
Related
I was trying to execute the appium script in an virtual emulator.But while executing i am getting this below error.In emulator the app is launched but it doesn't perform any action gets closed.
Error:-
[16:52:46] E/launcher - An unknown server-side error occurred while processing the command. Original error: No Chromedriver found that can automate Chrome '77.0.3865'. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details. You could also try to enable automated chromedrivers download server feature
[16:52:46] E/launcher - WebDriverError: An unknown server-side error occurred while processing the command. Original error: No Chromedriver found that can automate Chrome '77.0.3865'. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details. You could also try to enable automated chromedrivers download server feature
[16:52:46] E/launcher - Process exited with error code 199
Conf File:-
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 300000,
seleniumAddress: 'http://localhost:4723/wd/hub',
specs: [
'./e2e/**/login.mobile.ts',
],
useAllAngular2AppRoots: true,
//chromeDriver: './node_modules/chromedriver/lib/chromedriver/chromedriver.exe',
capabilities: {
platformName: 'Android',
platformVersion: '9',
deviceName: 'emulator-5554',
browserName: '',
appiumVersion:'1.16.0',
autoWebview: true,
autoWebviewTimeout: 10000,
autoacceptalerts: true,
autoGrantPermissions: true,
clearSystemFiles: true,
app: './platforms/android/build/outputs/apk/android-debug.apk
},
//baseUrl: 'http://10.0.2.2:8000',
plugins: [
{
path: require.resolve('protractor-console'),
logLevels: ['severe'],
package: 'jasmine2-protractor-utils',
disableHTMLReport: false,
disableScreenshot: false,
screenshotPath: './screenshots',
screenshotOnExpectFailure: true,
screenshotOnSpecFailure: true,
clearFoldersBeforeTest: true
}
],
// directConnect: true, //enable for desktop
//baseUrl: 'http://localhost:4723/wd/hub',
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 300000,
print: function() {}
},
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
},
onPrepare() {
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: './report/mobile',
filePrefix: 'xmlresults'
})
);
var wd = require('wd'),
protractor = require('protractor'),
wdBridge = require('wd-bridge')(protractor, wd);
wdBridge.initFromProtractor(exports.config);
},
onComplete: function() {
var browserName, browserVersion;
var capsPromise = browser.getCapabilities();
capsPromise.then(function(caps) {
browserName = caps.get('browserName');
browserVersion = caps.get('version');
var HTMLReport = require('protractor-html-reporter');
testConfig = {
reportTitle: 'CVM Test Execution Report',
outputPath: './report/mobile', //relative path
screenshotPath: './screenshots',
testBrowser: 'Mobile',
browserVersion: browserVersion,
modifiedSuiteName: false,
screenshotsOnlyOnFailure: true
};
new HTMLReport().from('./report/mobile/xmlresults.xml', testConfig);
});
}
};
Oflate , I have been observing below error when ran my protractor tests on browserstack.
"UnhandledPromiseRejectionWarning: WebDriverError: Could not start Browser / Emulator"
Here is my protractor config file.
let browserstack = _.defaults({
user: process.env.BROWSERSTACK_USERNAME,
key: process.env.BROWSERSTACK_ACCESS_KEY
}, {
user: '**',
key: '**'
});
let timeoutMultiplier = 2;
exports.makeDefaultCapabilities = function(that) {
return {
browserName: 'chrome',
chromeOptions: {
prefs: {
credentials_enable_service: false,
},
loggingPrefs: {
driver: 'WARNING',
server: 'WARNING',
browser: 'INFO'
},
'browserstack.user': browserstack.user,
'browserstack.key': browserstack.key,
'browserstack.debug': true,
build: that.params.BUILD_NUMBER || '(unknown)',
maxInstances: 2,
name: that.baseUrl,
}
};
exports.config = {
suites: {
e2e: [
'*/*.spec.js'
]
},
SELENIUM_PROMISE_MANAGER: false,
baseUrl: undefined,
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 60 * 1000 * timeoutMultiplier,
realtimeFailure: true
},
maxSessions: 1,
params: {
BUILD_NUMBER: undefined,
CI: undefined,
TIMEOUT_MULTIPLIER: timeoutMultiplier
},
seleniumAddress: 'https://hub-cloud.browserstack.com/wd/hub',
useAllAngular2AppRoots: true,
getMultiCapabilities: function() {
return new Promise(function(resolve) {
let capabilities = [];
capabilities.push({
os: 'OS X',
os_version: 'High Sierra'
});
resolve(capabilities);
});
},
onPrepare: function() {
browser.manage().window().maximize();
jasmine.getEnv().addReporter(failFast.init());
let reporter = new SpecReporter();
jasmine.getEnv().addReporter(reporter);
}
};
Test that is failing :
calling function :
async clickButton() {
await browser.waitForAngularEnabled(false);
await waitForEl(this.Button);
await browser.sleep(10000);
await this.Button.click();
await browser.sleep(10000);
await this.stopButton.click();
await waitForElAbsence(this.Bar);
await browser.waitForAngularEnabled(true);
}
used above calling function in below spec:
it('should check if button is clicable', async function() {
let po = new check({
url
});
await po.go();
await po.clickButton();
});
Has any one experienced it before ? Also the error is seen only browserstack and not on my local computer. Also the test i pasted is not the only one failing . Tests are failing randomly with this error.
I have protractor v5.3.2
My Conf.js looks like below:
// An example configuration file.
exports.config = {
directConnect: true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: ['test_spec1.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
var log4js = require('log4js');
beforeLaunch:function(){
if (fs.existsSync('./logs/ExecutionLog.log')) {
fs.unlink('./logs/ExecutionLog.log')
}
log4js.configure({
appenders: [
{ type: 'log4js-protractor-appender', category: 'protractorLog4js' },
{
type: "file",
filename: './logs/ExecutionLog.log',
category: 'protractorLog4js'
}
]
});
},
onPrepare: function() {
browser.logger = log4js.getLogger('protractorLog4js');
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmineReporters.JUnitXmlReporter('./Reports', true, true));
}
};
I get following error on running command "protractor conf.js"
You need to move the var log4js = require('log4js'); line to the top of the conf file, above the exports.config ={ .. } block. Also use const instead of var
I am a new to ReactJS, before I used angularJS for my client side. But now I want to integrate it with the present application on SpringMVC. Now I want to integrate ReactJS as client side instead of angularJS, please help me. If there is any example please help. I am using eclipse ide.
Try to create a view(jsp/html/xhtml) and link the UI build output to that. you may use webpack as a build tool for UI(React) which will return bundle file.
Then it can be included to view using script tag. Please note you can use webpack-dev-server for UI development and try to use Proxy to consume the spring-mvc service. Its a recommended way. A folder containing all the JS under webapp can be used if your using Maven as build tool for java.
webpack reference : https://webpack.js.org/
Sample Webpack.config.js for reference.
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: {
main: './src/scripts/main.js',
engine: './src/scripts/engine/Engine.js',
debugger: './src/scripts/debug/Debugmain.js',
client: './src/scripts/clientcode/Client.js'
},
output: {
path: path.resolve('./dist/client'),
filename: '[name].js',
publicPath: '/dist/client/',
chunkFilename: '[name].js'
},
devtool: 'inline-sourcemap',
cache: true,
resolve: {
alias: { ByteBuffer: 'bytebuffer' }
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'react-hot-loader'
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
cacheDirectory: true,
presets: ['react', 'es2015'],
compact: false
}
},
{
enforce: 'pre',
test: /\.(js|jsx)$/,
exclude: /node_modules/,
include: [path.join(__dirname, './src', 'scripts')],
loader: 'eslint-loader'
},
{
test: /\.less$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
loader: 'css-loader?sourceMap!less-loader?sourceMap'
})
},
{
test: /\.(eot|woff|woff2|ttf|otf|png|jpg)$/,
loader: 'file-loader?name=images/[name].[ext]'
}
]
},
devServer: {
port: 8080,
stats: 'errors-only',
proxy: {
'/api': {
target: 'http://localhost:20404', //http://localhost:20403/',
secure: false
}
},
historyApiFallback: {
index: 'debug.html'
}
},
plugins: [
new ExtractTextPlugin({
filename: './styles/main.css',
allChunks: true
})
],
resolve: {
modules: ['src/scripts', 'node_modules'],
extensions: ['.jsx', '.js'],
unsafeCache: true,
alias: {
components: path.resolve(__dirname, 'src', 'scripts', 'components'),
routes: path.resolve(__dirname, '.', 'routes'),
draggable_tab: path.resolve(__dirname, 'src', 'scripts', 'lib'),
utils: path.resolve(__dirname, 'src', 'scripts', 'utils'),
engine: path.resolve(__dirname, 'src', 'scripts', 'engine')
}
}
};
We are working on an Angular project where we are using Karma/Jasmine for our testing environment. We've been using the karma-chrome-launcher for debugging the tests and it was working great. For some reason, it has stopped working lately. I can't figure out why though, as we haven't changed anything regarding that pipeline. We tried updating to latest Karma (1.4.1), but that didn't help. Has anyone else seen this issue and been able to fix it? Help is appreciated. I've attached two images of what the Chrome inspector looks like when you first open the debugger and then after setting a breakpoint and hitting Refresh (it should look the same as the 1st image, but doesn't) edit: karma.config at bottom as well
'use strict';
var path = require('path');
var conf = require('./gulp/conf');
var _ = require('lodash');
var wiredep = require('wiredep');
var pathSrcHtml = [
path.join(conf.paths.src, '/**/*.html')
];
function listFiles() {
var wiredepOptions = _.extend({}, conf.wiredep, {
dependencies: true,
devDependencies: true
});
var patterns = wiredep(wiredepOptions).js
.concat([
path.join(conf.paths.src, '/app/**/*.module.js'),
path.join(conf.paths.src, '/app/**/*.js')
])
.concat(pathSrcHtml)
.concat('karmaMobileFramework/*.js');
var files = patterns.map(function(pattern) {
return {
pattern: pattern
};
});
files.push({
pattern: path.join(conf.paths.src, '/assets/**/*'),
included: false,
served: true,
watched: false
});
return files;
}
module.exports = function(config) {
var configuration = {
files: listFiles(),
singleRun: false,
autoWatch: true,
preprocessors : {
'/**/*.html': ['ng-html2js']
},
ngHtml2JsPreprocessor: {
stripPrefix: conf.paths.src + '/',
moduleName: 'directive-templates'
},
logLevel: 'WARN',
frameworks: ['jasmine', 'jasmine-matchers', 'angular-filesort'],
angularFilesort: {
whitelist: [path.join(conf.paths.src, '/**/!(*.html|*.spec|*.mock).js')]
},
browsers : ['Chrome'],
plugins : [
'karma-chrome-launcher',
'karma-angular-filesort',
'karma-coverage',
'karma-jasmine',
'karma-jasmine-matchers',
'karma-ng-html2js-preprocessor',
'karma-htmlfile-reporter',
'karma-junit-reporter'
],
coverageReporter: {
type : 'html',
dir : 'reports/coverage/',
reporters: [
{ type: 'html', subdir: 'report-html' },
{ type: 'cobertura', subdir: 'report-jenkins' }
]
},
reporters: ['progress', 'html', 'junit'],
junitReporter: {
outputDir: 'reports/tests/',
outputFile: 'test-results.xml',
useBrowserName: false
},
htmlReporter: {
outputFile: 'reports/tests/results.html',
pageTitle: 'BOLT Unit Tests'
},
proxies: {
'/assets/': path.join('/base/', conf.paths.src, '/assets/')
}
};
// This is the default preprocessors configuration for a usage with Karma cli
// The coverage preprocessor is added in gulp/unit-test.js only for single tests
// It was not possible to do it there because karma doesn't let us now if we are
// running a single test or not
configuration.preprocessors = {};
pathSrcHtml.forEach(function(path) {
configuration.preprocessors[path] = ['ng-html2js'];
});
config.set(configuration);
};