简体   繁体   English

如何使用 c# 编写 selenium 脚本并使其自动化以查找网站的停机时间和正常运行时间?

[英]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.我是 selenium 和 c# 的自动化测试人员(不是最伟大的开发人员),但我的任务是找出网站的正常运行时间和停机时间。 Now I guess this script would be run everyday because my scripts run on a build server at 00.05am every night.现在我猜这个脚本会每天运行,因为我的脚本每天晚上 00.05 在构建服务器上运行。 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?他是怎么得到 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看看您是否可以捕获 Web 服务器日志并 grep 日志以查看正常运行时间和停机时间
  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.要求您的管理团队在网络服务器中安装一个监控系统,这将为许多问题提供更广泛的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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