Skip to content
Advertisement

how to compare two numbers with selenium and java? (One number from CSV file and another in website)

I wrote a Program to compare prices in website with a csv file with selenium and java, at the end of program i wrote assert to confirm two numbers but it has a problem: expected price is 57,15
Actual price is 57.15

Actual Price should be 57,15 and i dont know how should i write that, Can you please help me?

@Test(priority = 1)
void checkBeschädigung() throws FileNotFoundException {
    prepareTest();
    List<CsvPrice> stuff = readFromCSV("resources/price/BikePrice.csv");

    
    Select price = new Select(driver.findElement(By.id("coverageSum")));
    price.selectByIndex(1);
    driver.findElement(By.xpath("//*[@id="landingApp"]/div[1]/div/div[2]/div/div/div/form/div[3]/div/div[2]/div[2]/div/label/input")).click();

    try {
        Thread.sleep(4000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    WebElement FirstPrice = driver.findElement(By.xpath("//*[@id='product-configurator-spinner']//parent::span"));
    String finalprice = FirstPrice.getText().split(" ")[0];
    System.out.println(finalprice);


    for (int i = 0; i <= 329; i++) {

        if (String.valueOf(stuff.get(i).getCoverageSum()).equals("250")
                && String.valueOf(stuff.get(i).getDurationStart()).equals("1") && stuff.get(i).getQualityName().equals("Diebstahl")
                && stuff.get(i).getDurationTimeUnit().equals("YEARS")) {
            System.out.println(stuff.get(i).getPriceBasePrice());
            Assert.assertEquals(finalprice, String.valueOf(stuff.get(i).getPriceBasePrice()));
            break;
        } else {
            System.out.println("that is wrong");
        }
    }

Advertisement

Answer

Please try below codes before assertion line to change “.” to “,” in your string data:

String actualValueWithComa = String.valueOf(stuff.get(i).getPriceBasePrice()).replaceAll(".",",");            
Assert.assertEquals(finalprice, actualValueWithComa));

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement