Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.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# Assert.Pass使我跳出了循环。无法生成输出_C#_Visual Studio 2010_Nunit - Fatal编程技术网

C# Assert.Pass使我跳出了循环。无法生成输出

C# Assert.Pass使我跳出了循环。无法生成输出,c#,visual-studio-2010,nunit,C#,Visual Studio 2010,Nunit,我正在使用C#、VSTS2010、Nunit和.Resx文件作为数据源自动化Web应用程序。 能够从资源文件中成功拾取数据。在生成结果时,在使用Assert.Pass(“”)时,如果通过,则会使我脱离循环。不知道如何产生结果,在哪里?请帮助我 foreach (string from1 in from) { foreach (string to1 in To) {

我正在使用C#、VSTS2010、Nunit和.Resx文件作为数据源自动化Web应用程序。 能够从资源文件中成功拾取数据。在生成结果时,在使用Assert.Pass(“”)时,如果通过,则会使我脱离循环。不知道如何产生结果,在哪里?请帮助我

    foreach (string from1 in from)
            {
                foreach (string to1 in To)
                {
                    driver.Navigate().GoToUrl(www.xyz.com);
                    System.Threading.Thread.Sleep(5000);
                    driver.FindElement(By.Id("tbFrom")).Clear();
                    driver.FindElement(By.Id("tbFrom")).SendKeys(from1);
                     driver.FindElement(By.Id("tbTo")).Clear();
                     driver.FindElement(By.Id("tbTo")).SendKeys(to1);
             if (driver.FindElement(By.Id("trAirLines")).Text.Contains("Air Canada"))
                    {
                       Assert.Pass("Air Canada Results are available")
                    }
         else
               {
                   Assert.Fail("AC not found")
               }
                }

当我删除Assert语句时,所有迭代都会完成,否则当它变为pass时就会失败

您不能调用
Assert.pass()
。这将立即中止测试的执行。因此,
Assert.Fail()

我认为你能相处的最好的事情是:

foreach (string from1 in from)
{
    foreach (string to1 in To)
    {
        driver.Navigate().GoToUrl(www.xyz.com);
        System.Threading.Thread.Sleep(5000);
        driver.FindElement(By.Id("tbFrom")).Clear();
        driver.FindElement(By.Id("tbFrom")).SendKeys(from1);
        driver.FindElement(By.Id("tbTo")).Clear();
        driver.FindElement(By.Id("tbTo")).SendKeys(to1);

        var infoElement = driver.FindElement(By.Id("trAirLines"));
        Assert.That(infoElement.Text, Is.StringContaining("Air Canada"));
    }
}

断言。。。Is.StringContaining
检查引用元素的文本是否包含
“加拿大航空公司”
。现在,测试将在第一个不满足此断言的元素上失败,否则将明显通过。

您的意思是,您有一个循环,其内部主体调用了
Assert.pass
Assert.Pass()
将立即结束测试,因为它会引发异常。你能提供一些代码吗?请找到上面的代码