1

The value mentioned in the Excel file is 21.650 and same value is presented on the page. But when script executes, it reads Excel value as 21.65 and my assert condition becomes false.

List<string> rowValue = new List<string> { };
var ExcelFilePath = "D:\\testexcel.xlsx";

Excel.Application xlApp = new Excel.Application(ExcelFilePath);
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(ExcelFilePath);
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;

int rowCount = xlRange.Rows.Count;

for (int i = 1; i <= rowCount; i++)
{
    rowValue.Add(xlRange.Cells[i, j].Value2.ToString());

    IWebElement element = driver.FindElement(By.Id(weight_field));
    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);

    string weight = driver.FindElement(By.Id(weight_field)).Text;

    if (mpuid == i)
    {  
        Assert.AreEqual(weight,rowValue[0]);
        Console.WriteLine(" Expected Value: " + rowValue[0] + " is equal to Actual Value: " + weight);
        break;
    }

    rowValue.Clear();
}
halfer
  • 19,824
  • 17
  • 99
  • 186
geeta
  • 75
  • 1
  • 1
  • 8

2 Answers2

0

In your Excel file, change your cell Category as Text.

halfer
  • 19,824
  • 17
  • 99
  • 186
Mahsum Akbas
  • 1,523
  • 3
  • 21
  • 38
0

Use DataFormatter class as suggested in answer forThis SO question. As this will return the exact text from excel file as it is displayed.

Community
  • 1
  • 1
MKay
  • 818
  • 9
  • 32