When talking about the automation test tool for web applications, Selenium often comes to mind. Selenium is a very popular open source tool used to test web applications, which supports most popular browsers like IE, Firefox, Safari, Chrome and Opera. I’ve been using Selenium 2 (Web Driver) for a few months now, and during this time, I found Selenium 2 really improved a lot comparing to Selenium 1. Here is a list of some useful Web Driver APIs and their usage that can resolve some issues we may have at the automation develop phase.
1) Takes Screenshot : takes screenshot when exceptions apply
When doing the automation test against web applications, we usually find that the element we try to find is not present. This may be caused by the UI change or may be because the page is not completely loaded, whatever the reason is, the automation script may fail and we need to figure out the exact reason. One possible solution is taking the error message we get in the log file, then analyze the error and predict the cause. Besides this, Selenium 2 provides a very useful API named TakesScreenshot which can take screenshots of current web pages in real time. Then you can clearly understand what the UI looks like at the moment the page is having errors by looking at the screenshot .
2) Web Driver Wait+ Expected Condition: wait until meeting the expected condition, otherwise wait until the timeout.
Another scenario we may come across during the automation test is that the UI element we try to find shows up quickly, and sometimes it may take more than one minute to display. The difficulty for us is determining how long to wait to get the element. One minute? Two minutes? That is really time consuming if the element is displayed quickly while we still need to wait for one minute or more. Rather that Selenium 1, Selenium 2 already takes this into consideration, Selenium API WebDriverWait in combination with Expected Condition is one way to resolve this issue. By using these two methods, we can have a step to find the UI element at regular intervals at regular intervals at regular intervals at regular intervals, for example, every 5 seconds, we try to find it, if it is found, then move on to next step, if it still can’t be found within the period we give, then we can fail this step and move to next one.
Nice post and i am really thankful to see that more and more people are working to make selenium more acceptable..
Hi Linda, thanks. I really like it and want more on this. Thanks.