Pages

Thursday, 29 December 2011

How to Accept Self-Signed SSL Certificates in Selenium


Accessing pages with self-signed SSL certificates in Selenium can be a bit tricky. The core of the issue is every major browser raises a security issue when accessing a page using a self-signed SSL certificate. Since this security check takes effect before the Selenium Javascript can execute, there's no way to instruct the browser to accept the certificate.


Selenium as a Proxy Server

As it turns out, there is a solution built into Selenium, but there's some work involved to get it going properly. Unless you use the -avoidProxy argument when you start up the Selenium server, it will serve as a proxy for connections originating on localhost. If you start the Selenium server with the -trustAllSSLCertificates argument the proxy will be able to handle any type of SSL certificate issue for any site. The corollary to using Selenium server as a proxy is that your browser sessions need to be configured to use the Selenium server as a proxy. It should be noted that this is not the same as proxy injection mode; Selenium is not injecting itself into your page, it's simply proxying the content for you.

Configuring the Selenium Browser Launchers

You configure the browser's proxy settings through the browser launcher. Some of the provided launchers do this already. For Internet Explorer you can use the *iexploreproxy launcher and for Firefox you can use the *firefoxproxy launcher. Another option is to use a custom browser launcher. We do this with both Firefox and Internet Explorer and the code can be found on our GitHub repository.
We found the default chrome launcher for Firefox is very close to what we want and didn't want to have to manage our own custom profiles. So we use that launcher as a base and modified it such that if Selenium server is started with -trustAllSSLCertificates option then then generated Firefox profile will set up the Selenium server as the proxy. The patch actually modifies the *firefox launcher, but a custom launcher is likely a safer option for you.
The reason we use a custom launcher with Internet Explorer is that we've experienced reliability issues with the *iexploreproxy launcher. We've found *iexplore to be more reliable so our custom launcher simply configures Internet Explorer to use Selenium as its proxy server and then uses HTA to perform the browser automation functions, similar to how *iexplore operates. The code for this launcher is also available in our GitHub repository.
An extra step is required for proxying SSL content with Internet Explorer. Selenium bundles a special certification authority (CA) certificate that is used to trust all the other SSL certificates. Windows will not trust this CA certificate until it is installed in the trusted root store.

Installing the CyberVillains Certificate on Windows

The following figures show the steps necessary to install the CyberVillains certificate on Windows. This is only necessary if you're using Internet Explorer. Selenium is able to manipulate Firefox to trust the certificate with its custom-built profile.
The CyberVillains certificate is bundled in the most recent Selenium RC releases. If you download the distribution and extract it, you should be able to get going starting with Figure 1. In the explorer address bar in Figure 1 you can see where to find the certificate. You must substitute the base path (C:\, here) with wherever you extracted the files.
Figure 1: Double-click the CyberVillains certificate in the selenium server distribution.
Figure 2: Install the CyberVillains certificate.
Figure 3: Click through the SSL certificate import wizard.
Figure 4: Choose the Trusted Root Certification Authorities certificate store.
Figure 5: Complete the import.
Figure 6: Accept the security warning.
Figure 7: Wrap everything up.

At this stage everything is set up and you should be able to run your Selenium server with the -trustAllSSLCertificates argument without any problems.

Conclusion

To recap, accepting self-signed certificates in Selenium is a two-staged process. You need to instruct the Selenium server to trust all SSL certificates and then tell the browser to use the Selenium server as a proxy. You may find that creating a custom browser launcher is the best way to configure your browser's proxy settings. After doing this, you'll be able to test sites running on domains with self-signed and invalid SSL certificates.

Thursday, 22 December 2011

Automation


Automation Tool Selection
After the strong analysis and believe of automation will really help for our concern,  We have to choose a right automation tool to implement.
Automation Tool Selection
1.Do we need to automate standalone application or client/server application or both?
2.Are we ready to invest some
money to buy a tool or not
3.Do we have the technical persons to train the resource or need any expert from out side
4.Is our existing testing resources capable of adopting the new technology?
5..How is the technical support available for the tool
6.How frequent update is available for the tool to handle the new technology implementation of AUT.
7.Complexity of using the tool.
 For Client/Server Application Selenium is my choice to automate my application for various reasons
a. Its Free
b. Its Compatible for many languages so i don't need a different language expert to implement. I can use any language which i am using to develop my application.
c. Its easily maintainable during frequent integration.

What needs to be automated
Before we start automation process we should prepare a list for things which has to be automated like below
1. Links
2. Elements
3. Functions
All the above mentioned
items will have some following sub divisions
Links:
a. Inner Link
b. Outer Link
Elements:
a.Visible Elements
b. Hidden Elements.
Functions:
a.Positive Case
b.Negative Case
c.Exceptional Case
Apart from all the above we can automate the Bugs to check for not reproducing again.

Why we need to automate an application?
              Testing needs more creativity, Logical thinking, Breaking attitude and different point of views. Then only a tester can break 100 developers developed code and catch possible missing of them. So no doubt its 100% manual resource involved work.

So then why we need to automate an application?

               Automation is an assistant of a Manual tester to give extra time for think about new sequences rather checking the routine of already developed sequences by them working or not. So never an automation tool can replace a manual tester until the product is dead (no further development ).

Where to Start Automation
This is the question i am being asked by many. First thing we should ask and answer for the following Questions with our self.
1. Why we need to automate?
2. What needs to be automated?
3. What is the goal of reducing the time and resource?
4. Is maintainability of automated scripts taking additional time and resource?

Sunday, 18 December 2011

Selection of Dymanic Combo Values

There are 2 cases where the Combo Box goes dynamic
1.ComboBox it self is an ajax element
2.The Combovalues gets dynamically populated on some event trigger

Point 1 can be handled using selenium.waitForCondition()
How about point 2 ? Below is the code

public class DynamicComboElementHandling {
    static Selenium selenium;
    static SeleniumServer server;

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        selenium = new DefaultSelenium("localhost", 4444, "*firefox",
                "http://www.google.com");
        server = new SeleniumServer();
        server.start();
        selenium.start();
        //Click on Google Advanced Search Link
        selenium.open("/advanced_search?hl=en");
        //Wait Until the Drop appears on the screen
        selenium.waitForCondition("selenium.isElementPresent(\"name=num\");",
                "15000");
        boolean flag = true;
        while (flag) {
            //Get the count of the drop down values
            int optionCount = selenium.getSelectOptions("name=num").length;
            // if the dropdown is populated with values, come out of the while
            // loop
            // else continue looping until the count is > 0
            if (optionCount > 0) {
                break;
            }
            continue;
        }
        //This code will be executed only if dropdown has some values
        //else the execution control will be inside the while loop until the
        //drop down values gets populated
        String[] options = selenium.getSelectOptions("name=num");
        for (int i = 0; i < options.length; i++) {
            if (options[i].equals("50 results")) {
                selenium.select("name=num", options[i]);
                break;
            }
        }

        Thread.sleep(3000);
        selenium.close();
        selenium.stop();
        server.stop();

    }

}