变量值测试
问题描述:
var vatDisplay = driver.FindElement(By.CssSelector("#tax-amount"));
Assert.AreEqual("£13.80", vatDisplay.Text);
我想以另一种方式来做到这一点类似的项目,而不是告诉变量值测试
Assert.AreEqual("£13.80", vatDisplay.Text);
我需要说的如果是vatDisplay.Text > £0.00
,我不知道该怎么做。 任何人都可以告诉我该怎么做。
预先感谢您
答
你可以parse the string value into a decimal然后验证结果值为正数:
var vatDisplay = driver.FindElement(By.CssSelector("#tax-amount"));
var culture = new CultureInfo("en-GB");
decimal amount;
if (!decimal.TryParse(vatDisplay, NumberStyles.Currency, culture, out amount))
{
Assert.Fail(
"{0} is an invalid currency and it cannot be verified that the amount is positive",
vatDisplay
);
}
Assert.IsTrue(amount > 0);
尤其在使用'Decimal.Parse'重载需要一个'NumberStyles'选项,以便你可以传递'NumberStyles.AllowCurrencySymbol'。 – Richard 2012-03-16 10:47:48
@理查德,是的,特别是。还应该使用'NumberStyles.Currency'。 – 2012-03-16 10:53:01
@Darin谢谢你的回复 – Leo 2012-03-26 09:33:49