Wednesday, October 9, 2013

Automating a basic web page using Selenium WebDriver + Java + Mavan +TestNG

It is very simple.Just follow these three steps.

1. update the pom file

 <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.21.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-control</artifactId>
            <version>2.0rc2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <groups></groups>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
        </plugins>
    </build>

2. Create the page class

Initialize the constructor on page object.Same time you can call the url.

    public YourFirstPage(WebDriver driver)  {

        this.driver = driver;
        driver.get("http://abc.lk");
     
    }

Then you can do what ever you want to do(filling forms,assertions,validations,....etc) in the page.

 public void setUserName(String userName) {

        WebElement uNameFld = driver.findElement(By.id("some id"));
        uNameFld.clear();
        uNameFld.sendKeys(userName);
    }

3. Create the test case class

This class is to write your test cases by calling methods in page class.

Before class

 @BeforeClass(alwaysRun = true)
    public void BeforeTest() throws IOException, InterruptedException {

         DesiredCapabilities capability = DesiredCapabilities.firefox();
        driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
        firstPage = new FirstPage(driver);
}

After Class

@AfterClass(alwaysRun = true)
    public void AfterMethod() {

        driver.close();
    }

That's it!
You can write test cases here now.

See my example code below to automate to open and validate links in www.abc.lk.





Wednesday, September 11, 2013

Selenium WebDriver Advance - Waits


When you need webdriver to wait for elements, there are several ways to keep waiting your web driver.

This is little bit advance, but more efficient way to wait for elements and assert those.


WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));


WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));

Sunday, January 13, 2013

THE START...!!!


When I started to work as a Software Quality Assurance/Test Automation Engineer, I had to face a lot of difficulties because of lack of subject knowledge and experience(still I am not an expert in this field :) ).How ever I could be able to overcome all those difficulties and do the my job well.But I had to made a really big effort and spent long time to study those from the internet.Still I am learning those kind of things and applying knowledge in practical scenarios.

Even though there are hundreds of QA tutorial, eBooks, web sites, blogs and forums can be found on the internet,  it is very difficult to find out a reference which can learn from A to Z.

Some time I also really got disappoint when I tried to understand some tutorials and references which are like Greek to understand for a beginner.

So I decided to write my own blog that to share my knowledge and experience with anyone who interested in Software Quality Assurance.

I really appreciate your feed backs (good and bad) and it will guide me to make this a successful one.

Image credit : http://tinyurl.com/asqh8qw