How can I get use phantomjs in my protractor test? - angularjs

I am trying to use phantomjs without success :(
Using this sample as a testcase:
https://github.com/angular/protractor/blob/master/docs/page-objects.md
my protractor.conf.js looks like this:
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'phantomjs'
},
// Spec patterns are relative to the location of the spec file. They may
// include glob patterns.
suites: {
homepage: '*.spec.js',
search: ['tests/e2e/contact_search/**/*Spec.js',
'tests/e2e/venue_search/**/*Spec.js']
},
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
isVerbose:true,
includeStackTrace: true
}
,
specs: ['example_spec.js']
};
when I run this I get:
"C:\Program Files (x86)\JetBrains\WebStorm 8.0.4\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" c:\Users\harry.redknapp\AppData\Roaming\npm\node_modules\protractor\lib\cli.js protractor.conf.js
Using the selenium server at http://localhost:4444/wd/hub
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
The last active task was:
WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (c:\Users\harry.redknapp\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:148:22)
at Function.webdriver.WebDriver.createSession (c:\Users\harry.redknapp\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:122:30)
at Builder.build (c:\Users\harry.redknapp\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\builder.js:293:22)
at HostedDriverProvider.getDriver (c:\Users\harry.redknapp\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\hosted.js:63:9)
at c:\Users\harry.redknapp\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:238:41
at _fulfilled (c:\Users\harry.redknapp\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:797:54)
at self.promiseDispatch.done (c:\Users\harry.redknapp\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:826:30)
at Promise.promise.promiseDispatch (c:\Users\harry.redknapp\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:759:13)
at c:\Users\harry.redknapp\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:573:44
How can I get phantomjs working?

Related

Protractor acting randomly or occasionally not starting

I've been tasked with writing different suites of tests and tasks automation but Protractor has been acting in a very strange way the past couple days and... I just don't recall having changed anything from the last time my suites ran correctly.
Currently using the latest drivers:
% ./node_modules/webdriver-manager/bin/webdriver-manager status
webdriver-manager: using local installed version 12.1.0
[09:14:25] I/status - selenium standalone version available: 3.13.0 [last]
[09:14:25] I/status - chromedriver version available: 2.40 [last]
[09:14:25] I/status - geckodriver version available: v0.21.0 [last]
[09:14:25] I/status - android-sdk is not present
[09:14:25] I/status - appium is not present
And what appears to be the latest Protractor version:
% ./node_modules/protractor/bin/protractor --version
Version 5.3.2
This is what Protractor's output looks like 80% of the time, when it doesn't run:
% ./node_modules/protractor/bin/protractor ./conf.js --suite scenarios --params.login.usr=$USR_E2E --params.login.pwd=$PWD_E2E --params.env=test
(node:1709) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[09:03:07] W/driverProviders - Using driver provider hosted, but also found extra driver provider parameter(s): seleniumServerJar
[09:03:07] I/launcher - Running 1 instances of WebDriver
[09:03:07] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[09:03:08] E/launcher - Error: NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":"[type="email"]"}
(Session info: headless chrome=67.0.3396.99)
(Driver info: chromedriver=2.40.565386 (45a059dc425e08165f9a10324bd1380cc13ca363),platform=Mac OS X 10.14.0 x86_64)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
[09:03:08] E/launcher - Process exited with error code 100
The corresponding webdriver-manager's output:
% ./node_modules/webdriver-manager/bin/webdriver-manager start
webdriver-manager: using local installed version 12.1.0
[09:30:49] I/start - java -Dwebdriver.chrome.driver=/Users/cyril/Projects/parkopoly_e2e/node_modules/webdriver-manager/selenium/chromedriver_2.40 -Dwebdriver.gecko.driver=/Users/cyril/Projects/parkopoly_e2e/node_modules/webdriver-manager/selenium/geckodriver-v0.21.0 -jar /Users/cyril/Projects/parkopoly_e2e/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.13.0.jar -port 4444
[09:30:49] I/start - seleniumProcess.pid: 1791
09:30:49.534 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.13.0', revision: '2f0d292'
09:30:49.535 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
2018-07-16 09:30:49.613:INFO::main: Logging initialized #282ms to org.seleniumhq.jetty9.util.log.StdErrLog
09:30:49.752 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
09:30:55.414 INFO [ActiveSessionFactory.apply] - Capabilities are: {
"browserName": "chrome",
"chromeOptions": {
"args": [
"--disable-extensions",
"--show-fps-counter=true",
"--disable-infobars",
"--incognito",
"--disable-gpu",
"--headless"
]
},
"count": 1
}
09:30:55.415 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 2.40.565386 (45a059dc425e08165f9a10324bd1380cc13ca363) on port 24866
Only local connections are allowed.
09:30:55.951 INFO [ProtocolHandshake.createSession] - Detected dialect: OSS
09:30:56.171 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 9ea12201cba04ac9e41639501f0c02e1 (org.openqa.selenium.chrome.ChromeDriverService)
09:30:56.925 INFO [ActiveSessions$1.onStop] - Removing session 9ea12201cba04ac9e41639501f0c02e1 (org.openqa.selenium.chrome.ChromeDriverService)
Here's the conf.js file I'm currently using:
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
exports.config = {
SELENIUM_PROMISE_MANAGER: false,
rootElement: 'html',
seleniumServerJar: './bin/selenium-server-standalone-3.12.0.jar',
seleniumPort: '4444',
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine2',
directConnect: false,
specs: ['./e2e/**/*.spec.js'],
suites: {
cft: './e2e/cft/**/*.spec.js',
scenarios: './e2e/scenarios/**/*.scenario.js'
},
jasmineNodeOpts: {
isVerbose: true,
defaultTimeoutInterval: 15000,
print: function() {}
},
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--disable-extensions', '--show-fps-counter=true', '--disable-infobars', '--incognito', '--disable-gpu', '--headless']
}
},
onPrepare: async function() {
browser.params.ts = Date.now();
if (browser.params.env === undefined)
browser.params.env = 'test';
await jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStackTrace: true,
displaySuccessful: true,
displayFailed: true,
displayPending: true,
displaySpecDuration: true,
displaySuiteNumber: true
},
summary: {
displayFailures: true,
displayPending: false
},
colors: {
enabled: true,
successful: 'green',
failed: 'red',
pending: 'yellow'
}
}));
await browser.get('https://dashboard-' + browser.params.env + '.website.com');
await browser.driver.findElement(by.css('[type="email"]')).sendKeys(browser.params.login.usr);
await browser.driver.findElement(by.css('[type="password"]')).sendKeys(browser.params.login.pwd);
await browser.driver.findElement(by.css('[type="submit"]')).click();
return await browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return /calendar_bo/.test(url);
});
}, 10000);
}
};
Sometimes, whenever Protractor starts and launch the tests, it just suffers from race conditions.
I couldn't find any thread, post, comment or anyone that ever had such outputs. I'm running out of ideas and I'd appreciate any ideas or potential solutions. Thanks!
Have not enough reputation to comment..
Could it be that you have a seleniumServerJar AND a seleniumAddress configured at the same time? Documentation specifies to use only 1.
Protractor needs to know how to connect to Drivers for the browsers it
is testing on. This is usually done through a Selenium Server.
There are five options - specify one of the following:
seleniumServerJar - to start a standalone Selenium Server locally.
seleniumAddress - to connect to a Selenium Server which is already running.
sauceUser/sauceKey - to use remote Selenium Servers via Sauce Labs.
browserstackUser/browserstackKey - to use remote Selenium Servers via BrowserStack.
directConnect - to connect directly to the browser Drivers. This option is only available for Firefox and Chrome.
can you try this code before email send keys:
var EC = protractor.ExpectedConditions;
var email_element = element(by.css('[type="email"]'));
browser.wait(EC.visibilityOf(email_element), 10000);

Protractor, internet explorer stops at "initial start page for the WebDriver server."

I have successfully created and executed test suites in Protractor for Chrome and Firefox. However I am unable to run tests with Internet Explorer. It stops at "initial start page for the WebDriver server" and displays this error in the powershell:
[11:02:10] I/launcher - Running 1 instances of WebDriver
[11:02:10] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[11:02:46] E/launcher -
[11:02:46] E/launcher - WebDriverError
at WebDriverError (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:27:5)
at parseHttpResponse (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:521:11)
at doSend.then.response (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:440:13)
at process._tickCallback (internal/process/next_tick.js:109:7)
From: Task: WebDriver.createSession()
at Function.createSession (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:777:24)
at createDriver (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:167:33)
at Builder.build (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:632:14)
at Hosted.getNewDriver (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\driverProvider.ts:60:29)
at Runner.createBrowser (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\lib\runner.ts:225:39)
at q.then.then (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\lib\runner.ts:391:27)
at _fulfilled (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:796:13)
at C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:556:49
[11:02:46] E/launcher - Process exited with error code 199
This is my protractor config:
// Protractor configuration file
exports.config = {
seleniumAddress: "http://localhost:4444/wd/hub",
multiCapabilities: [
//{ browserName: "chrome" },
{
browserName: 'internet explorer',
}
//{ browserName: "firefox" }
],
framework: "jasmine2",
jasmineNodeOpts: {
defaultTimeoutInterval: 2500000,
showColors: true, // Use colors in the command line report.
isVerbose: true,
includeStackTrace: true
},
specs: [
"specs/login-spec.js",
],
resultJsonOutputFile: "./Report.json",
};
I read tens of posts on StackOverflow but didn't find any solusion to my problem. I have tried to change IE settings but they always go back to its defaults due to corporation setup.
The error stacktrace doesn't give my much information on what's wrong actually. I'm not very familiar with WebDriver source.
Any suggestions? Did anyone face similar problem?

Protractor tests are not running in firefox with directconnect true

config file
I am unable to run my test in firefox with directconnect true. Please provide a solution
Versions:
Angular: 4
Protractor: 5.1.2
Selenium Standalone Server: 3.4.0
GeckoDriver: 0.18.0
Firefox Browser: 54.0
I modified your configuration file and use it as given below
exports.config =
{
framework: 'jasmine',
directConnect:true,
specs: ['spec4.js'],
capabilities: {
browserName: 'firefox',
}
};

Protractor seleniumServerJar sets selenium address to http://192.168.0.20:<random-port>

I'm trying to have Protractor start the standalone Selenium Server by setting the seleniumServerJar path according to this github issue, but it starts the selenium server on a different address and port than if you start it with java -jar or with ./node_modules/protractor/bin/webdrivermanager start.
Starting with java -jar /path/to/jar output:
$ java -jar selenium-server-standalone-2.42.2.jar Jun 23, 2014
10:28:25 PM org.openqa.grid.selenium.GridLauncher main INFO: Launching
a standalone server 22:28:25.082 INFO - Java: Apple Inc. 20.65-b04-462
22:28:25.082 INFO - OS: Mac OS X 10.9.3 x86_64 22:28:25.092 INFO -
v2.42.2, with Core v2.42.2. Built from revision 6a6995d 22:28:25.146
INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver
registration is skipped: registration capabilities Capabilities
[{platform=WINDOWS, ensureCleanSession=true, browserName=internet
explorer, version=}] does not match with current platform: MAC
22:28:25.197 INFO - RemoteWebDriver instances should connect to:
http://127.0.0.1:4444/wd/hub 22:28:25.198 INFO - Version Jetty/5.1.x
22:28:25.199 INFO - Started
HttpContext[/selenium-server/driver,/selenium-server/driver]
22:28:25.199 INFO - Started
HttpContext[/selenium-server,/selenium-server] 22:28:25.199 INFO -
Started HttpContext[/,/] 22:28:25.235 INFO - Started
org.openqa.jetty.jetty.servlet.ServletHandler#7786df0f 22:28:25.235
INFO - Started HttpContext[/wd,/wd] 22:28:25.240 INFO - Started
SocketListener on 0.0.0.0:4444 22:28:25.240 INFO - Started
org.openqa.jetty.jetty.Server#42698403
Starting it with Protractor by specifying seleniumServerJar:
$ ./node_modules/protractor/bin/protractor protractor_conf.js Starting
selenium standalone server... Selenium standalone server started at
http://192.168.0.20:59959/wd/hub
And then it hangs and times out.
How does one properly start the standalone selenium server when specifying seleniumServerJar?
Side note: I have put the selenium-server.jar file in my project to make it easy to use relative paths according to aformentioned github issue.
My protractor_conf.js:
exports.config = {
// Do not start a Selenium Standalone sever - only run this using chrome.
//chromeOnly: true,
//chromeDriver: '../node_modules/protractor/selenium/chromedriver',
//we are using a standalone selenium server so give it the local address
//seleniumAddress: 'http://0.0.0.0:4444/wd/hub',
seleniumServerJar: './selenium-server-standalone-2.42.2.jar',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'phantomjs'
},
baseUrl: 'http://localhost:8000',
onPrepare: function () {
require('jasmine-reporters');
var capsPromise = browser.getCapabilities();
capsPromise.then(function (caps) {
var browserName = caps.caps_.browserName.toUpperCase();
var browserVersion = caps.caps_.version;
var prePendStr = browserName + '-' + browserVersion + '-';
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('test-results/protractor/', true, true, prePendStr));
});
},
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['test/protractor/**/*_spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
isVerbose: true,
defaultTimeoutInterval: 30000
},
params: {
env: 'test'
}
};
192.168.0.20 is your local ip address and the port should be 4444 by default, you can change the port with
seleniumPort: 1234
inside your protractor_conf.js (btw: protractor.conf.js is the default config file name for protractor)

Angular Karma e2e with Grunt

I am trying to test
In the grunt file
karma: {
e2e: {
configFile: 'karma-e2e.conf.js',
singleRun: true
}
},
Karma file is basically what Yeoman generated for me. Only change is I swithed Chrome for PhantomJS.
karma-e2e.conf.js:
// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['ng-scenario'],
// list of files / patterns to load in the browser
files: [
'test/e2e/**/*.js'
],
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
// '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
});
};
I have a very basic test I try to run
describe('E2E: Testing Routes:', function () {
'use strict';
beforeEach(function() {
browser().navigateTo('/');
});
it('test', function() {
browser().navigateTo('#/');
expect(browser().location().path()).toBe("/list_persons");
});
})
This is the output from the test. I googled this error and it suggested that I add a "sleep" in my test. That does not sound like a solution for me.
> Running "karma:e2e" (karma) task
INFO [karma]: Karma v0.12.0 server started at http://local:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket i0eExVxerWfwrirxJXue with id 46269744
PhantomJS 1.9.7 (Linux): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
PhantomJS 1.9.7 (Linux) E2E: Testing Routes: should jump to the /videos path when / is accessed FAILED
TypeError: 'undefined' is not a function (evaluating '$document.injector()')
PhantomJS 1.9.7 (Linux): Executed 1 of 1 (1 FAILED) ERROR (0.068 secs / 0.077 secs)
Warning: Task "karma:e2e" failed. Use --force to continue.
Can anyone help me. What I want to do is to run e2e tests from grunt in PhantomJS.It does not have to be on a listener for filechanges. One simple run on "grunt test" is perfect.
Edit: I changed files to include
files: [
'app/vendor/scripts/angular.js',
'app/vendor/scripts/angular-mocks.js',
'app/vendor/scripts/angular-route.js',
'app/vendor/scripts/jstd-scenario-adapter-config.js',
'app/vendor/scripts/jstd-scenario-adapter.js',
'app/vendor/scripts/angular-scenario.js',
'test/e2e/**/*.js'
],
Now getting this:
Running "karma:e2e" (karma) task
INFO [karma]: Karma v0.12.0 server started at http://localhost:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket ZbZbabDGNCtvVa4Z-LQk with id 99494524
PhantomJS 1.9.7 (Linux): Executed 0 of 0 ERROR (0.036 secs / 0 secs)
Warning: Task "karma:e2e" failed. Use --force to continue.
You have to add this:
singleRun: true,
To your karma config section in your grunt file.
Details:
https://github.com/karma-runner/grunt-karma

Resources