在场景运行时是否可以记录或输出任何用户数据?我知道php代码在每次运行时执行两次,如何在第二步中看到变量的值?
我是CodeCeption的新手.我身体里面有以下html,
<div><input type="text" name="content_id" id="contentId" maxlength="10" value="123"></div>
Run Code Online (Sandbox Code Playgroud)
在CodeCeption验收测试中,我有一个以下代码
`<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('fillfield test');
$I->amOnPage('/');
$I->seeInField('#contentId', 123);
$I->fillField('#contentId', 222397);
?>`
Run Code Online (Sandbox Code Playgroud)
seeInField测试成功通过,但fillField会抛出错误
抱歉,我无法填写字段"#contentId",222397
InvalidArgumentException:当前节点列表为空
这阻止了我继续前进.帮助我解决这个问题.
当我使用codeception生成的AcceptanceHelper(_support/AcceptanceHelper.php)时,如何访问Actor/AcceptanceTester($ I).如何从StepObjects访问我的函数?
我有:
接受/ _steps/MyStepObject.php
namespace AcceptanceTester;
class MyStepObject extends \AcceptanceTester
{
public function deleteCookies(){
$I = $this;
$I->amGoingTo("delete all cookies...");
$I->executeInSelenium(function(\WebDriver $webdriver) {$webdriver->manage()->deleteAllCookies(); });
$I->reloadPage();
}
public function loginUser($user,$password,$language = 'Untranslated')
{
$I = $this;
$I->amOnPage(\LoginPage::$URL);
$I->deleteCookies();
$I->amGoingTo('fill the fields...');
$I->fillField(\LoginPage::$usernameField, $user);
$I->fillField(\LoginPage::$passwordField, $password);
$I->click(\LoginPage::$loginButton);
}
}
Run Code Online (Sandbox Code Playgroud)
在类中_support/AcceptanceHelper.php我想调用AcceptanceTester中的方法$I->canSee('something'),我想'login'从我的StepObject 调用我自己的方法(比如).
我知道我可以获得一个特定的模块(例如WebDriver)$this->getModule('WebDriver').但是我怎样才能获得AcceptanceTester/my StepObject?
我正在设置Codeception的Db模块,并希望使用Symfony 2的parameters.yml文件中的参数。
基本上是这样的:
paths:
tests: tests
log: tests/_log
data: tests/_data
helpers: tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
log: true
modules:
config:
Symfony2:
app_path: 'app'
var_path: 'app'
environment: 'test'
Db:
dsn: "mysql:host='%test_database_host%';dbname='%test_database_name%'"
user: "%test_database_user%"
password: "%test_database_password%"
dump: tests/_data/test_data.sql
Run Code Online (Sandbox Code Playgroud)
占位符(例如%test_database_user%)不会被Symfony 2的app / config目录中的parameters.yml文件中的值替换。
parameters.yml:
parameters:
test_database_name: testdb
test_database_host: 127.0.0.1
test_database_user: root
test_database_password: thisismypassword
Run Code Online (Sandbox Code Playgroud)
最好的方法是什么?
谢谢。
作为基础,我使用\ Codeception\TestCase\Test类.
我注意到,对于类中定义的每个test*方法,codeception都会重新创建TestCase\Test类!
但为什么?
结果我不能使用类字段!
public function getName() {
if (!empty($this->_name)) {
return $this->_name;
} else $this->_name = uniqid('_name');
}
Run Code Online (Sandbox Code Playgroud)
每个测试方法的getName()都会返回新生成的名称..这对我来说是错误的行为.如果我想为每个测试方法使用类字段,就像普通的OOP一样,可以解决这种情况吗?
我正在使用Yii2的代码,我的配置如下:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://ucms.ac.ir/admin/index-test.php/'
browser: chrome
- tests\codeception\common\_support\FixtureHelper
- Yii2
config:
Yii2:
configFile: '../config/backend/acceptance.php'
Run Code Online (Sandbox Code Playgroud)
测试运行,并且它们成功完成,但selenium打开的新浏览器选项卡上没有任何内容.我已经看过一些教程,在那些教程中,浏览器实际上显示了测试过程.此外,当发生错误并通过代码识别截取以供以后参考时,它也只是一个空白页面.我在ubuntu 14.10,selenium 2.47.1和chrome 45.当我使用firefox而不是chrome时也会发生这种情况.
我正在寻找一种方法来从命令行覆盖我的测试的基本URL.将来,我会测试很多网站,所以如果我必须在acceptance.suite.yml文件的新环境中添加每个网站,那将非常笨拙.
目前,我acceptance.suite.yml是:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://foo.com
browser: chrome
Run Code Online (Sandbox Code Playgroud)
我看到我可以使用run命令选项'override',但即使我读了代码库文档并浏览帮助网站(比如stack 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
(
)
)
Run Code Online (Sandbox Code Playgroud)
我试过了./vendor/bin/codecept run acceptance --steps -o 'modules: enabled: 0: WebDriver: url: http://faa.faa,但测试一直在运行http://foo.foo …
我想检查这样的事情:
<?php
$I->amOnPage('/go/google');
$I->seeCurrentUrlEquals('http://google.com');
Run Code Online (Sandbox Code Playgroud)
但我得到错误:
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://google.com'
+''
Scenario Steps:
2. I see current url equals "http://google.com"
1. I am on page "/go/google"
Run Code Online (Sandbox Code Playgroud)
想法只是检查用户是否被重定向到外部资源。
有没有办法使用 Codeception 设置会话变量?我试过:
$_SESSION['variable'] = true;
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用。
在 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 来说比自动生成的特征更简单。
有什么区别吗?为什么文档建议采用不太直接的方法?
codeception ×10
php ×6
selenium ×2
testing ×2
phpunit ×1
symfony ×1
unit-testing ×1
yaml ×1
yii2 ×1