Pages

Wednesday, May 30, 2012

Switch to window - smart way

Selenium : Smart way to switch to new window



var handlesBefore = webDriver.WindowHandles; 
webDriver.Click(foo); //Which opens a new window 
var handlesAfter = webDriver.WindowHandles; 
var newHandle = handlesAfter.Except(handlesBefore).Single(); 
webDriver.SwitchTo().Window(newHandle); 


Switch to a window with known name 

JUnit 4 Vs TestNG

JUnit 4 and TestNG are both very popular unit test framework in Java. Both frameworks look very similar in functionality. Which one is better? Which unit test framework should i use in Java project?
Here i did a feature comparison between JUnit 4 and TestNG.

Reference: http://www.mkyong.com/unittest/junit-4-vs-testng-comparison/
junit-vs-testngjpg

Monday, May 28, 2012

Scrum's Principles


The framework and terminology are simple in concept yet difficult to implement. Successful Scrum teams embrace the values upon which Scrum is based (paraphrased from the Agile Manifesto):

We value
  • Individuals and interactions over processes and tools
  • Completed functionality over comprehensive documentation
  • Customer collaboration over contract negotiation
  • Responding to change over following a plan
That is, while there is value in the items on the right, the items on the left matter more.
True success with the Scrum framework comes from teams and organizations who understand these values and the principles that form the foundation of all agile processes.

A Few Detailed Definitions

Product backlog: A product backlog is dynamic—Items may be deleted or added at any time during the project. It is prioritized—Items with the highest priority are completed first. It is progressively refined—Lower priority items are intentionally coarse-grained.
Sprint backlog: A sprint backlog is a negotiated set of items from the product backlog that a team commits to complete during the timebox of a sprint. Items in the sprint backlog are broken into detailed tasks for the team members to complete. The team works collaboratively to complete the items in the sprint backlog, meeting each day (during a daily scrum) to share struggles and progress and update the sprint backlog and burndown chart accordingly.
Potentially Shippable: Potentially shippable means that the increment/deliverable could be released to a customer.The product owner makes the decision about when to actually release any functionality or deliverable.

Scrum Terminology

We've introduced some new terms in describing the Scrum framework. Let's look at them in more detail. Scrum is made up of three roles, four ceremonies, and three artifacts. 

Three roles

  • Product owner: responsible for the business value of the project
  • ScrumMaster: ensures that the team is functional and productive
  • Team: self-organizes to get the work done

Four ceremonies

  • Sprint planning: the team meets with the product owner to choose a set of work to deliver during a sprint
  • Daily scrum: the team meets each day to share struggles and progress
  • Sprint reviews: the team demonstrates to the product owner what it has completed during the sprint
  • Sprint retrospectives: the team looks for ways to improve the product and the process.

Three artifacts

  • Product backlog: prioritized list of desired project outcomes/features
  • Sprint backlog: set of work from the product backlog that the team agrees to complete in a sprint, broken into tasks
  • Burndown chart: at-a-glance look at the work remaining (can have two charts: one for the sprint and one for the overall project)

Scrum's Three Roles


Scrum has three roles: product owner, ScrumMaster, and team.
Product Owner
  • The product owner decides what will be built and in which order
  • Defines the features of the product or desired outcomes of the project
  • Chooses release date and content
  • >Ensures profitability (ROI)
  • Prioritizes features/outcomes according to market value
  • Adjusts features/outcomes and priority as needed
  • Accepts or rejects work results
  • Facilitates scrum planning ceremony
ScrumMaster
The ScrumMaster is a facilitative team leader who ensures that the team adheres to its chosen process and removes blocking issues.
  • Ensures that the team is fully functional and productive
  • Enables close cooperation across all roles and functions
  • Removes barriers
  • Shields the team from external interferences
  • Ensures that the process is followed, including issuing invitations to daily scrums, sprint reviews, and sprint planning
  • Facilitates the daily scrums
  • Organizes the ceremonies and invites required people

The ScrumMaster has three primary responsibilities in addition to leading the daily scrums:
  1. The ScrumMaster needs to know what tasks have been completed, what tasks have started, any new tasks that have been discovered, and any estimates that may have changed. This makes it possible to update the burndown chart, an artifact that shows the cumulative work remaining day by day. The ScrumMaster must also look carefully at the number of open tasks in progress. Work in progress needs to be minimized to achieve maximum productivity.
  2. The ScrumMaster needs to raise awareness of dependencies and blocks that are impediments to the sprint. These issues need to be prioritized and tracked. A remediation plan needs to be implemented for impediments in priority order. Some can be resolved with the team, some can be resolved across teams, and others will need management involvement as they may be company issues that block all teams from achieving their production capacity. For example, a telecom company recently implemented Scrum and found eighteen items on their impediment list, only two of which were directly related to Scrum teams. The others were company issues that needed management attention.
  3. Last but not least, the ScrumMaster may notice personal problems or conflicts within the Scrum team that need resolution. These need to be clarified by the ScrumMaster and be resolved by dialogue within the team. Sometimes, the ScrumMaster may need help from management or human resources in order to resolve these issues. Certified ScrumMaster James Coplien developed over 200 case studies of notable projects while working at ATT Bell Labs. He reports that over 50% of productivity losses were caused by personnel issues. The ScrumMaster must pay attention to them to ensure the team is fully functional and productive.
The Team:
  • Is cross-functional
  • Is right-sized (the ideal size is seven -- plus/minus two -- members)
  • Selects the sprint goal and specifies work results
  • Has the right to do everything within the boundaries of the project guidelines to reach the sprint goal
  • Organizes itself and its work
  • Demos work results to the product owner and any other interested parties.




Tuesday, May 22, 2012

Object identification

Following are few XPath patterns one can use to find dynamic ids. 

text 
Not yet written - locate elements based on the text content of the node. 

starts-with 
Many sites use dynamic values for element’s id attributes, which can make them difficult to locate. One simple solution is to use XPath functions and base the location on what you do know about the element. For example, if your dynamic ids have the format (input id="text-12345") where 12345 is a dynamic number you could use the following XPath: //input[starts-with(@id, 'text-')] 

contains 
If an element can be located by a value that could be surrounded by other text, the contains function can be used. To demonstrate, the element can be located based on the ‘heading’ class without having to couple it with the ‘top’ and ‘bold’ classes using the following XPath: //span[contains(@class, 'heading')]. Incidentally, this would be much neater (and probably faster) using the CSS locator strategy css=span.heading 

siblings 
Not yet written - locate elements based on their siblings. Useful for forms and tables. 

Starting to use CSS instead of XPATH 
Locating elements based on class 
In order to locate an element based on associated class in XPath you must consider that the element could have multiple classes and defined in any order. However with CSS locators this is much simpler (and faster). 

XPath: //div[contains(@class, 'article-heading')] 
CSS: css=div.article-heading 

Perform a sequence of actions with Selenium WebDriver



Problem

We want to perform multiple actions in once, like: drag-and-drop, sliding, selecting multiple items.

Solution

The example code below shows some examples where we can use the Actions interface of Selenium WebDriver.
 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class ActionExample {
    private static WebDriver driver;

    @BeforeClass
    public void setUp() {
        driver = new FirefoxDriver();
    }

    @AfterClass
    public void tearDown() {
        driver.close();
        driver.quit();
    }

    @Test
    public void draggable() {
        driver.get("http://jqueryui.com/demos/draggable/");

        WebElement draggable = driver.findElement(By.id("draggable"));
        new Actions(driver).dragAndDropBy(draggable, 120, 120).build()
                .perform();
    }

    @Test
    public void droppable() {
        driver.get("http://jqueryui.com/demos/droppable/");

        WebElement draggable = driver.findElement(By.id("draggable"));
        WebElement droppable = driver.findElement(By.id("droppable"));
        new Actions(driver).dragAndDrop(draggable, droppable).build().perform();
    }

    @Test
    public void selectMultiple() throws InterruptedException {
        driver.get("http://jqueryui.com/demos/selectable/");

        List<WebElement> listItems = driver.findElements(By
                .cssSelector("ol#selectable *"));

        Actions builder = new Actions(driver);
        builder.clickAndHold(listItems.get(1)).clickAndHold(listItems.get(2))
                .click();

        Action selectMultiple = builder.build();
        selectMultiple.perform();
    }

    @Test
    public void sliding() {
        driver.get("http://jqueryui.com/demos/slider/");

        WebElement draggable = driver.findElement(By
                .className("ui-slider-handle"));
        new Actions(driver).dragAndDropBy(draggable, 120, 0).build().perform();
    }
 @Test
    public void typing() {
        driver.get("http://jqueryui.com/demos/typing/");

        WebElement typingArea = driver.findElement(By
                .className("div-to-wrtite-text-in"));
        new Actions(driver).sendKeys(typingArea).build().perform();
    }
Read more here - http://code.google.com/p/selenium/wiki/AdvancedUserInteractions