Thursday, October 11, 2012

Cloud Computing

Today, i am surfing about "Cloud Computing" and i found some nice information to start with what is "Cloud Computing"?

Cloud computing is the use of computing resources (hardware and software) that are delivered as a service over a networ (typically the Internet). The name comes from the use of a Cloud-shaped symbol as an abstraction for the complex infrastructure it contains in system diagrams. Cloud computing entrusts remote services with a user's data, software and computation.
There are many types of public cloud computing:
  • Infrastructure as a service (IaaS)
  • Platform as a service (PaaS)
  • Software as a service (SaaS)
  • Storage as a service (STaaS)
  • Security as a service (SECaaS)
  • Data as a service (DaaS)
  • Test environment as a service (TEaaS)
  • Desktop as a service (DaaS)
  • API as a service (APIaaS) 

The above two are nice to go through to get start with what is "Cloud Computing"



Friday, October 5, 2012

Selenium RC vs WebDriver

Selenium RC (Selenium 1):
Selenium uses JavaScript to automate web pages. This lets it interact very tightly with web content, and was one of the first automation tools to support Ajax and other heavily dynamic pages. However, this also means Selenium runs inside the JavaScript sandbox. This means you need to run the Selenium-RC server to get around the same-origin policy, which can sometimes cause issues with browser setup.

WebDriver (Selenium 2):

WebDriver on the other hand uses native automation from each language. While this means it takes longer to support new browsers/languages, it does offer a much closer ‘feel’ to the browser. If you’re happy with WebDriver, stick with it, it’s the future. There are limitations and bugs right now, but if they’re not stopping you, go for it.

Selenium Benefits over WebDriver
  • Supports many browsers and many languages, WebDriver needs native implementations for each new languagte/browser combo.
  • Very mature and complete API
  • Currently (Sept 2010) supports JavaScript alerts and confirms better
Benefits of WebDriver Compared to Selenium
  • Native automation faster and a little less prone to error and browser configuration
  • Does not Requires Selenium-RC Server to be running
  • Access to headlessHTMLUnit can allow really fast tests
  • Great API

Wednesday, September 26, 2012

How to maximize window of the browser?


How to maximize window of the browser?

We can maximize browser window in multiple ways...

By Using WebDriverBackedSelenium, by using Robot class and by webdriver.

1. WebDriverBackedSelenium:
        The very first method which is given in their documentation is using windowMaximize() command of selenium instance.

selenium = new WebDriverBackedSelenium(driver, url);


selenium.windowMaximize();

2. Using Robot class:  We can use robot class to invoke keyboard action to maximize browser window.

Robot robot = new Robot();
// Press ALT and SPACE Keys

robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_SPACE);
Thread.sleep(1000);
//Press down arrow keys to move to select Maximize option in menu

robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
Thread.sleep(100);

robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
Thread.sleep(100);

robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
Thread.sleep(100);

robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
Thread.sleep(100);
//Press enter to invoke the Maximize menu option

robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}

3. Using WebDriver and dimensions:

public static void maximizeWindow(){

        Toolkit t = Toolkit.getDefaultToolkit();
        org.openqa.selenium.Dimension screenResolution = new   org.openqa.selenium.Dimension((int)t.getScreenSize().getWidth(), (int)t.getScreenSize().getHeight());

       driver.manage().window().setSize(screenResolution);
}



4. WebDriver:

driver.manage().window().maximize();

























Tuesday, September 18, 2012

What is Defect Density?


DEFINITION
Defect Density is the number of confirmed defects detected in software/component during a defined period of development/operation divided by the size of the software/component.

ELABORATION
The ‘defects’ are:
  • confirmed and agreed upon (not just reported).
  • Dropped defects are not counted.
The period might be for one of the following:
  • for a duration (say, the first month, the quarter, or the year).
  • for each phase of the software life cycle.
  • for the whole of the software life cycle.
The size is measured in one of the following:
  • Function Points (FP)
  • Source Lines of Code
DEFECT DENSITY FORMULA











USES
  • For comparing the relative number of defects in various software components so that high-risk components can be identified and resources focused towards them.
  • For comparing software/products so that quality of each software/product can be quantified and resources focused towards those with low quality.

Sunday, September 16, 2012

How to pass parameters in selenium RC using TestNG

How to pass parameters in selenium RC using TestNG


We can parametrize our test cases using TestNG in Selenium RC in two ways

Pass the data from testng.xml file...

1. using @parameters

public class first_class {
    private Selenium selenium;
    public String url = "http://google.com/";   

    @Parameter ({ "url" })
    @Test   
    public void Test(String url) throws MalformedURLException { 
        System.out.println("In Test Methos");
        selenium.open(url); 
        System.out.println(selenium.getTitle() + "in in Test Method");
        selenium.close();
    }
    }


2. using @DataProvider


import org.openqa.selenium.server.RemoteControlConfiguration;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;

import java.io.*;
import java.sql.*;



public class TestExcel extends SeleneseTestBase {

@DataProvider(name="DP1")
public Object[][] createData(){
Object[][] retObjArr = {{"testuser1","password1"},
{"testuser2","password2"},
{"testuser3","password3"},
{"testuser4","password4"},
{"testuser5","password5"},
};
return(retObjArr);
}


private SeleniumServer seleniumServer;
Selenium selenium;

@BeforeClass
public void setUp()throws Exception{

RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.trustAllSSLCertificates();
seleniumServer = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost",4444,"*iexplore","http://www.yahoo.com");
seleniumServer.start();
selenium.start();
}

@Test (dataProvider = "DP1")
public void testEmployeeData(String username, String password){
selenium.open("https://login.yahoo.com/config/mail?.src=ym&.intl=us/");
selenium.type("username", username);
selenium.type("passwd",password);
selenium.click(".save");
selenium.waitForPageToLoad("30000");
assertTrue(selenium.isTextPresent("Hi,"+username));
selenium.click("_test_sign_out");
selenium.waitForPageToLoad("30000");

}
@AfterTest
public void tearDown() throws InterruptedException{
selenium.stop();
seleniumServer.stop();

}

Saturday, September 15, 2012

How to take screenshot of a page using webdriver?

How to take screenshot of a page using webdriver?

 Here is a sample code to get the screenshot of the current browser window using webdriver ...

The file name with the specific path should mentioned. Either it should be dynamic or we can hard-code the file name ( every time we run this code, the file will be overriden).


    public static void snapshot() throws IOException{
       
        File fi = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(fi, new File("file name with the path should be mentioned here... "));
    }

It is very simple and we call this method when ever we need (Pass or Fail cases) to take the screenshots of the pages.

Hope this is helpful.. :)

How to maximize window size of current window using webdriver?

How to maximize window size of current window  using webdriver?

Generally when we start the browsers, it will open based on its previous state. Some times it is customized to certain size (width and height) manually. So in order to make the browser opens in a maximized window, we need to use Toolkit class.

Maximize window option will allows the user to see the complete application under test.

Here is the snippet to achieve the maximized window using Webdriver...

Here driver is WebDriver object for Firefox or IE driver.

WebDriver driver = new Firefoxdriver();

public static void maximizeWindow(){
        Toolkit t = Toolkit.getDefaultToolkit();
        org.openqa.selenium.Dimension screenResolution = new org.openqa.selenium.Dimension((int)t.getScreenSize().getWidth(), (int)t.getScreenSize().getHeight());
        driver.manage().window().setSize(screenResolution);
   
    }

Saturday, September 1, 2012

How to drag and drop elements using webdriver?

How to drag and drop elements using webdriver?
 
If we want to drag and drop from one element to other element.

Below is the small snippet code....

WebDriver driver  = new FirefoxDriver();

driver.get("URL");

Actions builder = new Actions(driver);

builder.clickAndHold().moveToElement(ele).release().build().perform();

How to mouse hover using WebDriver Backed selenium?

How to mouse hover using WebDriver Backed selenium?

Create a webdriverbackedselenium object and mouse move to the specific id and click on the on any specific id.

Below is the small snippet code for mouse move or mouse hover using webdriver backed selenium.


Using WebDriverBacked Selenium:

        WebDriverBackedSelenium seleniumDriver = new WebDriverBackedSelenium(driver,"URL");
       
        seleniumDriver.mouseMove("Specify id ");
        seleniumDriver.click("Specify id");


how to mouse hover on any element using webdriver

how to mouse hover on any element using webdriver?

Mouse over using WebDriver little different. And also the given solution may not work with the latest versions of FF 12+. We need to wait for the latest version of the selenium jar.


//driver = new InternetExplorerDriver();
// driver = new FirefoxDriver();
driver.get("URL");


Using Actions:

        Actions builder = new Actions(driver);
        WebElement ele = driver.findElement(By.xpath("Specify xpath"));
        builder.moveToElement(ele).build().perform();
        WebElement ele2 = driver.findElement(By.xpath("Specify xpath"));
        ele2.click();


Friday, August 31, 2012

How do we configure proxy to our browser?

If we need to use a proxy. How do we configure that?

Proxy configuration is done via the org.openqa.selenium.Proxy class like so:

Proxy settings need to set, when an application runs under proxy. And also we can set
the Desired Capabilities for any given browser. 

Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl("http://youdomain/config");
// We use firefox as an example here.
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.PROXY, proxy);
// You could use any webdriver implementation here
WebDriver driver = new FirefoxDriver(capabilities);
 

Monday, July 30, 2012

Last date for filing IT returns is 31-Jul-2011

Even though this post is not relevant to the blog, just adding it as it very useful for those who wants to file thier returns.

Currently there are many paid and free services for filing the returns. Some of the paid services are as follows:
  1. http://www.taxmunshi.com/
  2. http://www.taxspanner.com/
There are various other paid services but I found these to be the lowest Rs. 199 and Rs. 249 respectively.
If you are like me, who is not interested to spend a paisa on the filing the tax return then you have to visit the following site:
https://incometaxindiaefiling.gov.in
First Step: Login to the portal. If you don’t have the log in then register and create your id. It requires your PAN card details so keep them handy. If you don’t have PAN card with you at the moment, then don’t worry. Here is the link which you can access to know your PAN Card details.
Second Step: Download the excel utility or pdf Utility from the following link. For salaried professional download ITR-1. My suggestion would be to download the excel utility.
Third Step: This step requires you to have your Form 16 from your employer. Once you have that with you, you can go ahead with filling the excel utility or pdf utility. I am assuming that excel is what you have downloaded based on my suggestion since it is very easy to fill.
Now in detail, we will go about filling the excel utility.
  1. It is necessary to ENABLE the execution of macros in Return-Preparation-Utility in order to enter, validate and generate an .XML file for upload. Follow these steps to ENABLE execution of macros depending on the version of [Microsoft Office Excel] being used to open the Return-Preparation-Utility.[Microsoft Office Excel 2003] Navigate through the following excel menu option to reduce the level of security in executing macros : Tools –> Macros –> Security
  2. OR
  3. Tools –> Macros –> Security –> Medium
  4. Save the excel-utility and re-open it.
  5. [Microsoft Office Excel 2007] Navigate through the following excel menu options to reduce the level of security in executing macros : Excel Options –> Trust Centre –> Trust Centre Settings –> Macro Settings –> Enable all macros
  6. AND
  7. Excel Options –> Trust Centre –> Trust Centre Settings –> ActiveX Settings –> Enable all controls without restriction and without prompting
  8. Save the excel-utility and re-open it.
  9. [Microsoft Office Excel 2010] When you open the EXCEL-UTILITY, the yellow Message Bar appears with a shield icon and the Enable Content button. Click on the Enable Content to enable the macros.
  10. Fill in your name and address and other details in personal information column.
  11. Clearly mention the ward/circle for filing; since I reside in Bangalore, I have given it as Bangalore Circle. You can find your own from this following link.
  12. In the section Return filed under Section, fill in “11-u/s 139(1)“.
  13. In ” income & deductions” section of the excel sheet, field1 namely, Income from Salary / Pension (Ensure to fill Sch TDS1) can be filled using field 6 in the form 16 namely “Income chargeable under the head ‘Salaries’(3-5)“
  14. If you have a home loan then, Income from one House Property should be filled with Loss From House Property value from your Form 16.
  15. If you have any other Source of income then you have to mention the same in the next row i.e. Income from Other Sources (Ensure to fill Sch TDS2).
  16. Fill the next section namely Dedcutions under Chapter VI A (Section) referring to section with the same name from form16. It is a one to one correspondence between the fields.
  17. Move to next worksheet i.e. TDS, where in you mention the details of your employer as given in Form 16 and also the Income chargeable under the head Salaries will be the amount that is obtained from the First worksheet Row 7. Total Income (4 – 6).
  18. Once that is done, complete the Details of Advance Tax and Self Assessment Tax Payments referring to your Form 16 namely from the ANNEXURE-B section DETAILS OF TAX DEDUCTED AND DEPOSITED IN THE CENTRAL GOVERNMENT ACCOUNT THROUGH CHALLAN.
  19. Lastly fill the Tax paid and Verification worksheet. Once everything is done. Validate the utility by pressing the Validate button. If you have done everything correctly, then there should be no issues. If you have made any error, please correct the same.
  20. Click on Calculate Tax in the first worksheet and Generate Xml file.
Now only two steps are remaining for you to complete the e-filing of the returns.
Once you have generated the XML file, login to the portal. Then in the left, you can find the Submit returns; click the select assessment year, then AY 11 -12. You will land in this page.  Select ITR-1 and say No for digitally signing the file.
Once done, upload the file and voila, it is all done.
You will get an acknowledgment from the IT- Department in your email that you have registered. It should be instantaneous. If you don’t get it in some time, please wait for an hour or so and still if you don’t get the same then my suggestion would be to re-upload the xml file.
Last and important step for filing the income tax returns is as follows:
Since you have not digitally signed the file, you have to send the acknowledgment back to IT office. Please furnish the signed and verified Form ITR-V to the Income-tax Department by mailing it to
Income Tax Department – CPC,
Post Bag No – 1 , Electronic City Post Office, Bangalore – 560100, Karnataka.
Please send it by ORDINARY POST OR SPEEDPOST ONLY within a period of 120 days from the date of transmitting the data electronically.
ITR-V sent by Registered Post or Courier will not be accepted. Form ITR-V shall not be received in any other office of the Income-tax Department or in any other manner.
Once you have sent the ITR-V, you can check the status of the same using the following link.
Hope this helps and please spread the word so that many can benefit from the same. Thank you.

Thursday, July 26, 2012

selenium screenshots using webdriver

Taking Screenshots with Selenium WebDriver

Take a screenshot with Selenium WebDriver

Testers do take screenshots while testing, its important in many ways. So can you take screenshots using Selenium WebDriver? The answer is yes. Below you can find few good links that show you how to take screenshots with Selenium WebDriver:

1. This StackOverflow link has an example from Java, Python, Ruby, Jython [Link]

2. Taking screenshots with Selenium WebDriver (Selenium Client Driver for C#) [Link]

3. Taking screenshot of flash object using Selenium with Webdriver [Link]

4. Taking a Screenshot with Selenium Remote Webdriver - Java, Csharp, Python, Ruby [link]

5. If capture screenshot functionality with remote webdriver implementation throws Class Cast Exception [java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to org.openqa.selenium.TakesScreenshot], then take a look here.

6. How to take an OS level screen capture using ruby selenium webdriver [Link]

7. How to Take Screenshots during Selenium Test Execution [Link]

Selenium - Uploading a File

Selenium - Uploading a File

If you are trying to upload a file using Selenium and are stuck then below links may help you. Below are 10 links to help you upload a file using Selenium automation testing tool.

1.
Selenium RC with Junit framework - upload a file using attachFile() method - [Link]

2.
Selenium - Uploading Files in Remote WebDriver - [Link]

3.
Selenium - Upload files on browsers running over remote machines [Link]

4.
Selenium: Upload file in Google Chrome - [Link]

5.
How to deal with file uploading in test automation using selenium or webdriver - [Link]

6.
Webdriver: File Upload - [Link]

7.
How to upload a file using Selenium in Java - [Link]

8.
How to upload a file in selenium - AutoIT - [Link]

9.
Selenium RC: How to Upload and Submit Files Using Selenium and AutoIt - [Link]

10.
Selenium Upload/Download file handling - [Link]

Wednesday, July 25, 2012

How to handle popup using Selenium RC?

Handling Popup's using Selenium RC:
 
public void testPopup() throws Exception {
    selenium.open("http://yoursitename/page.jsp");
    selenium.click("//img[@alt='Share']");
    selenium.waitForPopUp("_blank", "30000");
    selenium.selectWindow("windowId");
    verifyTrue(selenium.isTextPresent("Recommend to a friend"));
    selenium.close();
} 

How to locate Web Elements or UI Elements in a page

First of all inorder to locate the web elements we need to open or fetch (open) a web page. We can do this
by
 driver.get("http://www.google.com");


Web Elements:

Locating elements in WebDriver can be done on the WebDriver instance itself or on a WebElement. Each of the language bindings expose a “Find Element” and “Find Elements” method. The first returns a WebElement object otherwise it throws an exception. The latter returns a list of WebElements, it can return an empty list if no DOM elements match the query.
The “Find” methods take a locator or query object called “By”. “By” strategies are listed below.

By ID:
Ex:
< span=""> id="coolestWidgetEvah">... <>
Using Java:  
WebElement element = driver.findElement(By.id("coolestWidgetEvah"));
 



By Class Name:
Ex:
< span=""> class="cheese">Cheddar <>
< span=""> class="cheese">Gouda <>

Using Java:
List<WebElement> cheeses = driver.findElements(By.className("cheese")); 

By Tag Name:

The DOM Tag Name of the element.
Ex

How to handle popups in WebDriver

public boolean testNewWindow(){
 String currentHandle = driver.getWindowHandle();
 Set handles = driver.getWindowHandles();
 handles.remove(currentHandle);
 if (handles.size() > 0) {
 try{
 driver.switchTo().window(handles.iterator().next());
 return true;
 }
 catch(Exception e){
 System.out.println(e.getMessage());
 return false;
 }
 }
 System.out.println("Did not find window");
 return false;
 }

Getting started with WebDriver

package org.openqa.selenium.example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class WebDriverExample  {
    public static void main(String[] args) {
        // Create a new instance of the Firefox driver
        // Notice that the remainder of the code relies on the interface, 
        // not the implementation.
        WebDriver driver = new FirefoxDriver();

        // And now use this to visit Google
        driver.get("http://www.google.com");
        // Alternatively the same thing can be done like this
        // driver.navigate().to("http://www.google.com");

        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));

        // Enter something to search for
        element.sendKeys("Cheese!");

        // Now submit the form. WebDriver will find the form for us from the element
        element.submit();

        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());
        
        // Google's search is rendered dynamically with JavaScript.
        // Wait for the page to load, timeout after 10 seconds
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
            }
        });

        // Should see: "cheese! - Google Search"
        System.out.println("Page title is: " + driver.getTitle());
        
        //Close the browser
        driver.quit();
    }
}

WebDriver and Selenium Server

You may, or may not, need the Selenium Server, depending on how you intend to use Selenium-WebDriver. If you will be only using the WebDriver API you do not need the Selenium-Server. If your browser and tests will all run on the same machine, and your tests only use the WebDriver API, then you do not need to run the Selenium-Server; WebDriver will run the browser directly.
There are some reasons though to use the Selenium-Server with Selenium-WebDriver.
  • You are using Selenium-Grid to distribute your tests over multiple machines or virtual machines (VMs).
  • You want to connect to a remote machine that has a particular browser version that is not on your current machine.
  • You are not using the Java bindings (i.e. Python, C#, or Ruby) and would like to use HtmlUnit Driver

WebDriver

WebDriver:

WebDriver is a selenium 2.0 and it has all cool features like

1. Selenium-WebDriver makes direct calls to the browser using each browser’s native support for automation.
2. Selenium-WebDriver, drives the browser directly using the browser’s built in support for automation.
3. No need to start the server.
4. Works with higher versions of firefox.
5. Android and iPhone based testing.
6. We can do object extraction in Bulk.

WebDriver and Selenium Server:

You may, or may not, need the Selenium Server, depending on how you intend to use Selenium-WebDriver. If you will be only using the WebDriver API you do not need the Selenium-Server.. more

Tuesday, July 24, 2012

How to run Firefox 4.0 and higher versions using Selenium RC?

So many of us are facing this problem for a quite long time and unable to run test using selenium RC 1.0.x. The problem behind this is: in the selenium server the max version of firefox to be used is defined as 3.6. To overcome this problem, we need to override the value to the version number you want to use (in my case 4.0). Below are the step on how to do it:
  1. Change the file extension of the selenium-server.jar file to .zip.
  2. Now, extract the file content to any particular folder let’s say ‘selserver’.
  3. Now search for all available install.rdf files. You may get 5-6 such file depending on the version.
  4. Open those files with note pad. In this file you will see a tag like “3.6.*”. As it’s defined as 3.6, hence we need to change it to 4.0 and save the file.
  5. Compress all the files again as you had decompressed them to selenium-server.zip. Change the file extension to .jar.
We are ready with our server with support for Firefox 4.0. Now happy testing using Firefox 4.0 and higher veriosns...  :) .