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

Viewed 1114

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 :

enter image description here

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 :

enter image description here

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)

enter image description here

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");
1 Answers

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