我有我的WebDriver腳本檢查,我在哪裏拉出一個日期字段的頁面。爲什麼AreEquals說在兩個雙引號中有兩個值不正確?
IWebElement crInfo = driver.FindElement(By.Id("crInfo"));
string copyDate = crInfo.Text;
// From the converted string now pulling out the year by index and length
string copyYear = copyDate.Substring(2, 4);
// Get the current year
int nowYear = DateTime.Today.Year;
// Converting the year
nowYear.ToString().Trim();
// Make the comparison to be sure the copyright is using the current date
Assert.AreEqual(copyYear,nowYear);
正如片段注意什麼,我試圖做的是確認,出現在頁面上的日期是當前年份,這只是一個web前端檢查落實到位函數返回正確的價值。當我運行這雖然是我在NUnit的控制檯中看到的是:
error: Expected: "2012" But was: 2012
我真的不明白兩者之間的區別,是引用值的字符串?我在腳本中添加了轉換,以確保它們是相同的類型,並在可能存在空白的情況下添加修剪。
如果我想完成這項工作,我沒有做什麼來讓評估通過?
因爲一個String <>到一個Int – MethodMan 2012-08-09 16:46:58
一個是字符串,另一個是int? – Alxandr 2012-08-09 16:47:05
你需要將日期轉換爲字符串表示使用.ToString()將日期轉換爲字符串。表示 – MethodMan 2012-08-09 16:48:02