Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.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# WatiN似乎没有找到JavaScript警报_C#_Watin - Fatal编程技术网

C# WatiN似乎没有找到JavaScript警报

C# WatiN似乎没有找到JavaScript警报,c#,watin,C#,Watin,我有一个web应用程序,在某些情况下,它会弹出JavaScript alert(),我需要在WatiN测试中对此作出反应。谷歌早在2007年就向我指出了这一点,这似乎很有希望,我将该帖子中的示例代码改编为以下内容(匿名): 但是,当调用DoWrong()时,警报几乎是即时显示的(正如预期的那样),对alertDialogHandler.WaitUntilExists()的调用最终失败,出现WatiNException:Dialog在10秒内不可用。。唯一的问题是,我可以看到对话框肯定出现在屏幕上

我有一个web应用程序,在某些情况下,它会弹出JavaScript alert(),我需要在WatiN测试中对此作出反应。谷歌早在2007年就向我指出了这一点,这似乎很有希望,我将该帖子中的示例代码改编为以下内容(匿名):

但是,当调用DoWrong()时,警报几乎是即时显示的(正如预期的那样),对alertDialogHandler.WaitUntilExists()的调用最终失败,出现
WatiNException:Dialog在10秒内不可用。
。唯一的问题是,我可以看到对话框肯定出现在屏幕上

我可能错过了一些简单的东西;有人能给我指一下正确的方向吗

我还尝试了以下两种变体,以及其中的一些变体,但运气不佳;我总是犯同样的错误

        AlertDialogHandler alertDialogHandler = new AlertDialogHandler();

        DoWrong(helper, false);

        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        stopwatch.Start();

        do
        {
        }
        while (!alertDialogHandler.Exists() && stopwatch.Elapsed.TotalMilliseconds < 3000);

        Assert.IsTrue(alertDialogHandler.Exists(), "No JavaScript alert when it should have been there");

        alertDialogHandler.OKButton.Click();
        SecondAssert(browser);

是的,我知道代码有点难看,但现在我主要是想让它工作。如果在我第二次尝试时,由于循环很紧,它以100%的利用率运行了几秒钟,但只执行了我需要的操作(简单明了,消除该警报()),那么就可以了。

这是WatiN和IE8的问题,IE8改变了它创建弹出窗口的方式。该问题已在项目的Sourceforge SVN存储库中可用的当前代码中修复。得到它,编译它,你的问题就解决了

WatiN的新版本将在今年年底前发布

嗯,,
Jeroen

这是WatiN和IE8的问题,IE8改变了它创建弹出窗口的方式。该问题已在项目的Sourceforge SVN存储库中可用的当前代码中修复。得到它,编译它,你的问题就解决了

WatiN的新版本将在今年年底前发布

嗯,,
Jeroen

等待10秒后,此警报对话框是否仍然可见?您是将WatiN与Internet Explorer一起使用还是与WebBrowser控件一起使用?是的,警报对话框将一直保持不动,直到我手动将其关闭,此时JavaScript中的警报()之后的代码才会执行。当然,当时的测试已经失败了。我正在将WatiN与MSIE一起使用。IE和Windows的版本是什么?32位MSIE 8.0.6001.18943更新版本:0,在Windows Server 2008 SP1 64位上。WatiN.Core.dll表示文件版本为2.0.0.1000。此外,如果我尝试手动解除警报,测试仍然失败(因为它从一开始就找不到警报对话框,导致Assert.IsTrue()或WaitUntilExists()调用引发异常)。等待10秒后,此警报对话框仍然可见吗?您是将WatiN与Internet Explorer一起使用还是与WebBrowser控件一起使用?是的,警报对话框将一直保持不动,直到我手动将其关闭,此时JavaScript中的警报()之后的代码才会执行。当然,当时的测试已经失败了。我正在将WatiN与MSIE一起使用。IE和Windows的版本是什么?32位MSIE 8.0.6001.18943更新版本:0,在Windows Server 2008 SP1 64位上。WatiN.Core.dll显示文件版本2.0.0.1000。此外,如果我尝试手动解除警报,测试仍然失败(因为它从一开始就找不到警报对话框,导致Assert.IsTrue()或WaitUntilExists()调用引发异常)。
        AlertDialogHandler alertDialogHandler = new AlertDialogHandler();

        DoWrong(helper, false);

        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        stopwatch.Start();

        do
        {
        }
        while (!alertDialogHandler.Exists() && stopwatch.Elapsed.TotalMilliseconds < 3000);

        Assert.IsTrue(alertDialogHandler.Exists(), "No JavaScript alert when it should have been there");

        alertDialogHandler.OKButton.Click();
        SecondAssert(browser);
        AlertDialogHandler alertDialogHandler = new AlertDialogHandler();
        browser.DialogWatcher.Add(alertDialogHandler);
        DoWrong(helper, false);
        alertDialogHandler.WaitUntilExists();
        alertDialogHandler.OKButton.Click();
        browser.WaitForComplete();
        Assert.IsFalse(alertDialogHandler.Exists());
        SecondAssert(browser);