protractor deprecated getLocationAbsUr - javascript

I am trying to write a code for tasting that I'm redirected to the index.html file using protractor .When I type in terminal protractor protractor.conf.js to execute the e2e tests. it shows me this error :
W/protractor - browser.getLocationAbsUrl() is deprecated, please use browser.getCurrentUrl instead.
Why is that happening?Isn't getLocationAbsUrl Protractor's words?
the code for Configuring Protractor
exports.config = {
allScriptsTimeout: 11000,
specs: [
'e2e/*.js'
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:3000/',
framework: 'jasmine',
directConnect: true,
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
Code for e2e test
'use strict';
describe('conFusion App E2E Testing', function() {
it('should automatically redirect to / when location hash/fragment is empty', function() {
browser.get('index.html');
expect(browser.getLocationAbsUrl()).toMatch("/");
});

As your error said, this function is deprecated. It means the use of this code is now discouraged. You should use getCurrentUrl().
From Protractor's Github:
browser.getLocationAbsUrl() is now deprecated, you should use
browser.getCurrentUrl() instead.

Related

Protractor / Jasmine timing out on headless chromium - Error: Timeout - Async callback

Hi all so I am trying to run headless chromium with protractor and jasmine. I have everything setup and working for both firefox and chrome with a head. When I run firefox headless it works... when I try running chromium headless it ends up timing out. Looking for some help to solve this problem.
The error I get is :
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Now I've read a million article online and have tried increasing the timeout time and adding done into the function as well...
Here is my current code:
Conf.js - this has a bunch of added args and settings that I've found online. I've tried pretty much every variation and had no success..
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
allScriptsTimeout: 5000000,
capabilities: {
'directConnect': true,
'browserName': 'chrome',
"goog:chromeOptions": {
args: ["--headless", "--remote-debugging-port=9222", "--verbose", "--disable-gpu", "--disable-web-security", "--window-size=800x600"],
'binary': "/usr/bin/chromium-browser"
}
}
};
Spec.js - straight off of their website with console.logs. All of the console.logs print out in the following order 3,1,2. This is something I'm unsure is correct? Should the describe be waiting for the it to finish? It almost feels like my it is never returning...
describe('angularjs homepage todo list', function() {
it('should add a todo', function(done) {
console.log("WOOO1");
browser.get('https://angularjs.org');
element(by.model('todoList.todoText')).sendKeys('write first protractor test');
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write first protractor test');
// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click();
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);
console.log("WOO2");
}, 15000);
console.log("WOO3");
});
Following this some other discoveries I have found... when I go to the localhost:9222 I see
Inspectable WebContents
data:text/html,<html></html>
The data:text/html,<html></html> is a link and if clicked on takes me to the remote chrome debugger that is loading ... data:text/html,. This is where I think the problem is. Why is this never actually loading the angular site?
Maybe I'm off base but does anyone know how to make sense of this?
EDIT:
Additional useful information.
I am using
chromium 79.0.3945.130
chromedriver 79.0.3945.36
jasmine v3.5.0
jasmine-core v3.5.0
Protractor 5.4.3
Thanks
Config that ended up working for me
exports.config = {
framework: 'jasmine',
allScriptsTimeout: 9000,
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
capabilities: {
'directConnect': true,
'browserName': 'chrome',
"goog:chromeOptions": {
args: ["--headless", "--remote-debugging-port=9222", "--verbose", "--disable-gpu", "--disable-web-security", "--window-size=800x600"],
'binary': "path to chrome"
}
}
};
add allScriptTimeOut in your configuration like this:
exports.config = {
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
specs: ['example_spec.js'],
allScriptsTimeout: 9000
};
hope this link will help you
https://www.protractortest.org/#/timeouts.

Can I Make the `seleniumAddress` field in protractor.config.js take parameters?

I have a Windows box and an Ubuntu box which I run my automated tests on. Currently, in my protractor.config.js file I have two seleniumAddress fields under my multiCapabilities: [{}] section and just comment out one or the other depending on which environment I would like to run in.
Is there a way to parameterize the seleniumAddress: so I can tell from my command line which environment to run in?
Something like this: gulp e2e --suite <suiteName> --baseUrl <URL>
--environment Windows
Here is my current multiCapabilities section from my protractor conf file:
multiCapabilities: [{
browserName: 'chrome',
// seleniumAddress: "URL to webdriver-manager Windows Box",
seleniumAddress: "URL to webdriver-manager Ubuntu Box",
platform: 'ANY',
version: 'ANY',
chromeOptions: {
args: ['--no-sandbox', '--test-type=browser', '--lang=en', '--window-size=1680,1050'],
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
},
download: {
prompt_for_download: false,
directory_upgrade: true,
default_directory: 'C:\\downloads\\'
},
},
}
// shardTestFiles: true,
// maxInstances: 2
}],
Protractor is run on Node.js, so you should be able to pass an argument (a little more complicated), or easier, set an environmental variable:
Protractor conf snippet from the Protractor website with environmental variable logic added:
// Use the Windows selenium if the environmental variable IS_WINDOWS is set.
const seleniumServer = process.env.IS_WINDOWS ?
'https://path/to/windows-silenium' : 'https://path-to-default-selenium';
exports.config = {
// The address of a running selenium server.
seleniumAddress: seleniumServer,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to the configuration file location passed
// to protractor (in this example conf.js).
// They may include glob patterns.
specs: ['example-spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
}
};
I'm not quite sure what you would want to choose from (and I don't use gulp), but for the snippet above, you would probably use:
IS_WINDOWS=true gulp e2e --suite <suiteName> --baseUrl <URL>

'Path must be a string' error after execute a cucumber feature

I'm working in the implementation of cucumber with protractor I already have the conf.js file:
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'firefox'
},
specs: './features/login.feature',
onPrepare: function(){
browser.driver.manage().window().maximize()
browser.get('http:www.google.com')
},
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
},
cucumberOpts: {
require: 'features/steps/my_steps.js',
}
};
This is my step file that just contain a console.log:
module.exports = function(){
this.Given(/Display something/, function () {
console.log('Hi');
});
}
and this is the feature:
Feature: Running Cucumber with Protractor
Scenario: Protractor and Cucumber Test
Given Display something
but every time that I execute with the command
protractor conf.js
i'm getting this error:
Unhandled rejection VError: a handler errored, process exiting: PrettyFormatter::handleFeaturesResult: Path must be a string. Received undefined
i'm not sure if I have problems in the conf.js or the command is not the right to execute.
I hope you can help me.
This works for me:
in the conf.js in the cucumberOpts: I add this:
cucumberOpts: {
require: 'features/steps/my_steps.js',
format: 'pretty',
tags:'false'
}
So for me is working now I hope this is a solution for you guys.

Protractor + Hybrid Angular 1+2 Application = Fail

Protractor works well on Angular 1 but after upgrading my app to an hybrid Angular 1+2 I get this error:
Failed: Error while waiting for Protractor to sync with the page:
"[ng:test] no injector found for element argument to getTestability
http://errors.angularjs.org/1.4.9/ng/test"
It seems a common error when you don't have a ng-app tag <div ng-app=myAppManager"> in your Angular 1 app and can be easily fixed wiyh rootElement : 'html' in your protractor config file but it doesn't seem to change anything on hybrid app.
I tried rootElement : 'html' or even useAllAngular2AppRoots: true.
I suspect the problem comes from the asynchronous loading of the hybrid angular (from the upgrade doc):
One notable difference between angular.bootstrap and
upgradeAdapter.bootstrap is that the latter works asynchronously. This
means that we cannot assume that the application has been instantiated
immediately after the bootstrap call returns.
my config file:
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['protractor.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 50000,
},
allScriptsTimeout: 50000,//seb
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'prefs': {
'profile.managed_default_content_settings.notifications':2
}
}
},
rootElement : 'html',
// useAllAngular2AppRoots: true,
jasmineNodeOpts: {
realtimeFailure: true
},
onPrepare: function() {
var failFast = require('jasmine-fail-fast');
jasmine.getEnv().addReporter(failFast.init());
}
}
Protractor team has fixed with this:
https://github.com/angular/angular/pull/7603
Edit: I haven't tested it yet
Edit 2: Doesn't seem to work, I went back to angularJs (version 1)
Edit 3: I moved to React

Running protractor config results 'This webpage is not available'

I'm trying to test protractor on a vanilla.js app and when I run protractor basicConf.js
I am getting below error :
This webpage is not available ERR_CONNECTION_REFUSED
This is my test:
describe('foo', function() {
beforeEach(function() {
browser.get('index.html');
});
it('should return the same result as browser.findElement', function() {
$('#newItem').sendKeys('sdg');
element('#addBtn').click().then(function(){
});
});
})
And my protractor config:
// The main suite of Protractor tests.
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine2',
// Spec patterns are relative to this directory.
specs: [
'spec.js'
],
// Exclude patterns are relative to this directory.
exclude: [
'basic/exclude*.js'
],
capabilities: {'browserName': 'chrome'},
baseUrl: 'http://localhost:' + ( '8082'),
jasmineNodeOpts: {
isVerbose: true,
realtimeFailure: true
},
params: {
login: {
user: 'Jane',
password: '1234'
}
}
};
Any ideas what I need to do to start fixing this?
I have run both:
protactor npm install -g protractor
webdriver webdriver-manager update
Error connection gets refused if either the webdriver server isn't started or there is a configuration compatibility issue with your protractor and browser. Looking at your config file and config data, there is no such issue. However, you should start your webdriver before running your tests. Open a command prompt in windows or terminal in mac and then run the following command to start the selenium webdriver -
webdriver-manager start
Later run your protractor scripts with the command that you already have. Hope this helps.
Looking over your test I believe the issue originates from the address that you are passing to the browser.get() function. You'll want to either reference the baseUrl you setup in the config file and append the "index.html" piece in your test or adjust the baseUrl and reference that in your beforeEach function. Try one of the following:
...
baseUrl: 'http://localhost:8082',
...
browser.get(browser.baseUrl + '/index.html');
or
...
baseUrl: 'http://localhost:8082/',
...
browser.get(browser.baseUrl);
or
browser.get('http://localhost:8082/index.html');
Also you could try this:
...
baseUrl: 'http://localhost:8082/index.html');
...
browser.get(browser.baseUrl);

Categories

Resources