Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对一个测试提出两个异常_C#_Selenium_Automation_Selenium Webdriver_Nunit - Fatal编程技术网

C# 对一个测试提出两个异常

C# 对一个测试提出两个异常,c#,selenium,automation,selenium-webdriver,nunit,C#,Selenium,Automation,Selenium Webdriver,Nunit,这是我的SeleniumWebDriver,带有c代码。 我正在同一测试中验证2个功能 我想为测试用例1和测试用例2提出单独的异常 那么如果,, Assert.IsTruedriver.IsElementPresentBy.LinkTextHelp;失败,我想引发一个异常,在该异常中,我将更新测试工具,说明测试用例1失败 如果其中一个 driver.FindElementdriver.IsElementPresentBy.LinkTextOk.Click; Assert.IsTruedriver

这是我的SeleniumWebDriver,带有c代码。 我正在同一测试中验证2个功能

我想为测试用例1和测试用例2提出单独的异常

那么如果,, Assert.IsTruedriver.IsElementPresentBy.LinkTextHelp;失败,我想引发一个异常,在该异常中,我将更新测试工具,说明测试用例1失败

如果其中一个 driver.FindElementdriver.IsElementPresentBy.LinkTextOk.Click; Assert.IsTruedriver.IsElementPresentBy.LinkTextLogged In; 失败,我想通过将测试用例2发送到另一个异常来更新我的工具,使其失败

在此方面的任何帮助都将不胜感激。。。。任何关于用一个异常处理这个问题的想法都可以

    [Test]
    public void TestTwo()
    {
        try
        {
    //open Page

            // test case 1
            Assert.IsTrue(driver.IsElementPresent(By.LinkText("Help")));

            // test case 2
            driver.FindElement(driver.IsElementPresent(By.LinkText("Ok")).Click();
            Assert.IsTrue(driver.IsElementPresent(By.LinkText("Logged In")));
        }


        catch (Exception e)
        {

            Console.WriteLine("FAILED");
        }


    }

如果我理解正确,您希望在测试运行报告中区分这两种情况中的哪一种失败

我想到的最简单的方法是使用失败消息作为断言的第二个参数


我在同一测试中验证2个功能是您的第一个问题,请将其分解为单独的测试。另外,为什么您认为您应该捕获并处理断言失败引发的异常?我不想运行它两次..这是我在上面的代码中提供的一个小示例,要到达测试用例1,大约需要3分钟。。。因此,为了运行从测试用例1结束的地方开始的测试用例2,我需要重新运行我想要处理异常的3分钟测试,因为我需要更新测试用例库工具中测试用例的通过/失败结果,。。因此,如果测试用例1失败,在异常1中,我告诉它将状态更改为failse。。同样地,对于例外2,这也确实不清楚,我同意这些评论,它们基本上是两个不同的测试用例,所以它们需要是两种不同的测试方法。您的代码,就像应用程序代码一样,应该写得很好,并且也应该遵循KISS原则之类的标准!给我们一个真实的例子来帮助我们理解这一点。当您的第一个断言失败时,测试会发生什么?测试停止了吗?它应该以失败告终吗?作为通行证?
// test case 1
Assert.IsTrue(driver.IsElementPresent(By.LinkText("Help")), "help link is missing");

// test case 2
Assert.IsTrue(driver.IsElementPresent(By.LinkText("Logged In")), "user is not logged in");