Http://blog.sina.com.cn/s/blog_c189e2590102w3bv.html
Selenium (webdriver) Automated test Frequently asked questions
(1) How to ensure the success rate of the operation element in selenium? So how do I ensure that the element I clicked on must be clickable?
A: Selenium to ensure that element success rate is through the positioning of elements, of course, its positioning methods are many, must be suitable. However, in the implementation of automation engineering, high-quality automated testing is not the only Test personnel guarantee. Developers are required to standardize development practices, such as adding unique name,id to page elements, which can greatly improve the accuracy of element positioning. Of course, if developers develop non-standard, we try to use relative address positioning when locating elements, which can reduce the influence of element positioning by page changes. As long as our elements are positioned accurately, it will ensure that every operation I make is consistent with my expectations.
(2) How can I increase the execution speed of selenium scripts?
A: The execution speed of the selenium script is influenced by many factors, such as the speed of the network, the complexity of the operation steps, the rate of page loading, the waiting time we set in the script, the number of threads running the script, etc. Therefore, we can not pursue the speed of the unilateral, to ensure stability, to achieve a stable regression test is the key.
We can improve speed from the following aspects:
One, reduce the steps, such as after three or four steps to open the page we want to test, we can directly through the URL to open, reduce unnecessary operations.
Two, break the page load, if the page loading too much content, we can see the reason for the slow loading, if the loaded content does not affect our testing, set the time-out period, interrupt page loading.
Three, when setting the waiting time, you can sleep fixed time, you can also detect an element after the occurrence of an interrupt wait can also increase the speed.
Four, configure testng to implement multithreading. When writing test cases, be sure to achieve loose coupling, and then the server allows to set up multi-threaded operation, improve execution speed.
(3) Use cases in the operation of the process often appear unstable situation, that is, this can pass, the next time there is no way to pass, how to improve the stability of use cases?
A: At this point we have to analyze the causes of instability, and then targeted to solve the problem. There are several main aspects:
One, the network speed problem: Sometimes the page load is relatively slow, in the execution of the program to operate the elements are not displayed. This situation is more common, run a good time to pass the network, and then run again, the page is not open, will not pass. In order to improve stability, we can only sacrifice the elapsed time, before the element that often detects the failure, plus the wait time, and so on, and then perform the following operation.
Second, the reason for Selelnium: Selenium1.0 and 2.0 are still different, some of the functions in the 2.0 run does have sometimes effective, when the surface is invalid. If the mouseover () function, which is the case, we need to avoid the use of such functions.
Three, multi-threaded, test cases between the interaction. Although multi-threading time is faster, if the coupling between use cases is not well designed, it will affect the use case B when it is executed before use case B, and vice versa. In this case, if your automated test project is intended to be multithreaded, it is necessary to compare the test case test with the coupling degree, as far as possible, because the order of execution of multithreading is not controlled.
(4) What is the execution strategy for your automation use case?
A: The execution strategy for automated test cases is to look at the purpose of automated testing, usually with the following strategies:
First, automated test cases are used to monitor, and in this case, we set up automated test cases to execute on a timed basis, and if executed every five minutes or one hours, create a timed task on Jenkins.
Two, the use case must return. Some of the test cases, such as BVT test cases, we need to return to execution before any changes to the company's products go live. Then we set the test case to trigger execution and bind our automated test task to the development build task on Jenkins. Our automated test cases are triggered when the developer is in the upper code of the simulation environment.
Third, test cases that do not need to be executed frequently. Like a full-scale test case, we do not have to go back to the execution, there will be time consumption, some non-main lines of business do not need to always return. This kind of test case we use manual execution, in Jenkins to create a task, need to execute when the human to build.
Selenium (webdriver) Automated test Frequently asked questions