c# - 使用 C# 在 Selenium WebDriver 中断言、验证和其他命令

标签 c# c#-4.0 automated-tests selenium-webdriver

我几乎搜索了所有与 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/

相关文章:

c# - 在 WP7 和 8 上递归删除 IsolatedStorage 中的目录的简便方法

c# - 同一 SPROC 的每次迭代执行时间变慢

c# - 如何在 C# 中声明一个 void 指针

testing - 无法将值传递给测试用例中的输入字段

c# - 我可以定义 2 个名称相同但参数不同的委托(delegate)吗?

c# - 在提供 ISigningCredentialStore 的自定义实现后,Identity Server 仍将内存中的 key 包含在发现文档中

asp.net-mvc-3 - 此版本的 SQL Server 不支持没有聚集索引的表

c#-4.0 - C# 4.0 AsParallel() 访问文件系统时出现UnAuthorizedAccessException

testing - 有没有办法在 TestCafe 中指定动态报告文件名

ruby - 如何通过 ruby​​ 将测试结果重定向到 txt 文件?