集成测试HTML特殊字符 [英] Integration Testing HTML Special Characters

查看:249
本文介绍了集成测试HTML特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有点奇怪,但在我看来,我有一个勾号(✔)和一个十字(×)用作链接(代替图像)。有没有什么方法可以找到这些元素,并使用RSpec和Capybara-webkit进行测试,或者我应该尝试和定位title属性来代替并忽略此路线?



我的有问题的测试如下所示:

  contextcast a vote,js:true do do $ b之前的
$ b sign_in user
click_link'✔'
sleep 0.2
end

it {should have_content(Vote cast!)}
结束

我得到的失败消息是(可预测的):

 失败/错误:click_linkraw('✔')
Capybara :: ElementNotFound:
无法找到链接 raw('✔')

非常感谢您的帮助。

解决方案

Capybara没有看到HTML,它通过DOM运行,然后看到这些东西编码的实际值。您必须将原始代码作为包含代码点本身的UTF- {8,16}字符串发送。

大多数语言都会显示HTML ' ✔'作为\\\က4,所以试试。


Kind of a strange one, but in my views I have a tick (✔) and a cross (×) used as links (in lieu of images). Is there any way of finding these elements and testing them using RSpec and Capybara-webkit, or should I try and target say the title attribute instead and ignore this route?

My test in question looks like this:

context "casting a vote", js: true do
  before do
    sign_in user
    click_link '✔'
    sleep 0.2
  end

  it { should have_content("Vote cast!") }
end

The failure message I get is (predictably):

Failure/Error: click_link "raw('✔')"
Capybara::ElementNotFound:
Unable to find link "raw('✔')"

Thanks in advance for your help.

解决方案

Capybara doesn't see the HTML, it runs thru the DOM, which then sees the actual values those things encode. You must send the raw code as a UTF-{8,16} string containing the code point itself.

Most languages would present an HTML '✔' as "\u10004", so try that.

这篇关于集成测试HTML特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆