简体   繁体   中英

How can I write a selenium script with c# and automate it to find the downtime and uptime of a website?

I am an automated tester in selenium and c# (not the greatest developer) but I have been tasked to find out the uptime and downtime of the website. Now I guess this script would be run everyday because my scripts run on a build server at 00.05am every night. So my question is how do I get the numbers? I have found a pretty good post on here which is similar but what I don't understand is, how to get the availability/uptime over a period of time? How did he get 86400)/100) * 97.91m? Check out the code guys

 CultureInfo provider = CultureInfo.InvariantCulture;

 DateTime first = DateTime.ParseExact("20.04.2015", "dd.MM.yyyy", provider);
 DateTime last = DateTime.ParseExact("26.04.2015", "dd.MM.yyyy", provider);

 TimeSpan time = last - first;

 decimal secondsUptime = ((time.Days * 86400)/100) * 97.91m;  //97.91 is the uptime calculated above for the time period. 

 // The problem is how to get this?

 decimal secondsDowntime = ?

So the guy had problems getting the downtime and the posts answer was this:

decimal PercentDownTime = 100 - PercentUpTime;
decimal SecondsUpTime = (time.Seconds / 100) * PercentUpTime;
decimal SecondsDownTime = (time.Seconds / 100) * PercentDownTime;

This is ideally a monitoring problem. You may not need selenium for this. Few ways could be

  1. See if you can capture the web server logs and grep the logs to see the uptime and downtime
  2. You can write a tool which keeps polling the website and record if it is sending you the right response or not. Based on the response you can decide the uptime and downtime.
  3. Ask your admin team to install a monitoring system in the webserver which will have much more wider soltuion for many problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM