【问题标题】:Codeception, how override url from command line for a specific (or not specific) suite test?Codeception,如何从命令行覆盖特定(或非特定)套件测试的 url?
【发布时间】:2019-02-07 16:24:42
【问题描述】:

我正在寻找一种方法来从命令行覆盖我的测试的基本 url。以后我会测试很多网站,所以如果我必须在acceptance.suite.yml文件中添加新环境中的每个网站,这很不方便。

目前,我的acceptance.suite.yml是:

actor: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: http://foo.com
            browser: chrome

我知道我可以在运行命令中使用“覆盖”选项,但即使我阅读了代码接收文档并浏览了帮助网站(如堆栈 overflox..),我也找不到覆盖的好方法。有人能帮我吗?

当我打印所有配置(通过./vendor/bin/concept)时,我得到:

Array
(
    actor => AcceptanceTester
    modules => Array
        (
            enabled => Array
                (
                    0 => Array
                        (
                            WebDriver => Array
                                (
                                    url => http://foo.foo
                                    browser => chrome
                                )
                        )
                    1 => \Helper\Acceptance
                )
            config => Array
                (
                )
            depends => Array
                (
                )
        )

我试过了:./vendor/bin/codecept run acceptance --steps -o 'modules: enabled: 0: WebDriver: url: http://faa.faa,但测试一直在 http://foo.foo 上运行

在这个codeception issue post 中,当我们运行一个特定的套件时似乎不可能覆盖配置值(我的英语不是很好,所以也许我误解了)。所以我在我的acceptance.suite.yml 文件中添加了一个环境:

actor: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: http://foo.foo
            browser: chrome
env:
    generic:
        modules:
            config:
                WebDriver:
                    url: http://faa.faa

我尝试了这些命令:

./vendor/bin/codecept run acceptance --env generic --steps -o 'env: generic: modules: config: WebDriver: url: http://faa.faa

还有

./vendor/bin/codecept run acceptance --env generic --steps -o 'WebDriver: url: http://faa.faa

什么也没发生。我的测试总是在http://foo.foo

“军团”帮助后编辑

当我使用这个acceptance.suite.yml

actor: AcceptanceTester
modules:
  enabled:
      - WebDriver
  config:
    WebDriver:
      url: ''
      browser: ''

env:
  chrome:
    modules:
      config:
        WebDriver: {}

我得到一个错误:

所以当我使用这个acceptance.suite.yml 时:

actor: AcceptanceTester
modules:
  enabled:
    - WebDriver
  config:
    WebDriver:
      url: ''
      browser: chrome

env:
  chrome:
    modules:
      config:
        WebDriver: {}

我收到另一个错误:

如果我使用这个acceptance.suite.yml

actor: AcceptanceTester
modules:
  enabled:
    - WebDriver
  config:
    WebDriver:
      url: ''
      browser: chrome

env:
  chrome:
    modules:
      config:
        WebDriver:
          url: 'http://foo.foo'
          browser: 'chrome'

没有错误!呜呜呜!我不在好网址 x)

我得到的网址是“数据:”,很奇怪...... 为了获取 url,我在我的测试文件中添加了这个简单的行:

$this->comment("I am on the url : " . $this->executeJS("return window.location.href") . "\n");

【问题讨论】:

标签: codeception


【解决方案1】:

注意:您需要 Codeception 1.8 或更高版本!在那个版本被窃听之前。

如果版本大于 1.8,它应该可以工作...您可以尝试编辑您的接受文件,如下所示,看看是否有更改:

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'

如下运行:

php vendor/bin/codecept run acceptance --env chrome

** 编辑 **

要从命令行传递 url,您需要空的 WebDriver 配置:

actor: AcceptanceTester
    modules:
        enabled:
            - WebDriver
        config:
            WebDriver: {}
env:
    chrome: #or watherver you want
         modules:
            config:
                WebDriver:
                    url:'http://foo.foo'
                    browser:'firefox'

命令行:

./vendor/bin/codecept run acceptance --env chrome --steps -o 'WebDriver: url: \'http://faa.faa\' browser: \'chrome\''

(我通常将 apex 用于 url 和浏览器...但不确定是否真的需要)。

【讨论】:

  • 感谢您的帮助 :) 这是可行的,但我正在寻找一种解决方案,而无需在“acceptance.suite.yml”中添加每个未来网站。我希望能够像我在帖子开头所说的那样从命令行设置 url
  • 哎呀,我的错,顺便说一句,我认为你可以通过稍微编辑我的答案来达到目标​​,只需几秒钟。
  • 我测试了您的编辑,执行您的命令时出现错误(未配置 WebDriver 模块!选项:浏览器、url 是必需的)。因此,我在“acceptance.suite.yml”文件的块“modules: enabled: -WebDriver: ...”中添加了默认 url 和浏览器。当我再次运行你的命令行时,url没有改变,测试选择的url是我刚刚在“acceptance.suite.yml”中定义的url(我的codeception版本:2.4)
  • 尝试配置它,在默认情况下保留空白 ulr 和浏览器... idk 为什么该代码不适合您,但可能您的问题是您的 WebDriver 具有默认值,我编辑我的答案编辑以匹配我的意思。
  • 它正在进行中(现在没有错误),但 url 被值“data:”覆盖。请参阅我最初的帖子,我添加了一个带有屏幕截图的 EDIT 部分
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-25
  • 1970-01-01
  • 1970-01-01
  • 2011-05-18
相关资源
最近更新 更多