草庐IT

php - Selenium 不显示失败的数字行

coder 2024-04-16 原文

我的 Selenium 服务器在 MAMP 本地服务器上与 PHPUnit 一起工作。

当 Assert 失败时,没有显示失败的数字行,而是我看到了 phpunit 数字行。

当我执行“仅限 phpunit”测试时,我可以看到失败断言的数字行。

仅 PHPUnit 测试

$ cd '/Applications/MAMP/htdocs/my-client/tests' && phpunit -c 'phpunit.xml'  '/Applications/MAMP/htdocs/my-client/tests/controllers/homeTest.php'
PHPUnit 3.6.10 by Sebastian Bergmann.

Configuration read from /Applications/MAMP/htdocs/my-client/tests/phpunit.xml

.

Time: 0 seconds, Memory: 8.00Mb

There was 1 failure:

1) HomeTest::test_get_sections
Failed asserting that Array (
    blah, blah, blah
    )
) is identical to Array (blah, blah, blah2
    )
).

/Applications/MAMP/htdocs/my-client/tests/controllers/homeTest.php:56
/Applications/MAMP/bin/php/php5.3.6/bin/phpunit:46

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

PHPUnit Selenium 测试

$ cd '/Applications/MAMP/htdocs/my-client/tests' && phpunit -c 'phpunit.xml'  

'/Applications/MAMP/htdocs/my-client/tests/views/af_web_Test.php'
PHPUnit 3.6.10 by Sebastian Bergmann.

Configuration read from /Applications/MAMP/htdocs/my-client/tests/phpunit.xml

E

Time: 2 seconds, Memory: 8.75Mb

There was 1 error:

1) af_web_Test::test_crear_una_af_nueva_y_validar_el_valor_por_defecto_de_los_campos
Current URL: http://localhost:8888/my-client/index.php/home/view

Failed asserting that '' matches PCRE pattern "/0/".

/Applications/MAMP/bin/php/php5.3.6/bin/phpunit:46

FAILURES!
Tests: 1, Assertions: 6, Errors: 1.

最佳答案

我遇到了同样的问题(尽管是在 LAMP 服务器上),因为我非常依赖这些行号和屏幕截图来确定我的测试中到底出了什么问题。我认为这是错误,显然已报告。参见 https://github.com/sebastianbergmann/phpunit-selenium/issues/81供引用。

作为临时 解决方法,我已将行号强制放入正在抛出的异常中的错误消息中(因为行号当然可以在跟踪中找到)。作为副作用,大多数异常都被重新抛出,我只抛出 PHPUnit_Framework_Error,但至少我在输出中得到了行号。作为解决此问题之前的临时解决方法,这对我有用。

为此,我使用自己的 SeleniumTestCase 扩展了 PHPUnit_Extensions_SeleniumTestCase,并将这些函数放入其中:

我自己使用的这个函数的非常轻微的修改版本:https://stackoverflow.com/a/6608751

protected function dumpStack(Exception $e) {
    $stack = '';
    foreach ($e->getTrace() as $trace) {
        if (isset($trace['file'])        &&
            isset($trace['line'])        &&
            isset($trace['class'])       &&
            isset($trace['function']))
        {
            $stack .= PHP_EOL .
                $trace['file']     . ':' .
                $trace['line']     . ' ' .
                $trace['class']    . '::' .
                $trace['function'];
        }
    }
    return $stack;
}

我从 PHPUnit_Extensions_SeleniumTestCase 覆盖 onNotSuccessfulTest:

protected function onNotSuccessfulTest(Exception $e) {
    try {
        parent::onNotSuccessfulTest($e);
    }
    catch (PHPUnit_Framework_IncompleteTestError $e) {
        // Don't do anything with the incomplete test exception
        throw $e;
    }
    catch (PHPUnit_Framework_SkippedTestError $e) {
        // Don't do anything with the skipped test exception
        throw $e;
    }
    catch (Exception $e_parent) {
        // Include line number for specific test file in error
        $error_msg = chr(10).chr(10).$this->dumpStack($e);

        throw new PHPUnit_Framework_Error($e_parent->getMessage().$error_msg, $e_parent->getCode(), $e_parent->getFile(), $e_parent->getLine(), $e_parent->getTrace());
     }
}

我不喜欢这种 hack,所以如果有人有更好的解决方案,我很乐意听到!

更新: 我一开始忘记提到这一点:您当然必须让测试扩展您自己的自定义 SeleniumTestCase,而不是 PHPUnit_Extensions_SeleniumTestCase。

关于php - Selenium 不显示失败的数字行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9227232/

有关php - Selenium 不显示失败的数字行的更多相关文章

  1. ruby-on-rails - Rails 编辑表单不显示嵌套项 - 2

    我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib

  2. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  3. ruby-on-rails - 使用 Sublime Text 3 突出显示 HTML 背景语法中的 ERB? - 2

    所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择

  4. ruby-on-rails - link_to 不显示任何 rails - 2

    我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article

  5. ruby - 即使失败也继续进行多主机测试 - 2

    我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r

  6. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

  7. ruby - 查找字符串中的内容类型(数字、日期、时间、字符串等) - 2

    我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s

  8. ruby-on-rails - 复数 for fields_for has_many 关联未显示在 View 中 - 2

    目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi

  9. 区块链之加解密算法&数字证书 - 2

    目录一.加解密算法数字签名对称加密DES(DataEncryptionStandard)3DES(TripleDES)AES(AdvancedEncryptionStandard)RSA加密法DSA(DigitalSignatureAlgorithm)ECC(EllipticCurvesCryptography)非对称加密签名与加密过程非对称加密的应用对称加密与非对称加密的结合二.数字证书图解一.加解密算法加密简单而言就是通过一种算法将明文信息转换成密文信息,信息的的接收方能够通过密钥对密文信息进行解密获得明文信息的过程。根据加解密的密钥是否相同,算法可以分为对称加密、非对称加密、对称加密和非

  10. 「Python|Selenium|场景案例」如何定位iframe中的元素? - 2

    本文主要介绍在使用Selenium进行自动化测试或者任务时,对于使用了iframe的页面,如何定位iframe中的元素文章目录场景描述解决方案具体代码场景描述当我们在使用Selenium进行自动化测试的时候,可能会遇到一些界面或者窗体是使用HTML的iframe标签进行承载的。对于iframe中的标签,如果直接查找是无法找到的,会抛出没有找到元素的异常。比如近在咫尺的例子就是,CSDN的登录窗体就是使用的iframe,大家可以尝试通过F12开发者模式查看到的tag_name,class_name,id或者xpath来定位中的页面元素,会抛出NoSuchElementException异常。解决

随机推荐