【问题标题】:First test passes while second test (with same data) fail Selenium with Codeception第一个测试通过,而第二个测试(使用相同的数据)通过 Codeception 使 Selenium 失败
【发布时间】:2016-09-14 22:17:32
【问题描述】:

我是一个尝试使用 Selenium WebServer 学习 Codeception 的菜鸟,但遇到了一个我似乎无法找到答案的问题。我正在编写一个超级基本测试,以确保从 index.php 中传入的数据在另一个页面 toupper.php 上是相同的。

这是我的 index.php:

<?php $something = "Can you see me?"; ?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Convert Me!</title>
  </head>
  <body>
    <h1>Convert Me!</h1>
    <p>
      <?php echo $something; ?>
    </p>

    <form action="toupper.php" method="post" id="post_form">
      <label for="string">Convert to Uppercase:</label>
      <input type="text" name="my_string" id="string">

      <input id="submit" type="submit" name="submitButton" value="Convert">
</form>
  </body>
</html>

这是我的 toupper.php:

<?php

  $message = (!empty($_POST['my_string'])) ?    strtoupper($_POST['my_string']) : "No string entered";

?>
<!DOCTYPE html>
<html>
<head>
    <title>To Upper!</title>
</head>
<body>

    <h1>To Upper!</h1>

    <p class="message"><?php echo $message; ?></p>

    <p><a href="index.php">Back to form</a>.</p>

</body>
</html>

我创建了一个简单的测试套件:

<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure Toupper form works');
$I->amOnPage('index.php');
$I->see('Can you see me?');
$I->fillField('my_string', 'convert me to uppercase');
$I->click('Convert');
$I->amOnSubdomain('toupper.php');
$I->see('CONVERT ME TO UPPERCASE');

现在,每当我运行测试时,测试都会通过,但是当我使用相同的数据再次运行精确测试时,它会失败。而且我没有使用数据库。

这是我得到的错误:

Scenario --
 I am on page "index.php"
 I see "Can you see me?"
 I fill field "my_string","convert me to uppercase"
 I click "Convert"
 I am on subdomain "toupper.php"
 I see "CONVERT ME TO UPPERCASE"
 FAIL

--------------------------------------------------------------


Time: 2.59 seconds, Memory: 8.00MB

There was 1 failure:

---------
1) ToupperCept: Ensure toupper form works
 Test  tests/acceptance/ToupperCept.php
 Step  See "CONVERT ME TO UPPERCASE"
 Fail  Failed asserting that   /toupper.php
-->
--> contains "convert me to uppercase".

Scenario Steps:

 6. $I->see("CONVERT ME TO UPPERCASE")
 5. $I->amOnSubdomain("toupper.php")
 4. $I->click("Convert")
 3. $I->fillField("my_string","convert me to uppercase")
 2. $I->see("Can you see me?")
 1. $I->amOnPage("index.php")


FAILURES!
Tests: 1, Assertions: 2, Failures: 1.

有人可以为我指出如何解决这个问题的正确方向吗?我很感激!

更新

在搞乱测试时,当我在 toupper.php 上写一个寻找大写文本的断言时,EX) $I->see('SOMETHING'); ,测试失败。似乎如果测试在某个时候失败,所有其他断言都会失败。即使我注释掉失败的断言,所有先前的断言在再次运行测试时都会失败。好糊涂!!

更新2

很抱歉进行了多次更新,但又搞砸了,我将 webdriver 的浏览器从 firefox 切换到了 chrome。我所有的测试每次都完美通过。奇怪的是只有火狐有问题。

【问题讨论】:

  • 你不需要 amOnSubdomain。
  • @Naktibalda,我注释掉了 amOnSubdomain,但测试仍然失败。

标签: codeception


【解决方案1】:

尝试在测试代码中的失败行之前插入$I-&gt;pauseExecution();。然后,您可以轻松查看失败前浏览器窗口中发生的情况。可能您遇到了 Firefox 在表单中保留数据的问题。

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 2021-09-04
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 2019-03-14
    • 1970-01-01
    • 2019-10-23
    相关资源
    最近更新 更多