【问题标题】:How to assert decimal Excel value with the web value using Selenium WebDriver?如何使用 Selenium WebDriver 用 Web 值断言十进制 Excel 值?
【发布时间】:2015-09-23 05:45:04
【问题描述】:

Excel 文件中提到的值为21.650,页面上显示的值相同。但是当脚本执行时,它将 Excel 值读取为21.65,我的断言条件变为 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();
}

【问题讨论】:

    标签: c# excel selenium-webdriver decimal data-driven


    【解决方案1】:

    在您的 Excel 文件中,将您的单元格类别更改为文本。

    【讨论】:

      【解决方案2】:

      按照This SO question 的答案中的建议使用 DataFormatter 类。因为这将返回 excel 文件中显示的确切文本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-03-16
        • 2017-05-26
        • 2016-07-16
        • 2023-04-04
        • 1970-01-01
        • 2022-01-19
        • 2019-05-08
        相关资源
        最近更新 更多