Unable to print the locator (webelement) in Console Log - jasmine

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

Related

In e2e testing, blank page is opened in Chromium Edge (New Edge Browser) using Protractor

1.Open the MS Chromium edge and type the command "edge://settings/help" to check the version
2. Download the MS Chromium edge webdriver and placed it into project directory
3. Set the desired capabilities in conf.js file
4. Start the server using command "webdriver-manager start --edge msedgedriver.exe"
5. Run the test using the "protractor conf.js"
Environment:
Chromium Edge Version = 83.0.478.37
Chromium web driver = 83.0.478.37
Selenium server version = 3.141.59
JDK =1.8.191
conf.js
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome',
'goog:chromeOptions': {
// Faked out chrome binary
'binary':'C:\\Program Files (x86)\\Microsoft\\Edge Beta\\Application\\msedge.exe'
}
},
//Path of Chromium edge driver
chromeDriver:'./msedgedriver.exe',
specs: ['spec.js'],
}
};
Also tried with using desired capabilities in spec.js file as well but still blank page is opened
describe('slow calculator', function() {
beforeEach(function() {
let options = new edge.Options();
options.setEdgeChromium(true);
//options.setBinaryPath("C:\\Program Files (x86)\\Microsoft\\Edge Beta\\Application\\msedge.exe");
let browser = edge.Driver.createSession(options);
browser.get('http://juliemr.github.io/protractor-demo/');
});
});
While starting webdriver-manager, ensure the path to msedgedriver is specified.
webdriver-manager start --edge "pathToEdgeDriver/msedgedriver.exe"
The capabilities object should have MicrosoftEdge as browserName.
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'MicrosoftEdge'
}

Protractor - jasmine TypeError: cannot read property 'result' of undefined

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.

Common tests are excluded in suite configuration of protractor

I could see the common tests are excluded in a suite configuration of protractor. Below is my config.js and there are two scenarios configured in suites.
I'm expecting the test to complete the scenario1 successfully and then Login again as part of scenario2. But, I could see the test ignores 'Login.js', 'CustomerSelection.js', 'Create.js' of Scenario2 and directly proceeds with 'ProductSelection.js'.
Any idea why is that so ? Am I missing anything in conf.js to work the way the scenarios configured ?
Config.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine' ,
showColors: true,
suites : {
scenario1: [
'Login.js',
'CustomerSelection.js',
'Create.js',
'View.js',
],
scenario2: [
'Login.js',
'CustomerSelection.js',
'Create.js',
'ProductSelection.js',
]
},
jasmineNodeOpts: {
isVerbose: true,
showColors: true,
print: function () {
},
includeStackTrace: true,
defaultTimeoutInterval: 700000
},
onPrepare: function() {
browser.manage().window().maximize();
browser.manage().timeouts().implicitlyWait(5000);
}
};
Below are the versions I'm using:
protractor: Version 5.4.0
Jasmine: Version 3.2.0
Node: v8.11.1
NPM: Version 5.6.0
If this tests are something that you run always before all. You can place them like this into View.js and ProductSelection.js as part of beforeAll, I'm placing login beforeAll (loginPage is page where my functions are placed, Login() is function in loginPage that logins in application if you send correct username and password to it) like this:
beforeAll(function() {
loginPage.Login(username, password);
});

Protractor error selenium spring boot

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.

Can not load "teamcity", it is not registered! Perhaps you are missing some plugin?

I'm trying to run my karma (version v0.10.2) unit tests on teamcity (version 7.1).
When I run karma start --reporters teamcity --single-run I get the following error:
Can not load "teamcity", it is not registered! Perhaps you are missing some plugin?
I have installed the karma-teamcity-reporter module, but that hasn't helped.
The following are installed in my local node_modules folder:
karma
karma-chrome-launcher
karma-coffee-preprocessor
karma-coverage
karma-firefox-launcher
karma-html2js-preprocessor
karma-jasmine
karma-phantomjs-launcher
karma-requirejs
karma-script-launcher
karma-teamcity-reporter
Here is my karma.conf.js:
I'm running karma version v0.10.2. Here's my karma.conf.js:
module.exports = function(karma) {
karma.set({
// base path, that will be used to resolve files and exclude
basePath: '../../myapplication.web',
frameworks: ['jasmine'],
plugins: [
'karma-jasmine',
'karma-coverage',
'karma-chrome-launcher',
'karma-phantomjs-launcher'
],
// list of files / patterns to load in the browser
files: [
'Scripts/jquery/jquery-2.0.2.min.js',
'Scripts/jquery-ui/jquery-ui-1.10.3.min.js',
'Scripts/daterangepicker/daterangepicker.js',
'Scripts/angular/angular.js',
'Scripts/angular/restangular/underscore-min.js',
'Scripts/angular/restangular/restangular-min.js',
'Scripts/angular/angular-*.js',
'Scripts/angular/angular-test/angular-*.js',
'Scripts/angular/angular-ui/*.js',
'Scripts/angular/angular-strap/*.js',
'Scripts/angular/angular-http-auth/*.js',
'Scripts/sinon/*.js',
'Scripts/moment/moment.min.js',
'uifw/scripts/ui-framework-angular.js',
'app/app.js',
'app/**/*.js',
'Tests/unit/**/*.js'
],
// list of files to exclude
exclude: [
'Scripts/angular/angular-test/angular-scenario.js'
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters: ['progress', 'coverage', 'teamcity'],
preprocessors : {
'app/**/*.js': ['coverage']
},
coverageReporter : {
type: 'html',
dir: 'Tests/coverage/'
},
// web server port
port : 9876,
// cli runner port
runnerPort : 9100,
// enable / disable colors in the output (reporters and logs)
colors : true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel : karma.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch : true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout : 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun : true
});
};
If I run karma start karma.conf.js it runs correctly. What am I doing wrong?
Turned out I needed to add karma-teamcity-reporter to the plugins section to get this to work:
...
plugins: [
'karma-teamcity-reporter',
'karma-jasmine',
'karma-coverage',
'karma-chrome-launcher',
'karma-phantomjs-launcher'
],
...

Resources