Friday 23 February 2018

Selenium Wrapper Automation

Selenium Wrapper automation is not any automation technique or framework it is just strategy which used in creation of automation framework.

Lets understand selenium wrapper automation with example.

when we are going to click any element using automation then we have to first check weather that element is present on page or visible or not. Once element is visible on page then after we can click on that element.
'Click on Element' event is common event in any automation.

Now assume that you have a scenario for automation and in that scenario you have to perform 5 or more time use 'Click on element' event. So, every time you have to first check weather element is present or not otherwise selenium will throw 'Element Not Found' exception.

So, rather than checking every time element present or not and wait till element visible we can create one function which perform both the thing on once go.
1. Check Element visible or not and if not then wait till some specific time
2. Click on element once it is visible

Thats called selenium wrapper automation.

It is so easy!! right?

you can also do same thing for many automation events which is common like drop down events, element visible or not etc.

You can use below function for click event into your automation framework.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public boolean clickOnElement(WebDriver driver, WebElement vElement)
    {
     boolean bClickOnElement = true;

        final int WAIT_TIME = 3;  // this is in seconds
        final int MAX_RETRIES = 5;
        
        //WebDriverWait by default calls the ExpectedCondition every 500 milliseconds until it returns 

successfully. 
        // The max wait time is 15 seconds(3 seconds with 5 retries)
        
        WebDriverWait wait = new WebDriverWait(driver, WAIT_TIME);
        int retry = 0;
        while (true)
        {
            try
            {
             wait.until(ExpectedConditions.visibilityOf(vElement)).click();
                return bClickOnElement;
            }
            catch (Exception e)
            {
                if (retry < MAX_RETRIES)
                {                 
                    retry++;
                    continue;
                }
                else
                {                 
                 bClickOnElement = false;
                 throw new ElementNotVisibleException("Click on Element failed");
                 
                }
                
            }
        }
    }


If you want to do selenium wrapper automation for drop down then please click in below link

Drop down using Selenium Wrapper

Driver Wrapper Automation

Database Operations



No comments:

Post a Comment

Popular