Please, show me how to use Protractor with RequireJS.
code works
var dentalConfig = require('./conf/dentalConfig.js');
var login = require('./pages/login.js');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: dentalConfig.baseUrl,
specs: [
'pages/company.js'
],
onPrepare: function () {
login();
}
};
but if i put exports.config inside of requirejs()
protractor throw error:
c:\Users\UserName\AppData\Roaming\npm\node_modules\protractor\lib\configParser.js:184
fileConfig.configDir = path.dirname(filePath);
TypeError: Cannot set property 'configDir' of undefined.
this doesn't work
var requirejs = require('requirejs');
requirejs.config({
baseUrl: './',
nodeRequire: require
});
requirejs([
'conf/dentalConfig',
'pages/login'
],
function (dentalConfig, login) {
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: dentalConfig.baseUrl,
specs: [
'pages/company.js'
],
onPrepare: function () {
login();
}
};
}
);
Your config file should look something like this..
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect: true,
framework: 'jasmine',
specs: ['TestScript name that has to be executed.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose:true,
includeStackTrace:true
},
capabilities: {
'browserName': 'chrome',
},
}
Related
The Snowpack Svelte template includes a Jest setup which works well for Svelte apps and works out of the box. However, once svelte-preprocess is added, Jest hangs indefinitely.
This can easily be seen using https://github.com/agneym/svelte-tailwind-snowpack, which can be setup with:
npx create-snowpack-app dir-name --template svelte-tailwind-snowpack
svelte.config.js looks like this, although even if the pre-processor doesn't include Tailwind it still hangs:
const sveltePreprocess = require("svelte-preprocess");
const preprocess = sveltePreprocess({
postcss: {
plugins: [require("tailwindcss"), require("autoprefixer")],
},
});
module.exports = {
preprocess,
};
jest.config.js
const fs = require("fs");
const path = require("path");
// Use this instead of `paths.testsSetup` to avoid putting
// an absolute filename into configuration after ejecting.
// const setupTestsFile = fs.existsSync(paths.testsSetup)
// ? `<rootDir>/src/setupTests.js`
// : undefined;
const setupTestsFile = true;
module.exports = function () {
const userSvelteConfig = getUserSvelteConfig();
return {
testMatch: [
"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
"<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}",
],
transform: {
"^.+\\.svelte$": [
"jest-transform-svelte",
{ preprocess: userSvelteConfig.preprocess },
],
"^.+\\.(js|ts)$": path.resolve(__dirname, "jest/babelTransform.js"),
},
moduleFileExtensions: ["js", "ts", "svelte"],
testPathIgnorePatterns: ["node_modules"],
transformIgnorePatterns: ["node_modules"],
bail: false,
verbose: true,
setupFilesAfterEnv: setupTestsFile ? ["<rootDir>/jest.setup.js"] : [],
};
};
function getUserSvelteConfig() {
const userSvelteConfigLoc = path.join(process.cwd(), "svelte.config.js");
if (fs.existsSync(userSvelteConfigLoc)) {
return require(userSvelteConfigLoc);
}
return {};
}
Have to eject the default Snowpack configuration file and use svelte-jester instead of the config they were using. The config below works:
const fs = require("fs");
const path = require("path");
// Use this instead of `paths.testsSetup` to avoid putting
// an absolute filename into configuration after ejecting.
// const setupTestsFile = fs.existsSync(paths.testsSetup)
// ? `<rootDir>/src/setupTests.js`
// : undefined;
const setupTestsFile = true;
module.exports = function () {
const userSvelteConfig = getUserSvelteConfig();
return {
rootDir: "./",
testMatch: [
"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
"<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}",
],
transform: {
"^.+\\.svelte$": [
"svelte-jester",
{ "preprocess": true },
],
"^.+\\.(js|ts)$": "babel-jest",
},
moduleFileExtensions: ["js", "ts", "svelte"],
testPathIgnorePatterns: ["node_modules"],
transformIgnorePatterns: ["node_modules"],
bail: false,
verbose: true,
setupFilesAfterEnv: setupTestsFile ? ["<rootDir>/jest.setup.js"] : [],
};
};
function getUserSvelteConfig() {
const userSvelteConfigLoc = path.join(process.cwd(), "svelte.config.js");
if (fs.existsSync(userSvelteConfigLoc)) {
return require(userSvelteConfigLoc);
}
return {};
}
My protractor.conf.js has the following content. I was unable to find out whats wrong here. I have manually created target/screenshots in my root folder of angular-cli. When i run protractor conf.js the protractor tests in browser window but the screenshots aren't being generated. Can anyone help me resolve this?
// Protractor configuration file
const { SpecReporter } = require('jasmine-spec-reporter');
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var fs = require('fs');
var reporter = new HtmlScreenshotReporter({
dest: 'target/screenshots',
filename: 'my-report.html',
cleanDestination: false,
showSummary: true,
showConfiguration: false,
reportTitle: null,
ignoreSkippedSpecs: false,
captureOnlyFailedSpecs: false,
reportOnlyFailedSpecs: false
});
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: false,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
chromeOnly: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(reporter);
},
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
Thanks in Advance!
You can check by adding the 'protractor-screenshoter-plugin'
plugins: [{
package: 'protractor-screenshoter-plugin',
screenshotPath: <specify the path>,
screenshotOnExpect: 'failure',
screenshotOnSpec: 'failure+success',
withLogs: 'true',
writeReportFreq: 'asap',
imageToAscii: 'failure',
htmlReport:'true',
verbose:'info',
clearFoldersBeforeTest: true,
failTestOnErrorLog: {
failTestOnErrorLogLevel: 900
}
},
Can also check https://www.npmjs.com/package/protractor-screenshoter-plugin
protractor-jasmine2-screenshot-reporter compatible with jasmine2, so change to framework: 'jasmine2' in your conf.js
And you need to use higher version of Protractor which includes jasmine2
I did a quick test with your conf(did little changes) and it worked.
conf.js
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
// var fs = require('fs');
var reporter = new HtmlScreenshotReporter({
dest: 'target/screenshots',
filename: 'my-report.html',
cleanDestination: false,
showSummary: true,
showConfiguration: false,
reportTitle: null,
ignoreSkippedSpecs: false,
captureOnlyFailedSpecs: false,
reportOnlyFailedSpecs: false
});
exports.config = {
allScriptsTimeout: 11000,
// specs: [
// './e2e/**/*.e2e-spec.ts'
// ],
capabilities: {
'browserName': 'chrome'
},
directConnect: false,
// baseUrl: 'http://localhost:4200/',
framework: 'jasmine2',
// chromeOnly: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
jasmine.getEnv().addReporter(reporter);
},
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
spec.js
describe('xxx', function(){
it('yyy', function(){
browser.get('https://angular.io/');
});
});
target/screenshots folder and HTML report,
(I run for twice, so there are two screenshots.)
click the yyy will open the screenshot
protractor-jasmine2-screenshot-reporter will create target/screenshots folder if not exist, no need to create in advance.
Version I used:
protractor 5.3.0
protractor-jasmine2-screenshot-reporter 0.5.0
I am trying to take the "Screen shot" of the web page when the "test case fails".
I installed "protractor-jasmine2-screenshot-reporter" using "npm".
I am using below data.
1.Node -- v6.11.4
2.NPM -- 3.10.10
3.Protractor -- 5.1.2
My "Protractor.conf.js" file code below.
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest: 'C:/Users/agudla/Desktop/VSCodeWorkSpace/my-app/screenshots',
filename: 'my-report.html'
});
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
multiCapabilities: [{
'browserName': 'chrome',
'seleniumAddress':'http://localhost:4444/wd/hub'
},
{'browserName': 'firefox',
'marionette': 'false',
'seleniumAddress':'http://localhost:4444/wd/hub'
}
],
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
beforeLaunch: function() {
return new Promise(function(resolve){
reporter.beforeLaunch(resolve);
});
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(reporter);
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
I am getting below error message while running the test script.
ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444
Can any one help me to solve this issue.
It is working now , i run "Selenium server" and i changed the var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter'); as
var Jasmine2HtmlReporter = require('C:/Users/agudla/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');
Should have to provide complete "path" for the "protractor jasmine2 html reporter".
To know the "protractor jasmine2 html reporter" path in your system , type below command in command prompt.
npm link protractor-jasmine2-html-reporter
It will print the complete path .
Hi I have write a nodejs application that contains some tests written in jasmine.I am trying to get the test results published in TFS using CLI.
I have installed the following packages
"jasmine-spec-reporter": "^4.1.1",
"jasmine-tfs-reporter": "^1.0.0",
"phantomjs-prebuilt": "^2.1.14",
"ts-node": "^3.2.0"
Following is the protractor.conf
/*global jasmine */
var SpecReporter = require('jasmine-spec-reporter');
var TfsReporter = require('jasmine-tfs-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/tests/*spec.js'
],
capabilities: {
'browserName': 'phantomjs',
'phantomjs.binary.path': require('phantomjs-prebuilt').path,
'phantomjs.ghostdriver.cli.args': ['--loglevel=DEBUG']
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
useAllAngular2AppRoots: false,
beforeLaunch: function() {
require('ts-node').register({
project: 'PartyAndIndustryDataMigration'
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(new SpecReporter());
jasmine.getEnv().addReporter(new TfsReporter());
}
};
When i try and execute protractor from the command prompt i get error
the specified path does not exist PartyAndIndustryDataMigration
It was a minor fix. It had to just correct the path
useAllAngular2AppRoots: false,
beforeLaunch: function() {
require('ts-node').register({
project: '../PartyAndIndustryDataMigration'
});
},
Below is the config file which contains both 'protractor-jasmine2-screenshot-reporter' and 'jasmine-reporter'
It works fine individually but if i combine both the protractor-jasmine2-screenshot-reporter' is not working ,is it because i have two 'onPrepare' functions
var HtmlScreenshotReporter = require('C:/Protractor_Scripts/node_modules/protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest: 'C:/Protractor_Scripts/Screenshots',
filename: 'Report.html'
});
exports.config = {
directConnect: false,
multiCapabilities: [
{'browserName': 'chrome'},
{'browserName': 'firefox'}
],
allScriptsTimeout: 1200000,
framework: 'jasmine2',
specs: ['C:/Protractor_Scripts/Protractor/Driver/Driver.js'],
// Setup the report before any tests start
beforeLaunch: function() {
return new Promise(function(resolve){
reporter.beforeLaunch(resolve);
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
},
Jasmine Reporter which is used to generate xml reports
onPrepare: function() {
var jasmineReporters = require('C:/Protractor_Scripts/node_modules/jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'C:/Protractor_Scripts/Results',
filePrefix: 'xmloutput'
}));
},
// ----- Options to be passed to minijasminenode -----
jasmineNodeOpts: {
// onComplete will be called just before the driver quits.
onComplete: null,
// If true, display spec names.
isVerbose: false,
// If true, print colors to the terminal.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 1200000
}
};
Don't define two onPrepare functions, put everything into a single one:
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
var jasmineReporters = require('C:/Protractor_Scripts/node_modules/jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'C:/Protractor_Scripts/Results',
filePrefix: 'xmloutput'
}));
},