vegan#vegan:~/hb-productupload/gateway/src/test/javascript$ gulp protractor
[15:47:24] Working directory changed to ~/hb-productupload/gateway
[15:47:51] Using gulpfile ~/hb-productupload/gateway/gulpfile.js
[15:47:51] Starting 'protractor'...
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/http/index.js:174
callback(new Error(message));
^
Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:47841
at ClientRequest.<anonymous> (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/http/index.js:174:16)
at emitOne (events.js:90:13)
at ClientRequest.emit (events.js:182:7)
at Socket.socketErrorListener (_http_client.js:306:9)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at emitErrorNT (net.js:1265:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
From: Task: WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:157:22)
at Function.webdriver.WebDriver.createSession (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:30)
at new Driver (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/chrome.js:810:36)
at [object Object].DirectDriverProvider.getNewDriver (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/protractor/lib/driverProviders/direct.js:68:16)
at [object Object].Runner.createBrowser (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/protractor/lib/runner.js:186:37)
at /home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/protractor/lib/runner.js:276:21
at _fulfilled (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:759:13)
at /home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:525:49
[launcher] Process exited with error code 1
[15:47:59] gulp-notify: [JHipster Gulp Build] Error: protractor exited with code 1
[15:47:59] Finished 'protractor' after 7.34 s
[15:47:59] E2E Tests failed
I am trying to run a simple
i updated chrme driver.
Then i made
npm install
bower install
gulp install
but did not work when i run
gulp protractor
I run with gulp for project but also i downloaded to my ubuntu and i can run as local. But same error for that local happens when i run
protractor protractor.conf.js
Ysterday i could run both, i made upgrade. now i cant work both.
this is conf file
var HtmlScreenshotReporter = require("protractor-jasmine2-screenshot-reporter");
var JasmineReporters = require('jasmine-reporters');
var prefix = 'src/test/javascript/'.replace(/[^/]+/g, '..');
exports.config = {
chromeDriver: prefix + 'node_modules/protractor/selenium/chromedriver',
allScriptsTimeout: 20000,
suites: {
login: './e2e/account/login/*.js'
},
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
},
onPrepare: function () {
// Disable animations so e2e tests run more quickly
var disableNgAnimate = function () {
angular
.module('disableNgAnimate', [])
.run(
[
'$animate',
function ($animate) {
$animate.enabled(false);
}
]
);
};
var disableCssAnimate = function () {
angular
.module('disableCssAnimate', [])
.run(
function () {
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = 'body * {' +
'-webkit-transition: none !important;' +
'-moz-transition: none !important;' +
'-o-transition: none !important;' +
'-ms-transition: none !important;' +
'transition: none !important;' +
'}';
document.getElementsByTagName('head')[0].appendChild(style);
}
);
};
browser.addMockModule('disableNgAnimate', disableNgAnimate);
browser.addMockModule('disableCssAnimate', disableCssAnimate);
browser.driver.manage().window().setSize(1600, 1280);
}
};
this is in protractor config
{
"webdriverVersions": {
"selenium": "2.51.0",
"chromedriver": "2.25",
"iedriver": "2.51.0"
}
}
it was not 2.25 i updated but still same.
I changed chrome driver and selenium driver to latest and it worked.
Related
in package.json I used these versions of cucumber and esbuild with cypress:
"cypress-cucumber-preprocessor": {
"stepDefinitions": "cypress/support/step_definitions/**/*.{js,ts}"
},
"devDependencies": {
"#badeball/cypress-cucumber-preprocessor": "^11.5.1",
"#bahmutov/cypress-esbuild-preprocessor": "^2.1.5",
"cypress": "^10.7.0"
},
In cypress.config.js I have:
e2e: {
baseUrl: 'http://localhost:4200',
specPattern: 'cypress/e2e/features',
setupNodeEvents(on, config) {
const createEsbuildPlugin =
require('#badeball/cypress-cucumber-preprocessor/esbuild').createEsbuildPlugin
const createBundler = require('#bahmutov/cypress-esbuild-preprocessor')
require('#badeball/cypress-cucumber-preprocessor').addCucumberPreprocessorPlugin
on('file:preprocessor', createBundler({
plugins: [createEsbuildPlugin(config)],
}));
}
},
Now, this is working fine, no issues. But after I upgraded the cucumber preprocessor to:
"#badeball/cypress-cucumber-preprocessor": "^15.1.2",
and cypress version to 12.3.0
then ran npm install and started cypress test runner, I can't run any test.
After starting the test runner, however I can see all my tests there, but after I click any test, there is an error: Cypress could not detect tests in this file and this:
Error: Build failed with 1 error:
node_modules/common-ancestor-path/index.js:17:37: ERROR: [plugin: feature] Reduce of empty array with no initial value
at failureErrorWithLog (C:\Users\JS\Desktop\test\node_modules\esbuild\lib\main.js:1605:15)
at C:\Users\JS\Desktop\test\node_modules\esbuild\lib\main.js:1251:28
at runOnEndCallbacks (C:\Users\JS\Desktop\test\node_modules\esbuild\lib\main.js:1034:63)
at buildResponseToResult (C:\Users\JS\Desktop\test\node_modules\esbuild\lib\main.js:1249:7)
at C:\Users\JS\Desktop\test\node_modules\esbuild\lib\main.js:1358:14
at C:\Users\JS\Desktop\test\node_modules\esbuild\lib\main.js:666:9
at handleIncomingPacket (C:\Users\JS\Desktop\test\node_modules\esbuild\lib\main.js:763:9)
at Socket.readFromStdout (C:\Users\JS\Desktop\test\node_modules\esbuild\lib\main.js:632:7)
at Socket.emit (node:events:527:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
When I downgrade the cucumber preprocessor and cypress, it is working again. Is there anything I should change in config file or what is the issue?
I tried both versions, "#badeball/cypress-cucumber-preprocessor": "^15.1.2" worked ok but I did have to modify your config in line with the sample on the badeball repo:
awaiting the addCucumberPreprocessorPlugin() call
passing in the on, config params
returning the config at the end of setupNodeEvents()
putting a wildcard into specPattern (could explain test-not-found error)
const { defineConfig } = require("cypress");
module.exports = defineConfig({
e2e: {
// baseUrl: 'http://localhost:4200',
specPattern: "**/*.feature",
// prefix async
async setupNodeEvents(on, config) {
const createEsbuildPlugin = require('#badeball/cypress-cucumber-preprocessor/esbuild').createEsbuildPlugin
const createBundler = require('#bahmutov/cypress-esbuild-preprocessor')
// await here
await require('#badeball/cypress-cucumber-preprocessor').addCucumberPreprocessorPlugin(on, config)
on('file:preprocessor', createBundler({
plugins: [createEsbuildPlugin(config)],
}));
// return any mods to Cypress
return config
}
},
});
So as I still had issues with using esbuild, I replaced it with browserify:
const { defineConfig } = require("cypress");
const preprocessor = require("#badeball/cypress-cucumber-preprocessor");
const browserify = require("#badeball/cypress-cucumber-preprocessor/browserify");
async function setupNodeEvents(on, config) {
await preprocessor.addCucumberPreprocessorPlugin(on, config);
on("file:preprocessor", browserify.default(config));
return config;
}
module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:4200',
specPattern: "**/*.feature",
setupNodeEvents,
},
});
So now the package.json looks like:
"#badeball/cypress-cucumber-preprocessor": "^15.1.2",
"#cypress/browserify-preprocessor": "^3.0.2",
"cypress": "^12.3.0",
I also needed to replace all AND commands in step definitions js files, e.g.:
Before:
import { And, Then } from "#badeball/cypress-cucumber-preprocessor"
And("I select Checkbox", () => {}
Now:
import { When, Then } from "#badeball/cypress-cucumber-preprocessor"
When("I select Checkbox", () => {}
As And should be used in feature files, and in step definitions only When, Then.
With this config the latest cypress works with the latest cucumber and browserify.
So locally my cypress tests run as expected and work fine, but in the cypress cloud they return the following error:
cy.visit() failed trying to load:
/
We failed looking for this file at the path:
/Users/nigel/Documents/portfolio/
The internal Cypress web server responded with:
> 404: Not Found
The tests are written as follows:
describe('Language switcher working', () => {
it('See if the current language is Dutch', () => {
cy.viewport(1496, 1362)
cy.visit('/')
cy.contains('p', 'Ik ben een 2e jaars HBO-ICT Software Engineering student bij de Hogeschool Van Amsterdam.')
})
it('Switch to English', () => {
cy.viewport(1496, 1362)
cy.visit('/')
cy.get('#langSwitcher').select('en')
cy.contains('p', 'I am a second year Software Engineering student at the Amsterdam University of Applied Sciences.')
})
})
The cypress config file has the following content:
import { defineConfig } from "cypress";
export default defineConfig({
projectId: 'gmxneo',
fixturesFolder: "tests/e2e/fixtures",
screenshotsFolder: "tests/e2e/screenshots",
videosFolder: "tests/e2e/videos",
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require("./tests/e2e/plugins/index.js")(on, config);
},
specPattern: "tests/e2e/specs/*.cy.{js,jsx,ts,tsx}",
supportFile: "tests/e2e/support/index.js",
},
component: {
devServer: {
framework: "vue-cli",
bundler: "webpack",
},
},
});
The stacktrace is here:
at <unknown> (http://localhost:54356/__cypress/runner/cypress_runner.js:138231:84) at
visitFailedByErr (http://localhost:54356/__cypress/runner/cypress_runner.js:137639:12) at
<unknown> (http://localhost:54356/__cypress/runner/cypress_runner.js:138214:13) at
tryCatcher (http://localhost:54356/__cypress/runner/cypress_runner.js:8914:23) at
Promise._settlePromiseFromHandler
(http://localhost:54356/__cypress/runner/cypress_runner.js:6849:31) at
Promise._settlePromise (http://localhost:54356/__cypress/runner/cypress_runner.js:6906:18) at Promise._settlePromise0
(http://localhost:54356/__cypress/runner/cypress_runner.js:6951:10) at
Promise._settlePromises (http://localhost:54356/__cypress/runner/cypress_runner.js:7027:18) at
_drainQueueStep (http://localhost:54356/__cypress/runner/cypress_runner.js:3621:12) at
_drainQueue (http://localhost:54356/__cypress/runner/cypress_runner.js:3614:9) at
../../node_modules/bluebird/js/release/async.js.Async._drainQueues
(http://localhost:54356/__cypress/runner/cypress_runner.js:3630:5)
at Async.drainQueues (http://localhost:54356/__cypress/runner/cypress_runner.js:3500:14) From Your Spec Code: at
Context.eval (webpack:///./tests/e2e/specs/changeLang.cy.js:6:7)
I tried looking for other people that have this issue, but I couldn't find anything.
I have tried setting a base URL, but then it just waits for my local server to load up and that wont work if i want to integrate it with github actions i think.
Recently i encounter an issue below, whenever i try to execute protractor tests remotely.
I receive an error message upon execution:
npm run e2e:remote
> hogs#0.1.22 e2e:remote /home/user/projects/project
> ./node_modules/protractor/bin/protractor e2e/protractor.remote.conf.js
[09:34:07] I/launcher - Running 1 instances of WebDriver
[09:34:07] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
Jasmine started
/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5120
return children && children[0].result.status;
^
TypeError: Cannot read property 'result' of undefined
at isAfterAll (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5120:36)
at Suite.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5083:8)
at Suite.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5095:27)
at QueueRunner.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5191:28)
at onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4310:14)
at handleError (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4243:11)
at process.onerror (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:2371:17)
at process.emit (events.js:223:5)
at process.emit (/home/user/projects/project/node_modules/protractor/node_modules/source-map-support/source-map-support.js:439:21)
at process.emit (/home/user/projects/project/node_modules/source-map-support/source-map-support.js:485:21)
Due to the above, i am unable to run tests at all at remote.
my protractor.conf.js:
require('dotenv').config();
const { SpecReporter } = require('jasmine-spec-reporter');
/**
* #type { import("protractor").Config }
*/
exports.config = {
seleniumAddress: process.env.SELENIUM_SERVER_ADDRESS || `http://localhost:4444/wd/hub`,
allScriptsTimeout: 11000,
specs: ['./src/**/*.e2e-spec.ts'],
// directConnect: true,
multiCapabilities: [
{
browserName: 'chrome',
shardTestFiles: false,
maxInstances: 2,
},
//{
// browserName: 'firefox',
//},
],
maxSessions: -1,
baseUrl: process.env.REMOTE_URL || "",
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {},
},
onPrepare() {
process.env.USER_EMAIL = process.env.USER_EMAIL || '';
process.env.USER_PASSWORD = process.env.USER_PASSWORD || '';
require('ts-node').register({
project: 'e2e/tsconfig.json',
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
},
};
Tests run smoothly when i uncomment the directconnect, though in our project we are supposed to run tests through selenium grid, so it is vital that remote runs without it.
Jasmine version is 3.5.0,
Protractor is ver 5.4.3.
I'm new to Protractor.
I'm declaring an element as a variable like :
txtSearch : element(by.xpath('//input[#type="search"]')),
In some point I want to log the locator as :
var clickOn = function(webElement)
{
webElement.click();
console.log("Successfully clicked on the " + webElement);
};
I'm calling this function from Spec file like - clickOn (txtSearch)
In Console.log I am getting like - Successfully clicked on the [object Object].
Please find the required details below :
Node Version: 7.5.0
Protractor Version: 5.1.1
Browser(s): Chrome
Protractor configuration file :
exports.config = {
capabilities: {
browserName: 'chrome',
},
onPrepare: function(){
jasmine.getEnv().addReporter(reporter);
global.isAngularSite = function(flag) {
browser.ignoreSynchronization = !flag;
};
browser.manage().timeouts().setScriptTimeout(60000);
browser.driver.manage().window().maximize();
},
seleniumServerJar: '../../protractor/selenium/selenium-server-standalone-2.52.0.jar',
chromeDriver: '../../protractor/selenium/chromedriver_2.27.exe',
directConnect: true,
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['../PoC_Protractor/spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 600000,
isVerbose: true
}
I tried with webElement.locator().toString() but it is throwing-
Failed: webElement.locator is not a function
You can always output the locator used using webElement.locator().toString(). Check the output for the below code snipper.
Protractor spec:
describe('Locator testing by model', function(){
it('automate user register form', function(){
browser.get('http://www.way2automation.com/angularjs-protractor/registeration/#/login');
var search = element(by.model('Auth.user.name'))
console.log(search.locator())
console.log("Successfully clicked on the " + search.locator().toString());
console.log(search.locator().toString())
});
});
Output:
[14:01:48] I/local - Starting selenium standalone server...
[14:01:48] I/launcher - Running 1 instances of WebDriver
[14:01:49] I/local - Selenium standalone server started at http://10.96.61.119:56341/wd/hub
Started
{ findElementsOverride: [Function], toString: [Function] }
Successfully clicked on the by.model("Auth.user.name")
by.model("Auth.user.name")
.
1 spec, 0 failures
Finished in 0.942 seconds
[14:01:53] I/local - Shutting down selenium standalone server.
[14:01:53] I/launcher - 0 instance(s) of WebDriver still running
[14:01:53] I/launcher - internet explorer #01 passed
Hey it seems like you may not be resolving the promise in the correct way, try using -
webElement.click().then(function(element){
console.log(""Successfully clicked on the " + element);
};
We have tried below steps:
on node command prompt we tried exciting below commands
Npm install -g cucumber
Also we tried
npm install -g protractor-cucumber
cucumber --version
Above command opening webstorm editor.
We have created feature file(feature/testfeature.feature)
Now to generate skeleton we tried running below command on cmd prompt.
Cucumber.js
It is opening webstorm editor
We are not able to see skeleton file
Could you please suggest if we are missing anything
We should be able to create skeleton file using npm command.
Thanks in advance.
If you have to generate Step definitions structure/skeleton in your console you have to run the protractor command
protractor your_conf.js
your conf.js should look like this -
exports.config = {
directConnect: true,
baseUrl: '',
capabilities: {
'browserName':
(process.env.TEST_BROWSER_NAME || 'firefox'),
'version':
(process.env.TEST_BROWSER_VERSION || 'ANY')
},
onPrepare: function () {
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
global.expect = chai.expect;
browser.manage().window().maximize();
},
setDefaultTimeout : 60 * 1000,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
specs: [
'../Features/*.feature'
],
cucumberOpts: {
monochrome: true,
strict: true,
plugin: ["pretty"],
require: ['../StepDefinitions/*.js', '../Support/*.js']
}
};