开发者

How to properly check for server error within Watin integration test

I am trying to detect if a server error was encountered during a watin test. I had thought the below code would do the trick however, in usage I am getting an NRE during test execution on this line: (Text.Contains("Server Error")).

Any suggestions on what to do here? A try catch block of some sort seems to not be the right thing to do here.

Thanks.

public class WatinBrowser : IE
{
    public WatinBrowser(string url, bool createIn开发者_高级运维NewProcess) : base(url, createInNewProcess)
    {
    }

    public override void WaitForComplete(int waitForCompleteTimeOut)
    {
        base.WaitForComplete(waitForCompleteTimeOut);
        if (Text.Contains("Server Error"))
        {
            throw new ServerErrorException("A server error occured: " + Text);
        }
    }
}

public class ServerErrorException : Exception
{
    public ServerErrorException(string message): base(message)
    {
    }
}


I think the issue is that you're overriding the version which takes a timeout parameter. This means it's possible control returns to your code without a document being loaded.

I recommend either:

  1. Overriding the version of the method which doesn't take a timeout parameter
  2. Adding a null check before calling the Contains method.

Code example for (2):

if(this.Text == null) throw new TimeoutException();

if(this.Text.Contains("Server Error"))
{
    ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜