我正在尝试为学习目的进行简单的验收测试.这是一个简单的身份验证方案:用户输入/admin,如果没有记录,他会被重定向/login到填写表单.
当我运行测试时,我收到此错误:
1) Couldn't login with a password protected area in LoginCest.loginUserWithProperCredentials
Guy couldn't fill field "username","rafael": Field matching id|name|label|value or css or xpath selector does not exist
Scenario Steps:
5. I fill field "username","rafael" <==== RED
4. I see current url equals "/login"
3. I am on page "/admin"
2. So that I Perform administrative tasks
1. As a Site Owner
Run Code Online (Sandbox Code Playgroud)
现在这是我的观点:
//create.blade.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
</head>
<body>
<h1>Login</h1>
{{ Form::open() …Run Code Online (Sandbox Code Playgroud) 我想我可能会把这个概念弄错或者没有正确地考虑某些事情.我正在寻找一种连接到db的方法,然后为表的每一行运行selenium测试(在phantomjs中).测试是检查定制CMS上的损坏图像,并可应用于任何CMS.
我基本上希望通过从db加载它们的ID然后为每个ID运行单独的测试来为每个页面(特定类型)运行验收测试.
这是我到目前为止:
$I = new WebGuy($scenario);
$results = $I->getArrayFromDB('talkthrough', '`key`', array());
foreach ($results as $r) {
$I->wantTo('Check helpfile '.$r['key'].'for broken images');
$I->amOnPage('/talkThrough.php?id='.$r['key']);
$I->seeAllImages();
}
Run Code Online (Sandbox Code Playgroud)
这在某种程度上起作用,因为它执行直到第一次失败(因为它运行为具有许多断言的1个测试).
如何将此运行作为单独测试?
这是我第一次设置测试套件,所以我可能会犯一些愚蠢的错误.
我只是设置Codeception来为CodeIgniter项目编写一些测试.我有一些简单的测试工作(耶!)但我现在正在编写验收测试以确保我的登录表单有效.填写表单并单击提交工作正常,但是当我尝试在提交后检查页面时,似乎没有遵循重定向.
重定向是301标头重定向.编辑:FALSE关闭我使用的auth库执行"重新加载"标头重定向.使用真正的301修复了问题.
我假设应该遵循重定向.我需要设置/配置以使301重定向工作吗?
我的验收测试:
<?php
$I = new WebGuy($scenario);
$I->wantTo('Login');
$I->amOnPage('/');
$I->fillField('identity', 'manager@example.com');
$I->fillField('password', 'password');
$I->click('submit');
$I->see('Logged In Successfully');
Run Code Online (Sandbox Code Playgroud)
我在调试模式下运行测试时的输出.在InvalidArgumentException被抛出错误,因为它看起来在页面的DOM是空的:
Codeception PHP Testing Framework v1.7.1
Powered by PHPUnit 3.7.27 by Sebastian Bergmann.
Acceptance Tests (1) -----------------------
Trying to login (LoginCept.php)
Scenario:
* I am on page "/"
* I fill field "identity","manager@example.com"
* I fill field "password","password"
* I click "submit"
* I see "Logged In Successfully"
ERROR
---------------------------------------------
Time: 3.96 seconds, …Run Code Online (Sandbox Code Playgroud) 我试图在我的Laravel应用程序中运行一些验收测试.虽然功能测试会触发测试环境,但验收测试却没有.它是验收测试的错误还是功能?困扰我的主要问题是,它不是使用(+ populating + cleanup)测试数据库,它只连接到dev数据库(当没有指定其他ENV时使用,例如测试,生产),这个当我多次运行它们时经常会失败.
这是我的配置:
codeception.yml
paths:
tests: app/tests
log: app/tests/_log
data: app/tests/_data
helpers: app/tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
log: true
modules:
config:
Db:
dsn: 'mysql:host=localhost;dbname=testdb'
user: 'root'
password: 'root'
dump: 'app/tests/_data/dump.sql'
populate: true
cleanup: true
Run Code Online (Sandbox Code Playgroud)
acceptance.suite.yml
class_name: WebGuy
modules:
enabled:
- PhpBrowser
- WebHelper
- Db
config:
PhpBrowser:
url: 'http://localhost/'
Run Code Online (Sandbox Code Playgroud)
functional.suite.yml
class_name: TestGuy
modules:
enabled: [Filesystem, TestHelper, Laravel4, Db]
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我是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:当前节点列表为空
这阻止了我继续前进.帮助我解决这个问题.
我正在写一个简单的测试用例.我使用composer安装了代码.我的测试用例位于测试用例文件夹内的根文件夹中
当我尝试运行以下代码时
namespace app\tests\testcases;
use yii\codeception\TestCase;
class SomeMyTest extends TestCase
{
public function testOne()
{
echo "here";
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在浏览器中运行代码时,我收到以下错误
Fatal error: Class 'yii\codeception\TestCase' not found
Run Code Online (Sandbox Code Playgroud)
在我的项目中有一个名为yiisoft\yii2-codeception\TestCase.php的文件
我究竟做错了什么?任何人都可以帮忙吗?
我知道用于设置测试环境等的_bootstrap.php文件,但是我正在寻找一种在整个测试套件完成后运行一些代码的方法.
请注意,我并不是在寻找一种在单个类之后运行代码的方法,例如_after,但是在所有类之后.
有没有办法实现这个目标?
我正在尝试测试项目但由于此错误而无法检查登录页面:
[RuntimeException] Call to undefined method AcceptanceTester::loadSessionSnapshot
这是我的代码:
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('Login');
$I->amOnPage('/');
if($I->loadSessionSnapshot('loggedin')) exit();
$I->dontSee('NotFound');
//$I->dontSee('Error');
$csrf = $I->grabCookie('_token');
$I->submitForm('.form',array('login'=>array(
'username'=>'username',
'password'=>'*******'
)
));
$I->saveSessionSnapshot('loggedin');
$I->see('username');
Run Code Online (Sandbox Code Playgroud)
我的配置是这样的
# 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: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://myweb.com
- \Helper\Acceptance
Run Code Online (Sandbox Code Playgroud)
我使用命令行命令生成了它
codecept.bat generate:cept acceptance loginTest
Run Code Online (Sandbox Code Playgroud) 希望通过此代码块获得$ 2.00的XPath:
<td class="undefined" colspan="6">
<table class="history-bill-payments" cellspacing="0" cellpadding="0" border="0" align="center" width="99%">
<thead>
<tbody>
<tr>
<td valign="top">04/19/2016</td>
<td valign="top" style="text-align:right; height:">
$3.00
<br/>
$2.00
</td>
Run Code Online (Sandbox Code Playgroud)
我尝试了这些但无济于事
$I->CanSeeElement("//table[contains(tbody/tr[2]/td/table/tbody/tr/td[2]/following-sibling::br)]");
$I->CanSeeElement("//table[contains(tbody/tr[2]/td/table/tbody/tr/td[2]/preceding-sibling::br/text(),'$2.00')]");
$I->CanSeeElement("//table[contains(tbody/tr[2]/td/table/tbody/tr/td[2]/following-sibling::br/text(),'$2.00')]");
Run Code Online (Sandbox Code Playgroud)
在Firefox中使用firepath,我得到了这个XPath
html / body / div [4] / div [2] / div / div / div / div / div / table / tbody / tr [2] / td / table / tbody / tr / td [2]
我能够得到$ 3.00的xpath
$I->CanSeeElement("//table[contains(tbody/tr[2]/td/table/tbody/tr/td[2]/text(),'$3.00')]");
Run Code Online (Sandbox Code Playgroud) 我正在努力使代码接收与 PhpStorm 一起工作。
我已经设置了 CLI 解释器:
我还设置了 Codeception:
这是 Codeception 的配置:
当我从 PhpStorm 运行测试时,我收到以下信息:
在左边:
和右边的文字:
Testing started at 00:06 ...
/Applications/MAMP/bin/php/php7.2.1/bin/php /private/var/folders/3g/xng_tnzj6797frqqk20r69mw0000gn/T/ide-codeception.php run --report -o "reporters: report: PhpStorm_Codeception_ReportPrinter" --no-ansi --no-interaction unit
Process finished with exit code 255
Run Code Online (Sandbox Code Playgroud)
但是当我concept run在终端上的项目文件夹中运行时,它工作正常,我收到了这个:
我究竟做错了什么?我真的在这里阅读了 PhpStorm 的手册和 youtube视频,但我无法让它工作:/
谢谢!
在进一步的调查中,我发现了以下内容:
$ /usr/bin/env php --version
PHP 7.2.1 (cli) (built: Jan 15 2018 12:20:50) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend …Run Code Online (Sandbox Code Playgroud)