Пример #1
0
        public void TestCleanup()
        {
            ResultState testResult = TestContext.CurrentContext.Result.Outcome;

            if (testResult.Equals(ResultState.Failure) || testResult.Equals(ResultState.Error))
            {
                string screenshotName = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-ffff") + "_" + TestContext.CurrentContext.Test.MethodName + ".jpeg";
                string screenshotPath = AppSettings.Instance.ScreenshotDirectory + @"\" + screenshotName;
                TakeScreenshot(screenshotPath);
                TestContext.AddTestAttachment(screenshotPath, "screenshot");
            }
            Driver.Quit();
            TestPropertiesStorage.Instance.Remove(TestContext.CurrentContext.Test.ID);
        }
Пример #2
0
 private Image ImageResult(ResultState resState)
 {
     Image image = new Image();
     if (resState.Equals(ResultState.Success))
     {
         image.ImageUrl = "~/img/passed.png";
     }
     else if (resState.Equals(ResultState.Ignored))
     {
         image.ImageUrl = "~/img/Ignored.png";
     }
     else
     {
         image.ImageUrl = "~/img/failed.png";
     }
     return image;
 }
Пример #3
0
        public void TestEquality_Null()
        {
            var rs = new ResultState(TestStatus.Passed);

            Assert.AreNotEqual(null, rs);
            Assert.AreNotEqual(rs, null);
            Assert.False(rs.Equals(null));
        }
Пример #4
0
        public void TestEquality_WrongType()
        {
            var rs = new ResultState(TestStatus.Passed);
            var s  = "123";

            Assert.AreNotEqual(rs, s);
            Assert.AreNotEqual(s, rs);
            Assert.False(rs.Equals(s));
        }
Пример #5
0
        public static void MarkTestStatusOnBrowserStack(RemoteWebDriver driver, ResultState outcome, string message)
        {
            if (IsCloud == false)
            {
                throw new Exception("You are not testing on the cloud");
            }

            string status = "failed";

            if (outcome.Equals(ResultState.Success))
            {
                status = "passed";
            }

            JObject json = new JObject();

            json["status"] = status;
            json["reason"] = message;
            string reqString = json.ToString();

            SessionId sessionId = driver.SessionId;

            byte[]         requestData      = Encoding.UTF8.GetBytes(reqString);
            Uri            myUri            = new Uri($"https://www.browserstack.com/automate/sessions/{sessionId.ToString()}.json");
            WebRequest     myWebRequest     = HttpWebRequest.Create(myUri);
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)myWebRequest;

            myWebRequest.ContentType   = "application/json";
            myWebRequest.Method        = "PUT";
            myWebRequest.ContentLength = requestData.Length;
            using (Stream st = myWebRequest.GetRequestStream()) st.Write(requestData, 0, requestData.Length);

            NetworkCredential myNetworkCredential = new NetworkCredential(Config.BrowserstackUsername, Config.BrowserstackAccessKey);
            CredentialCache   myCredentialCache   = new CredentialCache();

            myCredentialCache.Add(myUri, "Basic", myNetworkCredential);
            myHttpWebRequest.PreAuthenticate = true;
            myHttpWebRequest.Credentials     = myCredentialCache;

            myWebRequest.GetResponse().Close();
        }