Test browser code with Intern through Grunt and Phantomjs - phantomjs

I have been playing with Intern and made my tests work in the browser. To better integrate with my current workflow I'm trying to run my tests through grunt with phantomjs. However all my attempts have failed. I've been looking at this question as a reference Intern WebDriver and PhantomJS but can't figure out all of the steps to make it work.
First of all: Is it even possible to run the tests through grunt and phantomjs?
A little bit of info:
I don't want/can't connect to Sauce Labs or a Selenium testing environment.
I want to test browser code while having jQuery as a shimmed dependency
I have Grunt 0.4.1 and phantomjs 1.9.1 installed
I'm not testing any ajax request (as the linked question is having problem with)
I'm not familiar with neither Selenium nor Sauce Lab
If it is possible to test through grunt and phanomjs, how would I go about doing it?
I guess that I have to start the GhostDriver
phantomjs --webdriver=8910
But then what are the important pieces of info in the Intern config to make this work?
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
environments: [
{
browserName: 'phantom',
version: '1.9.0',
platform: 'Linux'
}
],
webdriver: {
host: 'localhost',
port: 8910
},
maxConcurrency: 3,
useSauceConnect: false,
// ...
});
How does the environments browserName map to phantomjs? I've tried the browserNames 'phantom' as well as 'phanomjs' with different versions and platforms (running Mac 10.7)
My Gruntfile section for intern looks like:
intern: {
phantom: {
options: {
config: 'tests/intern',
reporters: ['webdriver']
}
}
}
Running this setup without any test-suite that includes browser code outputs
'ReferenceError: document is not defined' in 'node_modules/intern/lib/reporters/webdriver.js:41:19'
Adding browser tests gives 'ReferenceError: window is not defined' in 'src/vendor/jquery/jquery-1.9.1.js:9597:5'
Running it through node gives the same 'window is not defined' error.
node node_modules/intern/client.js config=tests/intern
What am I doing wrong/missing here?

There are two problems with your Gruntfile configuration:
The default run type for the Grunt task is 'client', which means it runs the Node.js client by default, not the test runner. You need to set runType: 'runner' in your Gruntfile options to run tests against your specified environments.
The webdriver reporter is for use in a browser client only and is specified automatically by the test runner when it is needed. You should typically never use it directly. The reporter you specify in the Gruntfile should be the one you want the test runner to use; the console default is usually appropriate.
These two things in combination mean that you’ve configured Intern to try to use a reporter that only works in a browser in conjunction with the test runner inside the Node.js client, hence the error. Once corrected, the remaining configuration should work properly to run on PhantomJS, assuming it is already running on localhost at port 8910.

Related

Test VueJs localization using Nightwatch

I have an application that I started in English from scratch. I had nightwatch tests and everything is working perfectly fine... but after adding 2 more languages, I want the main tests to run as they used to in English, then change the browser language (since that's the criteria on which I choose the language) so I can run the other tests in German or French... etc. Is there a way to start a test suite by changing the browser's language?
I looked into the documentation and found nothing in this area
In order to set the language and run the tests locally, I did the following:
chrome: {
desiredCapabilities: {
chromeOptions: {
prefs: {
intl: { accept_languages: "ss-ZA" }
}, args: []
}
}
}
this allows you to run the tests locally, on only that language. or you can manage setting that locale code to a variable in a way and try setting it at the beginning of your test suite.
I did not get that far, because in my case, I have to run my tests headless because they will run later on a remote git server that runs only headless tests. According to this issue on Nightwatch's github page, setting a browser language parameter for a headless test is not possible!

ERROR:process_metrics.cc(105)] NOT IMPLEMENTED [duplicate]

Recently, we've started to get these kind of warnings on the console when running Protractor tests:
[12252:14584:1207/223118.187:ERROR:process_metrics.cc(105)] NOT IMPLEMENTED
[12252:14584:1207/223118.187:ERROR:process_metrics.cc(105)] NOT IMPLEMENTED
[12252:14584:1207/223318.188:ERROR:process_metrics.cc(105)] NOT IMPLEMENTED
It feels like they happen randomly but doesn't affect the test execution.
The only problem is that they pollute the output console making it more difficult to keep track of tests being executed and test results reported by jasmine/protractor.
Is there a way to turn off this kind of chromedriver warnings?
Using Protractor 5.2.2, ChromeDriver 2.34.
We've found this --silent flag that can be passed to chromedriver executable, but could not find a way to configure protractor to pass this flag when launching chromedriver..
It seems to be an issue with chrome v63
https://github.com/SeleniumHQ/selenium/issues/5189#issuecomment-351605839
You should be able to pass the --silent flag to chromedriver in your conf file. Something like:
capabilities: {
browserName' : 'chrome',
'chromeOptions' : {
args: ['--silent']
}
}
}
"This warning message was generated by a bug in Chrome v63.
Upgrading to v64 (64.0.3282.167 as of this morning) resolves it."

Selenium doesn't start webdriver

versions
"nightwatch": "^0.9.16"
"chromedriver": "^2.30.1"
"selenium-server-standalone-jar": "^3.4.0"
I'm using nightwatch but that sh
I also tried with
I'm using nightwatch to run Selenium in this repo and I've tried with chrome and firefox drivers, no luck on either.
I have selenium standalone and chromedriver packages, and I know the path is right on nightwatch.conf.js:
const jar = require('selenium-server-standalone-jar')
console.log(jar.path) // logs /home/goldylucks/apps/ci-workshop/node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.4.0.jar
const chromedriver = require('chromedriver')
console.log(chromedriver.path) // logs /home/goldylucks/apps/ci-workshop/node_modules/chromedriver/lib/chromedriver/chromedriver
'selenium': {
'start_process': true,
'server_path': jar.path,
'log_path': '',
'port': 4444,
'cli_args': {
'webdriver.chrome.driver': chromedriver.path,
'webdriver.ie.driver': '',
},
},
'test_settings': {
'chrome': {
'desiredCapabilities': {
'browserName': 'chrome',
'javascriptEnabled': true,
'acceptSslCerts': true,
},
},
yet when I run the test it times out and hangs:
$ yarn e2e:ui
yarn e2e:ui v0.24.6
$ nightwatch -e chrome
Starting selenium server... started - PID: 12936
[App E2e Ui] Test Suite
===========================
✖ Timed out while waiting for element <body> to be present for 5000 milliseconds. - expected "visible" but got: "not found"
at Object.before (/home/goldylucks/apps/ci-workshop/test/ui/app.e2e-ui.js:9:8)
I tried it with the following combinations:
1. with the express server which serves the app on another terminal
2. without the express server
3. each of the above with chromedriver manually started at another terminal (I really don't think it should matter and that I should do this, just wanted to be thorough ...)
running the chromedriver manually yields the following and hangs:
$ node_modules/chromedriver/lib/chromedriver/chromedriver
Starting ChromeDriver 2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5) on port 9515
Only local connections are allowed.
I also tried running with firefox and it didn't work, which leads me to believe the problem is deeper than the chromedriver, i.e. related to selenium interacting with nightwatch.
I recall this happening a while back. I think it was that a previous instance Selenium had not closed freed port 4444 when shutting down. Try shutting down selenium and restarting.
To do that, open the following webpage manually, in the browser of your choice.
http://localhost:4444/selenium-server/driver?cmd=shutDownSeleniumServer
Then try running the script again as normal.

PhantomJS over HTTPS

I need to run Protractor tests using PhantomJS for a site using https. It's a development environment, the certs are self-signed and are not recognized by PhantomJS. I'm starting PhantomJS with the --ignore-ssl-errors flag, which supposed to make it accept invalid certs, but this isn't working. In CLI:
phantomjs --webdriver=localhost:4444 --web-security=false --ignore-ssl-errors=true --ssl-protocol=any
In spite of these settings, the acceptSslCerts property of the webdriver is still set to false. From the logs:
Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"mac-unknown-64bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
In a relevant GhostDriver repo issue (https://github.com/detro/ghostdriver/pull/388) the following code is listed:
const capabilities = webdriver.Capabilities.phantomjs();
capabilities.set(webdriver.Capability.ACCEPT_SSL_CERTS, true);
capabilities.set(webdriver.Capability.SECURE_SSL, false);
capabilities.set('phantomjs.cli.args', ['--web-security=no', '--ssl-protocol=any', '--ignore-ssl-errors=yes']);
const driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome(), capabilities).build();
I tried setting this in protractor.conf.js:
capabilities: {
browserName: 'phantomjs',
'webdriver.Capability.ACCEPT_SSL_CERTS': true,
'webdriver.Capability.SECURE_SSL': false
}
but this has no effect.
Has anyone figured out how to run PhatomJS in https mode?
I'm currently facing the same problem. Tried all alternatives you told and nothing seems to work.
Only thing that actually worked (not viable to my project, but maybe for yours) was to instantiate the webdriver passing the service_args like below:
Python:
webdriver.PhantomJS(executable_path='/home/rodrigo/bin/phantomjs-2.1.1-linux-x86_64/bin/phantomjs',
desired_capabilities=dict(DesiredCapabilities.PHANTOMJS),
service_args=['--web-security=no', '--ssl-protocol=any', '--ignore-ssl-errors=yes'])
Hope it helps you more than helped me.

change env when acceptance testing laravel app with codeception and selenium

I'm trying to write some acceptance tests for laravel 4 with codeception and the selenium module.
I got two problems with that.
The first one is that my app is running
in the homestead vagrant vm and the selenium server is running on the
host machine. So is there a easy way to run the selenium server in the vm and the call the browser o n the host machine ?
My second problem is that when testing the actual live database is used, because the environment of the laravel app is not set to testing. Obviously i would like to have it to use the test database and reset it after each test.
codeception.yaml
actor: Tester
paths:
tests: app/tests
log: app/tests/_output
data: app/tests/_data
helpers: app/tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
suite_class: \PHPUnit_Framework_TestSuite
modules:
config:
Db:
dsn: 'sqlite:app/tests/_data/testdb.sqlite'
user: ''
password: ''
dump: app/tests/_data/dump.sql
acceptance.yaml
class_name: AcceptanceTester
modules:
enabled: [WebDriver,AcceptanceHelper]
config:
WebDriver:
url: 'http://app.dev'
browser: firefox
window_size: 1920x1024
wait: 10
The easy way to run acceptance tests in the vm is to use phantom js in ghostdriver mode. There is a tutorial here:
https://gist.github.com/antonioribeiro/96ce9675e5660c317bcc
You can still see screenshots and the rendered html when tests fail, so it isn't a big deal that you can't see the browser.
For your second question, I prefer to keep a separate tests installation with it's own database. That way changes you make in dev don't alter your test results and it's a better approximation of production.
If you want to use the same installation, you can automate switching out your settings with .env files.
http://laravel.com/docs/4.2/configuration#protecting-sensitive-configuration
your config would look like this:
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
and your .env.php would look like:
return array( 'DB_HOST' => 'hostname', 'DB_NAME' => '' ..etc
than you can use a task runner like robo to automatically update your .env file and run codeception tests.
http://robo.li/
$this->replaceInFile('.env.php')
->from('production_db_name')
->to('test_db_name')
->run();
$this->taskCodecept()->suite('acceptance')->run();
.env files are changing in Laravel 5, but this workflow still works with minimal modification.
http://mattstauffer.co/blog/laravel-5.0-environment-detection-and-environment-variables