Codeception, how override url from command line for a specific (or not specific) suite test? - codeception

I'm looking for a way to override the base url of my tests from the command line. In the future, I'll tests a lot of websites, so it's very unwieldy if I must add each website in a new environment in the acceptance.suite.yml file.
Currently, my acceptance.suite.yml is:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://foo.com
browser: chrome
I see I can use the option 'override' with the run command, but even if I read the codeception document and navigate through help website (like stack overflox..), I can't find a good way for override. Can someone help me?
When I prints all config (via ./vendor/bin/concept), I get:
Array
(
actor => AcceptanceTester
modules => Array
(
enabled => Array
(
0 => Array
(
WebDriver => Array
(
url => http://foo.foo
browser => chrome
)
)
1 => \Helper\Acceptance
)
config => Array
(
)
depends => Array
(
)
)
I tried : ./vendor/bin/codecept run acceptance --steps -o 'modules: enabled: 0: WebDriver: url: http://faa.faa, but the test run ever on http://foo.foo
In this codeception issue post, it seems it's impossible to override a config value when we run a specific suite (my english is not very good , so maybe I misunderstood). So I add an env in my acceptance.suite.yml file :
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://foo.foo
browser: chrome
env:
generic:
modules:
config:
WebDriver:
url: http://faa.faa
And I tried theses commands :
./vendor/bin/codecept run acceptance --env generic --steps -o 'env: generic: modules: config: WebDriver: url: http://faa.faa
And
./vendor/bin/codecept run acceptance --env generic --steps -o 'WebDriver: url: http://faa.faa
And nothing happened. My test are always on http://foo.foo
EDIT AFTER "LEGION" HELP
When I use this acceptance.suite.yml :
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: ''
env:
chrome:
modules:
config:
WebDriver: {}
I get an error :
So when I use this acceptance.suite.yml :
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: chrome
env:
chrome:
modules:
config:
WebDriver: {}
I get an another error :
And if I use this acceptance.suite.yml :
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: chrome
env:
chrome:
modules:
config:
WebDriver:
url: 'http://foo.foo'
browser: 'chrome'
No error ! buuuUUUT ! I'm not on the good url x)
The url I get is "data:", its strange...
For get the url, I add this simple line in my test file :
$this->comment("I am on the url : " . $this->executeJS("return window.location.href") . "\n");

N.B: You need Codeception 1.8 or above! Before that version is bugged.
If the version is > 1.8 it should works... you may try editing your acceptance file like below and see if something is changed:
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: 'http://foo.foo/'
browser: 'firefox'
env:
chrome: #or watherver you want
modules:
config:
WebDriver:
url: 'http://fuu.fuu/'
browser: 'chrome'
run it like below:
php vendor/bin/codecept run acceptance --env chrome
** EDIT **
To pass the url from commandline you need empty WebDriver Configuration:
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver: {}
env:
chrome: #or watherver you want
modules:
config:
WebDriver:
url:'http://foo.foo'
browser:'firefox'
commandline:
./vendor/bin/codecept run acceptance --env chrome --steps -o 'WebDriver: url: \'http://faa.faa\' browser: \'chrome\''
(I usually use apex for url and browser... but not sure are really neded).

Related

Codeception: Class "tests\_support\AcceptanceTester" does not exist

New to PHP and Codeception, but not to programming. I've just set up Codeception in my web site's root folder.
During the install, I ran:
php vendor/bin/codecept bootstrap
and
php vendor/bin/codecept build
My _support/AcceptanceTester.php contains this:
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
/**
* Define custom actions here
*/
}
and acceptance.suite.yaml has this:
actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://localhost/shop
- \Helper\Acceptance
step_decorators: ~
What am I missing???

Drag and Drop codeception

I'm running a test with codeception to do a Drag & Drop. Running the test returns no error BUT the Drag & Drop does not actually work (I don't see what I want).
I have to move one window to another
This is my test:
$I->click(['id' => 'showGallery']);
$I->amOnUrl("http://xxxxxx");
$I->dragAndDrop("//div[#class='grid-stack-item-content']","//div[#id='dashboard']");
$I->wait ('15');
$I->see ("Codice prodotto:");
This is my acceptance.suite.yml:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://xxxx
host: xxxx
port: xxxx
window_size: false
browser: chrome
capabilities:
unexpectedAlertBehaviour: 'ignore'
chromeOptions:
args: ["--disable-gpu", "window-size=1920x1080", "--no-sandbox"]
- \Helper\Acceptance

Codeception acceptance tests run before browser starts

When I run Codeception tests, sometimes on acceptance tests a browser starts too late, tests do not wait for it to start, and I get errors for tests that passed before a browser start:
[ConnectionException] Can't connect to Webdriver at http://127.0.0.1:4444/wd/hub. Please make sure that Selenium Server or PhantomJS is running.
#1 Codeception\Subscriber\Module->before
#2 D:\path\Yii\basic\vendor\symfony\event-dispatcher\EventDispatcher.php:212
#3 D:\path\Yii\basic\vendor\symfony\event-dispatcher\EventDispatcher.php:44
One time a browser didn't start at all.
My command:
C:\Windows\System32\cmd.exe /K "cd /D D:\path\Yii\basic && vendor\bin\codecept run"
acceptance.suite.yml:
class_name: AcceptanceTester
extensions:
enabled:
- Codeception\Extension\RunProcess:
- java -jar -Dwebdriver.chrome.driver="D:/Selenium/chromedriver.exe" -Dwebdriver.gecko.driver="D:/Selenium/geckodriver.exe" "D:/Selenium/selenium-server-standalone-3.6.0.jar"
modules:
enabled:
- WebDriver:
url: https://hotel.localhost/
browser: chrome
- Yii2:
part: orm
entryScript: index-test.php
cleanup: false
codeception.yml:
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
memory_limit: 1024M
colors: true
modules:
config:
Yii2:
configFile: 'config/test.php'
cleanup: false
coverage:
enabled: true
whitelist:
include:
- models/*
- controllers/*
Thank you in advance.
Add some sleep to RunProcess configuration as documented here.
To wait for the process to be launched use sleep option. In this case you need configuration to be specified as object:
extensions:
enabled:
- Codeception\Extension\RunProcess:
0: java -jar ~/selenium-server.jar
1: mailcatcher
sleep: 5 # wait 5 seconds for processes to boot

Codeception - " Curl error thrown for http POST to /session with params:"

first of all, sorry for my poor english.
I have a problem with the test automation.
I am a beginner. I have virtual box instance with my app, where is set a standard address with VirtualBox outside (192.168.56.101). I connect netbeans with this instance, and i have project with my app on this. And the last thing - I'm trying to biuld test automation for it.
Unfortunately, I have a problem,. Test is created, selenium started, PhantomJs also started. I go to the project folder, "codecept run" and...
acceptance.suite config:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- \Helper\Acceptance
- Db:
dsn: 'mysql:host=localhost;dbname=xxx'
user: 'root'
password: 'xxx'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: false
reconnect: true
config:
WebDriver:
url: 'http://xxx.app/'
browser: chrome
host: '192.168.56.101'
port: 22
window_size: 'maximize'
env:
phantom:
modules:
config:
- WebDriver:
browser: 'phantomjs'
Please help.

How to setup Selenium grid remotely in protractor

I have my conf.js file which runs fine locally. But now as per my requirement I need to run it in a bamboo task. Since my code is going to run on server there is a remote selenium webdriver that i need to add to the conf.js.
Can you please help me out how it is done? My conf.js looks like this :
exports.config = {
params: {
url: "URL",
testroadname:"Testing123",
sleeptime:1000
},
directConnect: true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['mapfeedback.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
You have to remove directConnect = true and just give the seleniumAddress in your config or setup an environment.js file- you can simply add your remote selenium's address and fire up your protractor tests, following will be your environment.js-
// Common configuration files with defaults plus overrides from environment vars
var webServerDefaultPort = 8081;
module.exports = {
// The address of a running selenium server.You can add your remote address here
seleniumAddress:
(process.env.SELENIUM_URL || 'http://localhost:4444/wd/hub'),
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName':
(process.env.TEST_BROWSER_NAME || 'chrome'),
'version':
(process.env.TEST_BROWSER_VERSION || 'ANY')
},
// Default http port to host the web server
webServerDefaultPort: webServerDefaultPort,
// Protractor interactive tests
interactiveTestPort: 6969,
// A base URL for your application under test.
baseUrl:
'http://' + (process.env.HTTP_HOST || 'localhost') +
':' + (process.env.HTTP_PORT || webServerDefaultPort)
};
your config file will look like -
var env = require('./environment.js');
exports.config = {
params: {
url: "URL",
testroadname:"Testing123",
sleeptime:1000
},
seleniumAddress: env.seleniumAddress,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['mapfeedback.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
To setup selenium-grid remotely for Protractor :-
start hub with command :-
java -jar selenium-server-standalone-3.3.1.jar -role hub -port 4444
Now start your remote node with command where you want execute remote test cases :-
java -jar selenium-server-standalone-3.3.1.jar -role webdriver -hub http://HubDomain-IP:4444/grid/register -port 5556 -browser browserName=internet explorer,maxInstances=1,platform=WINDOWS,applicationName=remoteNode -Dwebdriver.ie.driver=path to IEDriverServer.exe
Once your selenium-grid setup is done and node get connected with Hub, then take config file with configuratiion set as this conf.js file:-
exports.config = {
//The address of your running selenium Hub server.
seleniumAddress: 'http://HubDomain-IP:4444/wd/hub',
//Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'internet explorer',
// add node-name as applicationName where you have started node and wanted to remotely execute test cases
'applicationName': 'remoteNode'
},
//Specify the name of the specs files.
specs: ['grid_spec.js'],
//Options to be passed to Jasmine-node.
jasmineNodeOpts: {
onComplete: null,
isVerbose: false,
showColors: true,
includeStackTrace: true
}
};
With above mentioned configuration and setup commands you could run selenium-grid setup for Protractor.Thanks !