I tried to have the server address injected to the test with environment variable ABSOLUTE_URL so PhpBrowser would test against it. The config I wanted to do is something like this:
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: "%ABSOLUTE_URL%"
But I simply could not get it to work. Is there anyway I can do it?
Add params section to codeception.yaml file:
params:
- env
Documented at https://codeception.com/docs/06-ModulesAndHelpers#Dynamic-Configuration-With-Parameters
Related
I'm using Lando to create a local development server for a Laravel project with the recipe below in .lando.yml
name: projectname
recipe: laravel
config:
php: '7.3'
composer_version: '2.0.7'
via: apache:2.4
webroot: .
database: mysql:5.7
cache: none
xdebug: false
config:
server: lando/httpd.conf
I need to add a few lines to a custom httpd.conf so I specify a path server: lando/httpd.conf. However, I couldn't locate the current default httpd.conf in order to make a copy and use it as a custom file. The link provided on Lando official site doesn't seem to work.
Did you try looking in the apache2 foler in the container?
$lando ssh
$cd /etc/apache2
I make my first steps in creating functional tests with codeception.
This is my functional.suite.yml
class_name: FunctionalTester
modules:
enabled:
- PhpBrowser:
url: 'http://localhost'
- \Helper\Functional
Now I want to generate the actions for the FunctionalTester. I use this command:
vendor/bin/codecept build
No methods are added. I expected that methods like amOnUrl($url) are created in the trait FunctionalTesterActions. But this is my result.
Building Actor classes for suites: unit, acceptance, functional
-> UnitTesterActions.php generated successfully. 0 methods added
\UnitTester includes modules: Asserts, \Helper\Unit
-> AcceptanceTesterActions.php generated successfully. 0 methods added
\AcceptanceTester includes modules: PhpBrowser, \Helper\Acceptance
-> FunctionalTesterActions.php generated successfully. 0 methods added
\FunctionalTester includes modules: \Helper\Functional, REST, PhpBrowser
The configuration should be OK. I tested this with the command
vendor/bin/codecept config:validate
What is my mistake? Thanks for every hint.
I figured it out. Turns out I had a syntax error in my Helper.
Hope this helps someone in the future.
Is there a way to have current base URL in _bootstrap file for my acceptance test ?
Or
Is there a way to have current environment in _bootstrap file for my acceptance test ?
Actually, I use environment variable to test different sites :
env:
env1:
modules:
config:
WebDriver:
url: 'http://local.env1.fr/'
env2:
modules:
config:
WebDriver:
url: 'http://local.env2.fr/'
Finaly I find a variable with current environment.
$settings["current_environment"]
The WebDriver has a method with the name
public function _getUrl()
$url = $I->_getUrl();
https://github.com/Codeception/Codeception/blob/2.0/src/Codeception/Module/WebDriver.php#L207
It seems, that it doesn't work, because the builded WebGuy class hasn't such a method. I guess the _bootstrap.php file hasn't the possibility to read the config. Only a special "module" could read it's own config by passing the config array as argument by the constructor.
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
What is the best practice for storing/retrieving API keys in rails3?
Should I create my own application yaml and access it through there? If so, how?
Sorry for the noob question...
I use the settingslogic plugin for things like this. Very easy to use.
Add settingslogic to your Gemfile and bundle install:
gem 'settingslogic'
Create a directory for your settings and place the settingslogic yaml in there:
/my_app/config/settings/my_settings.yml
You can include default settings and per environment settings. The file looks like this:
defaults: &defaults
api_key: abc123
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
Add this file: app/models/my_settings.rb, start up your app and you are good to go
class MySettings < Settingslogic
source "#{Rails.root}/config/settings/my_settings.yml"
namespace Rails.env
end
Now you can use call these settings from anywhere in the app like so:
MySettings.api_key