【问题标题】:cucumber-Junit Assertion fails - It's not able to assert '£' sybmolcucumber-Junit 断言失败 - 它无法断言“£”符号
【发布时间】:2014-11-08 11:32:56
【问题描述】:

我编写了一个黄瓜功能,它导航到一个网站,搜索一些手机并从结果集中验证手机的价格。但是,断言失败并显示以下错误消息:

java.lang.AssertionError: Price is incorrect expected: < ?508.00> but was:<£508.00>

你能帮我解决它吗?

我正在使用以下库:

junit-4.11
cucumber-core-1.1.5
cucumber-html-0.2.3
cucumber-java-1.1.5
cucumber-junit-1.1.5
cucumber-jvm-deps-1.0.3
gherkin-2.12.1
hamcrest-all-1.3
selenium-server-standalone-2.43.1

功能文件:

Feature: **** 
    phone search and price check feature

Scenario: 

Given I am on  ****** site
When I search for an iPhone
Then I should see the results showing phones at correct prices
  | Results | Price    |
  | record1 | £508.00 |
  | record2 | £415.00 |
  | record3 | £364.99 |
  | record4 | £418.00 |
  | record5 | £421.00 |

StepDefinition 文件的摘录:

.......

@Then("^I should see the results showing phones at correct prices$")
public void validateTheResults(DataTable table) throws Throwable {

    List<List<String>> data = table.raw();

    price = driver.findElement(By.xpath("//li[@id='result_0']/div/div/div/div[2]/div[2]/div[1]/div[1]/a/span")).getText();
    System.out.print("Price1 = " +price);
    assertEquals("Price is incorrect",data.get(1).get(1),price); 
    .........

【问题讨论】:

    标签: java selenium junit cucumber assertions


    【解决方案1】:

    您可能遇到字符集不匹配的情况。 Cucumber troubleshooting guide 指出要采取的几个步骤。这里有两个可能与您的情况最相关:

    1. 确保您的 .feature 文件保存为 UTF-8
    2. require 'cucumber/formatter/unicode' 添加到您的env.rb 文件中

    【讨论】:

      猜你喜欢
      • 2015-01-10
      • 1970-01-01
      • 2012-12-04
      • 1970-01-01
      • 2011-05-27
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      相关资源
      最近更新 更多