예제 #1
0
        public override bool Execute()
        {
            int numberOfAttemptsMade = 0;
            while (numberOfAttemptsMade < MaxNumberOfAttempts)
            {
                try
                {
                    WebRequest request = new WebRequest(Url, TimeoutInSeconds * 1000);

                    if (request.Response.Contains(TextThatMustBeInResponse))
                    {
                        if (this.BuildEngine != null) Log.LogMessage("Attempt " + (numberOfAttemptsMade + 1) + ": Success - text '{0}' found at {1}", TextThatMustBeInResponse, Url);
                        return true;
                    }
                    else
                    {
                        if (this.BuildEngine != null) throw new Exception(String.Format("Text '{0}' not found at {1}", TextThatMustBeInResponse, Url));
                    }
                }
                catch (Exception ex)
                {

                    Log.LogError("Attempt " + (numberOfAttemptsMade + 1) + ": Error occured accessing '{0}':\n{1}", this.Url, ex.ToString());
                    this.Log.LogErrorFromException(ex);
                }
                numberOfAttemptsMade++;
            }
            return false;
            
        }
예제 #2
0
		public void CheckThatPageLoads()
		{
			Uri uri = SpottedTests.Site.Uri;
			int maxTries = 3;
			int thisTry = 0;
			bool success = false;
			try
			{
				while (thisTry < maxTries && !success)
				{
					WebRequest request = new WebRequest(uri, 120*1000);
					success = request.Response.Contains(TextThatShouldBeOnThisPage);
					thisTry++;
				}
				Assert.IsTrue(success, "Could not access " + uri.ToString());
			}
			catch (Exception ex)
			{
				Assert.Fail("uri: " + uri.ToString() + "\nMessage: " + ex.Message);
			}
		}