Thursday, August 2, 2012

By Pass ssl security pages

Certificates are of mainly two types
1) Self signed
2) Signed by root certificate authority.

In the case of all browsers, security certificate warning page will only be shown for pages with self signed certificate(or if certificate signed by root authority has expired).

For firefox to by pass this page we can follow two methods
1) Use a profile in which the certificate has already been installed.
2) Create a new profile and use the functions
    a) setAcceptUntrustedCertificates(Boolean value)
    b) setAssumeUntrustedCertificateIssuer(Boolean value)
      
   setAssumeUntrustedCertificateIssuer will have boolean value true or false based on the whether it is self signed or not.
        If it is self signed certicate use setAssumeUntrustedCertificateIssuer(true)
        If it the certificate has expired use setAssumeUntrustedCertificateIssuer(false) and in both of above cases setAcceptUntrustedCertificates(true) should be used.


For IE
 1) Install the certificate and run tests. If that case is failing go for second option.
 2) Use driver.navigate().to("javascript:document.getElementById('overridelink').click()"); to bypass security certificate page.

I haven't tried it for Chrome.

Thursday, June 28, 2012

InternetExplorerDriver Issues in webdriver

I am really confused by the way InternetExplorerDriver driver works. What all are the issues. In what all OS/Versions it works. What all api's work etc. Are all api's using native events.

Why is click() failing and sendKeys() working?
Why is test failing for InternetExplorerDriver when browser is minimized, but for remotewebdriver it works?

Will click() work if ie window is having focus? I think so





Tuesday, May 29, 2012

Sample Framework for testng based tests

This summary is not available. Please click here to view the post.

Use firefox in custom location for Grid

Start Node 

java -jar selenium-server-standalone-2.20.0.jar -role node -hub http://IP_Remote_Machine:4444/grid/register -port 5561 -nodeConfig config.txt

config.txt File Contents

{
"capabilities":
        [
                {
                        "browserName":"firefox",
                        "acceptSslCerts":true,
                        "javascriptEnabled":true,
                        "takesScreenshot":true,
                        "firefox_binary":"c:\\Program Files\\FF9\\firefox.exe",
                        "maxInstances":5,
                        "version":"9"
                },
                {
                        "browserName":"chrome",
                        "maxInstances":5
                },
                {
                        "browserName":"internet explorer",
                        "platform":WINDOWS
                }
        ],
"configuration":
        {
                "cleanUpCycle":2000,
                "proxy":"org.openqa.grid.selenium.proxy.WebDriverRemoteProxy",
                "maxSession":5,
                "port": 5561,
                "hubPort" : 4444
        }
}

The above script will assigned firefox 9 installed in custom location to grid hub.

Java Code For Assigning Browser

DesiredCapabilites caps = new DesiredCapabilites.firefox();
caps.setVersion("9");
caps.setBrowserName("firefox");
caps.setPlatform(Platform.ANY);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:444/wd/hub"), caps);


Friday, May 25, 2012

JavascriptExecutor methods

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", 
 webElement);
 
((JavascriptExecutor) driver)
.executeScript("arguments[0].setAttribute('style', 'color: yellow; border: 2px solid yellow;
');", element); 
 
((JavascriptExecutor) driver).executeScript("arguments[0].click;", 
 webElement);
 
check image has loaded
 
List<WebElement> allImages = driver.findElements(By.tagName("img"));
for (WebElement image : allImages) {
  boolean loaded = ((JavaScriptExecutor) driver).executeScript(
      "return arguments[0].complete", image);
  if (!loaded) {
    // Your error handling here.
  }
}  

start remote webdriver node

java -jar selenium-server-standalone-2.20.0.jar -role webdriver -hub http://ip of machine:4444/grid/register -browser "browserName=internet explorer, platform=WINDOWS" -browser "browserName=firefox, platform=ANY" -port 5561

Grid with config file

config.txt for starting firefox in custom location

{
"capabilities":
        [
                {
                        "browserName":"firefox",
                        "acceptSslCerts":true,
                        "javascriptEnabled":true,
                        "takesScreenshot":true,
                        "firefox_binary":"c:\\Program Files\\FF9\\firefox.exe",
                        "maxInstances":5,
                       "version":"9"
                },
                {
                        "browserName":"chrome",
                        "maxInstances":5
                },
                {
                        "browserName":"internet explorer",
                        "platform":WINDOWS
                }
        ],
"configuration":
        {
                "cleanUpCycle":2000,
                "proxy":"org.openqa.grid.selenium.proxy.WebDriverRemoteProxy",
                "maxSession":5,
                "port": 5561,
                "hubPort" : 4444
        }
}

Sample node : java -jar selenium-server-standalone-2.20.0.jar -role node -hub http://ip of machine:4444/grid/register -port 5561 -nodeConfig config.txt




Java code to invoke it


DesiredCapabilities caps = DesiredCapabilites.firefox();
caps.setVersion("9.0");
caps.setBrowserName("firefox");