Assert.IsTrue()
方法中遇到了错误。代码中其他的东西都没问题。在停留之前,我进行了一些搜索以寻找可能的解决方案。
以下是我在 StackOverflow 上找到的解决方案:Assert Method Error 我已将 Microsoft.VisualStudio.QualityTools.UnitTestFramework 添加到我的项目引用中,并且还添加了
using Microsoft.VisualStudio.TestTools.UnitTesting;
和 using NUnit.Framework;
到我的使用代码部分。我得到了以下错误:
删除绑定后,我仍遇到相同的错误 - Microsoft.VisualStudio.TestTools.UnitTesting; & using NUnit.Framework。Severity Code Description Project File Line Suppression State Error CS0234 The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) PremierInn_Valid_User_Login c:\users\XXXX\onedrive\documents\visual studio 2015\Projects\PremierInn_Valid_User_Login\PremierInn_Valid_User_Login\Program.cs 5 Active
Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?) PremierInn_Valid_User_Login c:\users\XXXX\onedrive\documents\visual studio 2015\Projects\PremierInn_Valid_User_Login\PremierInn_Valid_User_Login\Program.cs 6 Active
最后,以下是代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System.Threading.Tasks;
namespace PremierInn_Valid_User_Login {
class Program {
static void Main(string[] args) {
//Instantiate Firefox Driver
var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("https://secure.premierinn.com/en/mypremierinn/home.action");
//Enter User Name - My Email Address
var user = driver.FindElement(By.Id("loginForm.username"));
user.SendKeys("abcdefg@gmail.com");
//Enter Password - Account Pasword
var pass = driver.FindElement(By.Id("loginForm.password"));
pass.SendKeys("Testing123");
//Click on Login button
driver.FindElement(By.Id("loginForm.button")).Click();
var loggedInHeader = driver.FindElement(By.Id("body-inner"));
Assert.IsTrue(loggedInHeader.Displayed, "The user was able to successfully login.");
}
}
}
感谢你的帮助。