标签: codeception

Codeception 设置会话变量

有没有办法使用 Codeception 设置会话变量?我试过:

$_SESSION['variable'] = true;
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用。

php codeception

5
推荐指数
1
解决办法
3600
查看次数

Codeception 通过测试方法传递变量?

我在testRegisterNewUser 中创建一个新用户并将用户名保存在类字段变量中:

    private $_userName;

protected function userName ()
{
    if (empty($this->_userName)) {
        $this->_userName = uniqid('test_');
    }

    return $this->_userName;
}

public function testRegisterNewUser()
{
    $user = new User($this->userName() ); // create user with random name 
}
Run Code Online (Sandbox Code Playgroud)

之后,我尝试在另一个类方法中使用这个值,但是$_userName没有用testRegisterNewUser 的原始值初始化!

public function testFundUser()
{
    $user = User::findByUsername( $this->userName() ); // fails, $this->userName() gives "non original" value
}
Run Code Online (Sandbox Code Playgroud)

问题是,当我运行测试时codecept run,

这是否意味着Codeception\TestCase\Test为每个 test* 方法调用重新创建了类?

unit-testing codeception

5
推荐指数
0
解决办法
589
查看次数

Codeception Cest 继承

我不确定 Cest 文件是否可以扩展。在文档中,您可以扩展 Cest 类以共享常见行为。但每次我尝试运行测试时,我都会遇到未找到类异常。

是文档错误还是我做错了什么?

现在我的基类看起来像这样。

class ServiceCest {
  ...
} 
Run Code Online (Sandbox Code Playgroud)

子类看起来像这样。

class CreateServiceCest extends ServiceCest {...}
Run Code Online (Sandbox Code Playgroud)

testing codeception

5
推荐指数
1
解决办法
944
查看次数

Codeception: [RuntimeException] 调用未定义的方法 AcceptanceTester::wait

我正在使用 Codeception 进行我的第一次验收测试。

当我使用wait()或运行测试时waitForElement(),我收到以下消息:

[RuntimeException] Call to undefined method AcceptanceTester::wait  
Run Code Online (Sandbox Code Playgroud)

这是我的 acceptance.yml

# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate     suite.

class_name: WebGuy
modules:
enabled:
    - WebDriver
    - \Helper\Acceptance
config:
    WebDriver:
        url: 'http://rh.dev'
        browser: 'firefox'
Run Code Online (Sandbox Code Playgroud)

这是我的测试:

$I = new AcceptanceTester($scenario);
$I->wantTo('Register my profile for the first time');
$I->amOnPage('/register');
$I->fillField('name', $person->name); …
Run Code Online (Sandbox Code Playgroud)

acceptance-testing laravel codeception

5
推荐指数
2
解决办法
5441
查看次数

记录代码接收错误

我对 Codeception 还很陌生,我遇到了一个我无法弄清楚的问题。我的测试套件中有大约 40 个测试,如果测试失败,我需要发送一封电子邮件,说明失败的原因。例如,如果 Codeception 在页面上找不到导致测试失败的元素,我需要发送一封仅包含错误的电子邮件,如下所示:

无法在 ThisClass::thisTest (/home/qauser/codeception_tests///acceptance-mobile/Wishlist/EmailWishlistCest.php) 中验证电子邮件愿望清单的行为是否符合预期,无法看到“成功!”,//*[@id ="wish-list-confirm-popup"]/div/div/div[1]/h4":

我不想发送完整的堆栈跟踪,只想发送实际的错误。有谁知道这是否可能?

php selenium codeception

5
推荐指数
1
解决办法
1259
查看次数

Yii2 + Codeception:如何使用fixtures?

我使用 Codeception 为 Yii2 应用程序编写了一个简单的测试。而不是使用真正的 MySQL 数据库,我想使用装置。

这是代码:

测试/PersonTest.php:

namespace app\tests\unit\models;

use tests\fixtures;
use app\controllers;

class PersonTest extends \Codeception\Test\Unit
{
    protected $tester;
    public $appConfig = '@app/config/main.php';

    protected function _before(){ }
    protected function _after(){ }

    public function _fixtures()
    {
        return [ 'Person' => fixtures\PersonFixture::className() ];
    }

    public function testUser(){
        $person = Person::findOne( [ "id" => 1 ] );
        $userId = isset( $person->id ) ? $person->id : false;
        $this->assertEquals( 1, $userId );
    }
}
Run Code Online (Sandbox Code Playgroud)

测试/夹具/数据/Person.php

return [
    'person1' => [
        'id' …
Run Code Online (Sandbox Code Playgroud)

unit-testing fixtures yii yii2 codeception

5
推荐指数
1
解决办法
4995
查看次数

PhpStorm Codeception 运行参数

我得到了带有 Codeception 框架的 PhpStorm。当我运行验收测试时,IDE 会生成默认选项:

C:\xampp\php\php.exe C:/.../Temp/ide-codeception.php run --report -o "reporters: report: PhpStorm_Codeception_ReportPrinter" --no-ansi --no-interaction -c C :...\codeception.yml 接受

我怎样才能重载这个配置(特别是--no-ansi和--no-interaction)?

我已经尝试过“运行/调试配置”和“测试运行器选项”,但它不起作用。

phpstorm codeception

5
推荐指数
1
解决办法
620
查看次数

Codeception Actor Actor vs Helper?

在 Codeception 中,文档建议我向Helper\Acceptance类添加操作,然后将其包含在AcceptanceTester类中。班级AcceptanceTester里还这样说:

class AcceptanceTester extends \Codeception\Actor
{
    use _generated\AcceptanceTesterActions;

   /**
    * Define custom actions here
    */
}
Run Code Online (Sandbox Code Playgroud)

因此,我可以将我的操作添加到其中,AcceptanceTester这对于开发人员及其 IDE 来说比自动生成的特征更简单。

有什么区别吗?为什么文档建议采用不太直接的方法?

php testing codeception

5
推荐指数
1
解决办法
1069
查看次数

使用 ID 使用 Codeception 切换 IFrame

如何使用 ID 切换到带有 Codeception 的 IFrame?实际上我可以使用 IFrame 的名称而不是 ID -> Codeception SwitchToIFrame

IFrame 示例:

<iframe id="iframeToolbar" src="link" frameborder="0" style="position: fixed; left: 0px; top: 0px; z-index: 998; width: 940px;" scrolling="no" width="100px" height="100%"></iframe>
Run Code Online (Sandbox Code Playgroud)

代码接收示例:

<?php
# switch to iframe
$I->switchToIFrame("another_frame");
# switch to parent page
$I->switchToIFrame();
Run Code Online (Sandbox Code Playgroud)

是否可能是 Codeception <-> Facebook Webdriver 连接问题?

编辑:我按照快速步骤指南重新安装了 Codeception。结果 - 问题仍然相同:Codeception 和 Facebook Webdriver 不想一起工作。我的代码

accept.suite.yml:

actor: AcceptanceTester
modules:
  enabled:
    - \Helper\Acceptance
    - WebDriver:
            url: https://xxxxxxxxxxxxxx.com
            browser: chrome
            window_size: maximize
            clear_cookies: true
Run Code Online (Sandbox Code Playgroud)

codeception.yml:

paths:
tests: tests …
Run Code Online (Sandbox Code Playgroud)

iframe selenium codeception

5
推荐指数
1
解决办法
3976
查看次数

Codeception - 无法连接到 Webdriver(验收测试)

我可以访问 url 并创建会话:

http://localhost:4444/wd/hub/static/resource/hub.html

但是当我执行./codecept run我得到一个错误,但我有 Selenium 服务器运行:

[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.
Run Code Online (Sandbox Code Playgroud)

连接到网络驱动程序时出错

要执行 Selenium Server,我使用了以下命令:

java -Dwebdriver.gecko.driver=./geckodriver -jar "selenium-server-standalone-3.12.0.jar"
Run Code Online (Sandbox Code Playgroud)

硒服务器运行

我也尝试过 IE 和 Chrome(我也有同样的问题):

java -Dwebdriver.chrome.driver=./chromedriver -jar "selenium-server-standalone-3.12.0.jar"
java -Dwebdriver.ie.driver=./IEDriverServer -jar "selenium-server-standalone-3.12.0.jar"
Run Code Online (Sandbox Code Playgroud)

验收套件.yml

class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver
        - \Helper\Acceptance
    config:
        WebDriver:
            url: 'http://localhost'
            browser: firefox
            window_size: 820x1000
Run Code Online (Sandbox Code Playgroud)
  • 代码接收版本: 2.4.1
  • WebDriver Chrome 版本: 2.38 (win32)
  • WebDriver Firefox 版本: 0.20.1 (x64)
  • Chrome 版本: 66.0.3359.139(64 位)
  • Firefox …

selenium webdriver selenium-chromedriver selenium-webdriver codeception

5
推荐指数
1
解决办法
6124
查看次数