Some experience browser experience sporadic automated 10 stability

Browser automation program, feeling the most difficult is stability. To realize an unattended automatic execution, particularly in the network is not good continuous non-stop running 8 hours, or longer, is not easy. Because many unpredicted abnormal situation. Do the following helpful:

1) If you are debugging in visual studio, should Debug - Exceptions - Managed Debugging Assistants - ContextSwitchDeadLock of Thrown tick removed, to avoid running into the half, the sudden appearance of a prompt, interrupt program execution.

2) If you are using webBrowser control, ScriptErrorsSuppressed be set to true, to avoid unexpected js error, interrupt program execution.

3) If selenium, remember driver can easily throw an exception, those who have driver's place, even if it is generally not easy to place driver.PageSource so abnormal, but also coupled with try catch, Caution is the ship. driver.Close () must be added try catch. When network conditions are poor, it is prone to time-out, but also to try catch live.

4) pay attention to the delay. Such as IO operations, selenium in the open a new page with javascript, would require a delay. If timer too much trouble, use Thread.Sleep. Anyway, the purpose of automatic unattended execution, so blocking the interface is not a problem.

5) Remember the case of poor network conditions, and any page may be a variety of abnormalities, such as whole pages are not eligible, browser blank page; half load; for a long time to load, does not always end; etc. Wait. So with javascript, webBrowser control, or when taking selenium elements, we must first detect the presence of, can not be taken for granted, in order to avoid because they can not abnormal.

At the same time, take time every page, every page is loaded completely detected. My approach is to find whether there is an element, if it is assumed that there is a whole page has loaded.

6) If you use a proxy server problems that may occur even more. For example, the header can not just add httprequest, take a variety of unexpected error page may appear, and so on. When using a proxy server to take a page, must be constantly detecting element is present, the addition of suitable retry mechanism.

7) unexpected prompt, confirm window is very annoying. Selenium, if used, can be added to an appropriate detection mechanism,

8) The basic principle is that all possible exceptions catch live, and to add an appropriate retry mechanism. To add an appropriate retry delay. For example, a page does not open, try not continuous, but after a few seconds delay to try again, with much better results.

9) Be sure to a lot of testing. For example, do book download programs, do not think you can download the twelve, dozen, even if you're done. 8 hours or normal operation, or continuously downloaded without errors hundreds present, generally considered pass.

Guess you like

Origin www.cnblogs.com/badnumber/p/12078540.html