Java 如何在断言中将字符串转换为int

Java 如何在断言中将字符串转换为int,java,string,int,assert,Java,String,Int,Assert,Assert无法找到值,因为它需要一个字符串,但存在一个整数。如何将此字符串转换为整数 我尝试使用Integer.parseInt(number),但被忽略 下面是我的代码 @Then("^User assert \"([^\"]*)\" and \"([^\"]*)\"$") public void userAssertAnd(String Qty, String Price) { String Quantity = driver.findElement(By.xpath("//tr

Assert无法找到值,因为它需要一个字符串,但存在一个整数。如何将此字符串转换为整数

我尝试使用Integer.parseInt(number),但被忽略

下面是我的代码

@Then("^User assert \"([^\"]*)\" and \"([^\"]*)\"$")
public void userAssertAnd(String Qty, String Price)  {
    String Quantity = driver.findElement(By.xpath("//tr[@class='GEHR2AJDIL']/td[8]/div/input[@class='form-control']")).getText();
    AssertJUnit.assertEquals(Quantity, Qty);

    String modifierPrice = driver.findElement(By.xpath("//tr[@class='GEHR2AJDIL']/td[9]/div/input[@class='form-control GEHR2AJDHI']")).getText();
    AssertJUnit.assertEquals(modifierPrice, Price);

错误:应为:但为:

因此120是数量,此处数量定义为字符串。因此,您需要将数量转换为字符串,如下所示:

String Quantity = String.valueOf(driver.findElement(By.xpath("//tr[@class='GEHR2AJDIL']/td[8]/div/input[@class='form-control']")).getText());

Price
在这里似乎是
null
。Price实际上是一个值,是数量还是价格?从这个“错误:预期的:但是是:“@AkhilMenon 120是数量,价格是R 355.60我仍然得到错误:java.lang.AssertionError:预期的:但是是: