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
Related
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!
I am trying to run an acceptance test on firefox using selenium 3.0.1. I am also using wp-browser WPWebDriver module. My acceptance-suit.yml looks like this.
class_name: AcceptanceTester
modules:
enabled:
- \Helper\Acceptance
- WPWebDriver
config:
WPWebDriver:
url: 'url'
adminUsername: 'juhi.saxena#gmail.com'
adminPassword: '123456'
adminPath: '/wp-admin'
browser: firefox
webdriver.gecko.driver: 'bin/geckodriver.exe'
On runnuning this wpcept run acceptance testsCest.php I get [Facebook\WebDriver\Exception\UnknownServerException] The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded fro
m https://github.com/mozilla/geckodriver/releases
Try removing the '.exe'.
I'm running successfully with webdriver.gecko.driver: '/usr/local/bin/geckodriver'.
Also, have you placed the geckodriver.exe in the path?
I solved a similar problem with Codeception and Firefox by adding path='' to the WebDriver config section.
I'm running tests using tasks in VS Code and I've stacked with problem of parallel launching tests.
I want to pass two environments to env variable in order to start tests. With one environment, everything works perfect, but if I pass several -all tests start with default configuration in 4 threads.
Example:
var nightwatchOptions = {
config: './dist/dev/specs/e2e/nightwatch/nightwatch.json',
env: ['firefox', 'chrome'] ---> this one doesn't work
};
I also tried to pass it like that: env: 'firefox,chrome' and like that ['firefox,chrome'] - first one hangs, second one - default configuration.
env: 'chrome' ---> this one works perfect.
Any help will be appreciated!
Ok, I've just figured out how to avoid this issue. I decided to start it with the help of child_process of nodejs:
nightwatchOptions = ['node_modules/nightwatch/bin/runner.js',
'-c',
'path to config'];
var tests = child_process.spawn('node', nightwatchOptions, {
stdio: 'inherit'
});
And I've added test_workers to nightwatch config. Now it works fine for me.
New Codeception user here, so apologies in advance for what's like a super simple question. Is it possible to have a codeception project that runs some acceptance tests with the PhpBrowser driver, and others with the selenium WebDriver driver?
That is, I have an acceptance.suite.yaml that looks like this
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://localhost/'
browser: firefox
window_size: 1024x768
wait: 10
capabilities:
unexpectedAlertBehaviour: 'accept'
And a test that looks like this
#File: tests/acceptance/Science.php
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('see Science word in title ');
$I->amOnPage('/');
$I->seeInTitle('Science');
When I run
vendor/bin/codecept run
My tests run in selenium server. (yay!) However, there's other tests I'd like to run in the plain old PhpBrowser. Is this possible without creating a second codeception suite? If so, what does the configuration and/or test look like?
No, you have to use separate suites.
I think you can use WebDriver with PhantomJS browser as explained in Codeception documentation here http://codeception.com/docs/modules/WebDriver.
You need to download and run PhantomJS and then change the browser value from firefox to phantomjs in codeception configuration file.
If you need both WebDriver and PHPBrowser tests - create a separate suite.
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.