c#4.0-使用c#在Selenium WebDriver中执行Assert、Verify和其他命令
本文关键字:Assert Verify 命令 其他 执行 使用 WebDriver Selenium c#4 | 更新日期: 2023-09-27 17:57:47
我几乎搜索了所有与Selenium WebDriver相关的论坛/网站,但仍然找不到如何使用C#在Selenium Web Driver中使用断言和验证的解决方案。
这是我的代码,我只想在下面写的代码中放一个示例断言。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace Healthfleet
{
class Login
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver(@"D:'Downloads");
driver.Navigate().GoToUrl("https://test.com/");
IWebElement username = driver.FindElement(By.Id("username"));
IWebElement password = driver.FindElement(By.Id("password"));
username.SendKeys("test@test.test");
password.SendKeys("test");
IWebElement loginButton = driver.FindElement(By.Id("Login"));
loginButton.Click();
}
}
}
我需要使用断言来检查username=test,但我找不到任何Assert类或方法。
我是否缺少包含Assert类或任何其他想法的名称空间?
NUnit需要进行测试。你必须添加它的dll,然后添加命名空间作为
using NUnit.Framework;
目前您已经编写了管理浏览器的程序。如果您将添加来自NUnit的断言,它将在失败的情况下抛出异常。
如果你想创建测试,你应该创建没有static void Main(string[] args)
的类,但添加一些用[Test]
标记的方法。我建议您学习xUnit系统的概念,尤其是NUnit。