java - cucumber-Junit 断言失败 - 无法断言 '£' 符号

标签 java selenium junit cucumber assertions

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

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); 
    .........

最佳答案

您可能遇到字符集不匹配的情况。 Cucumber troubleshooting guide记录需要采取的几个步骤。以下两个可能与您的情况最相关:

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

关于java - cucumber-Junit 断言失败 - 无法断言 '£' 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26816661/

相关文章:

java - Hibernate 记录 native sql 查询

java - 如何使用规范在mysql查询中使用多个 "OR"条件创建两个 "AND"条件

java - 带有 HTMLUnitDriver 的 Selenium 3.0.x

maven - 使用 Maven 运行 JUnit 测试套件

java - 如何初始化模拟对象?

java - 压缩会提高性能吗?

Java 通用堆栈错误

java - 使用 selenium 将基于关键字的 Excel 表测试用例作为 TestNG 测试用例执行

java - Selenium:元素定义的优化(页面对象)

java - JUnit 如何使用参数对象的不同值进行模拟?