Пример #1
0
        public void Invalid_Credentials_Fails_To_Submit_Test_Request()
        {
            IWebPageTester gtMetrixObject = new GtMetrixTester("abc", "abc");
            var            request        = new TestRequestParameter("https://www.rsagroup.com/");
            var            resposne       = gtMetrixObject.SubmitTest(request);

            Assert.AreEqual(resposne.HttpStatusCode, HttpStatusCode.Unauthorized);
        }
Пример #2
0
        static void TestGetMetrix(string url)
        {
            IWebPageTester gtMetrixObject = new GtMetrixTester(_gtMetrixApiKey, _gtMetrixUserName);
            var            request        = new TestRequestParameter(url);
            var            resposne       = gtMetrixObject.SubmitTest(request);

            Console.WriteLine($"Success:{resposne.Success}");
            Console.WriteLine($"HttpStatusCode: {resposne.HttpStatusCode}");
            Console.WriteLine($"PollStateUrl: {resposne.PollStateUrl ?? string.Empty}");
            Console.WriteLine($"Error: {resposne.Error ?? string.Empty}");
            Console.WriteLine($"Id: {resposne.TestId ?? string.Empty}");
            Console.WriteLine($"Status: {resposne.Status ?? string.Empty}");
            Console.WriteLine($"------------------------------------------------------------");
            var          testId = resposne.TestId;
            TestResponse result = null;

            do
            {
                result = gtMetrixObject.GetResult(testId);
                Console.WriteLine($"Success:{result.Success}. Code: {result.HttpStatusCode}");
                Console.WriteLine($"Task Status:{result.TaskStatus}.");
                if (result.Success && result.TestCompelted)
                {
                    break;
                }
                Console.WriteLine($".....Sleeping for two seconds.....");
                Thread.Sleep(2000);
            }while (!result.TestCompelted && result.Success);
            Console.WriteLine($"Task Status:{result.TaskStatus}");
            Console.WriteLine($"resposne.Success:{result.Success}");
            Console.WriteLine($"PageBytes:{result.PageBytes}");
            Console.WriteLine($"PageLoadTime:{result.PageLoadTime}");
            Console.WriteLine($"PageElements:{result.PageElements}");
            Console.WriteLine($"ScreenshotUrl:{result.ScreenShotUrl}");
            Console.WriteLine($"ReportUrl:{result.ReportUrl}");
        }