gpt4 book ai didi

c# - 错误 : The Name Assert Does Not Exist In The Current Context

转载 作者:行者123 更新时间:2023-11-30 21:43:12 25 4
gpt4 key购买 nike

我已经编写了一些代码来验证用户是否可以登录酒店预订平台,并且我还添加了一个验证步骤。我得到一个错误在 Assert.IsTrue() 方法上。代码中的其他一切都很好。

我在拜访之前针对可能的解决方案做了一些研究。

这是我在 StackOverflow 上找到的解决方案:Assert Method Error

我已将 Microsoft.VisualStudio.QualityTools.UnitTestFramework 添加到我的项目引用中,并且还添加了

使用 Microsoft.VisualStudio.TestTools.UnitTesting; & 使用 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

删除绑定(bind)后出现同样的错误 - Microsoft.VisualStudio.TestTools.UnitTesting; & 使用 NUnit.Framework。

最后是代码:

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.");

}
}
}

感谢您的帮助。

最佳答案

建议:

  1. 您正在尝试编写单元测试,但是是在主程序上而不是在单元测试项目中?创建单元测试项目。 see here .

  2. 您正在尝试同时使用 NUnit 和 Microsoft 单元测试框架?选择其中之一,而不是两者。

关于c# - 错误 : The Name Assert Does Not Exist In The Current Context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41916679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com