我几乎搜索了所有与 Selenium WebDriver 相关的论坛/网站,但仍然无法找到如何使用 C# 在 Selenium WebDriver 中使用断言和验证的解决方案。
这是我的代码,我只想在下面编写的代码中放置一个示例断言。
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 类或任何其他想法的 namespace ?
最佳答案
NUnit需要对此进行测试。你必须添加它的 dll,然后将命名空间添加为
使用 NUnit.Framework;
关于c# - 使用 C# 在 Selenium WebDriver 中断言、验证和其他命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14722641/