Wednesday 6 February 2013

WebDriver with JUNIT


import java.util.concurrent.TimeUnit;

import junit.framework.Assert;

import  org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class WebDriverJunit {

public static WebDriver oBrowser;

@BeforeClass
public static void Selenium_init()
{
oBrowser=new FirefoxDriver();
oBrowser.manage().window().maximize();
oBrowser.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
oBrowser.get("http://www.bing.com");
}

@AfterClass
public static void Selenium_End()
{
oBrowser.quit();
}

@Test
public void Validate_Edit()
{
WebElement oEdit;

try
{
oEdit=oBrowser.findElement(By.id("sb_form_q"));
Assert.assertEquals("", oEdit.getText());
}
catch(Exception e)
{
Assert.fail(e.getMessage());
}
}

@Test
public void Search()
{
WebElement oEdit,oButton;
String sPageSource;

try
{
oEdit=oBrowser.findElement(By.id("sb_form_q"));
oButton=oBrowser.findElement(By.id("sb_form_go"));
oEdit.sendKeys("Selenium");
oButton.click();
sPageSource=oBrowser.getPageSource();
oBrowser.navigate().back();
if (sPageSource.lastIndexOf("Selenium")<100)
{
Assert.fail("No Proper result");
}
}
catch(Exception e)
{
Assert.fail(e.getMessage());
}
}
}

21 comments:

  1. Excellent Post. Also visit http://whiteboxqa.com/selenium.php

    ReplyDelete
  2. Hi
    I read this post two times.
    I like it so much, please try to keep posting.
    Let me introduce other material that may be good for our community.

    Microsoft dynamics training

    ReplyDelete
  3. Hi
    I read this post two times.
    I like it so much, please try to keep posting.
    Let me introduce other material that may be good for our community.

    Microsoft dynamics training

    ReplyDelete
  4. Nice Post! Also visit http://arvindkj.blogspot.in/

    ReplyDelete
  5. Excellent Post.Also visit http://www.whiteboxqa.com/WBQA/google/selenium-webdriver-and-junit-class-design.php

    ReplyDelete
  6. It was very nice article and it is very useful to Selenium learners.We also provide Cub training software online training.

    ReplyDelete
  7. Thanks you for the awesome information in your blog on  Selenium training in Chennai

    ReplyDelete
  8. Thanks you for the awesome information in your blog.
    selenium training in chennai

    ReplyDelete
  9. • Thanks for all your information, Website is very nice and informative content.
    msbi training in chennai

    ReplyDelete

  10. Advanced Selenium Framework Training in Chennai by Vishwa

    Hi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.

    I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
    selenium training in chennai

    ReplyDelete
  11. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    Selenium Training in Chennai

    ReplyDelete
  12. Excellent post. I would like to tell about Supreet. Supreet Solutions is the Best Institute For Advanced Selenium Classroom And Online Training Institute In Hyderabad By 15+ years of Real Time Industry experts.
    Best Selenium Training Institute In Hyderabad | Online Selenium Training

    ReplyDelete
  13. Hi Shiva....interested in some technical discussion asap..can you ping me on this email:sshree43@gmail.com

    ReplyDelete
  14. Amazing blog. It's very helpful to learn these things easily. Thank You so much. Keep supporting. 
     aws training in chennai aws course in chennai 

    ReplyDelete