0

I am using eclipse kepler for the generate testcases using junit

I have tried the follow through this link https://earlwillis.wordpress.com/2012/01/31/getting-started-with-junit-reports/

but problem is that junit folder and build.xml file is not generated while refresh the project

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import junit.framework.Assert;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class  Test {


    static WebDriver driver;

 String expectedurl="http://example.com.au/account-page/";


    @BeforeClass
    public  static void setup()
    {
        System.setProperty("webdriver.chrome.driver", "E:\\Selenium Jar\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
    }
    @org.junit.Test
    public  void login(){
        driver.get("http://example.com.au/");
        WebElement loginmain=driver.findElement(By.id("menu-item-14235"));
        loginmain.click();
    }

    @org.junit.Test
    public void blankdata()
    {
        driver.get("http://example.com.au/loginregister/");   
        //driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

        String userblank=" ";
        String passblank=" ";

        WebElement username=driver.findElement(By.name("log"));
        username.clear();
        username.sendKeys(userblank);

        WebElement password=driver.findElement(By.name("pwd"));
        password.clear();
        password.sendKeys(passblank);

        WebElement submit=driver.findElement(By.name("Submit"));
        submit.click();

        String actual=driver.getCurrentUrl();

        Assert.assertEquals(expectedurl, actual);

    }
    @org.junit.Test
    public void blankpassword()
    {
        driver.get("http://example.com.au/loginregister/");   
    //  driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

        String userblank="rutvisoni";
        String passblank="";

        WebElement username=driver.findElement(By.name("log"));
        username.clear();
        username.sendKeys(userblank);

        WebElement password=driver.findElement(By.name("pwd"));
        password.clear();
        password.sendKeys(passblank);

        WebElement submit=driver.findElement(By.name("Submit"));
        submit.click();

        String actual=driver.getCurrentUrl();

        Assert.assertEquals(expectedurl, actual);

    }
    @org.junit.Test

    public void blankusername()
    {
        driver.get("http://example.com.au/loginregister/");   
        //driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

        String userblank=" ";
        String passblank="12Abcd";

        WebElement username=driver.findElement(By.name("log"));
        username.clear();
        username.sendKeys(userblank);

        WebElement password=driver.findElement(By.name("pwd"));
        password.clear();
        password.sendKeys(passblank);

        WebElement submit=driver.findElement(By.name("Submit"));
        submit.click();

        String actual=driver.getCurrentUrl();

        Assert.assertEquals(expectedurl, actual);

    }
    @org.junit.Test
    public void invaliddata()
    {
        driver.get("http://example.com.au/loginregister/");   
        //driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

        String userblank="rutvisoni1";
        String passblank="12Abcdfdg";

        WebElement username=driver.findElement(By.name("log"));
        username.clear();
        username.sendKeys(userblank);

        WebElement password=driver.findElement(By.name("pwd"));
        password.clear();
        password.sendKeys(passblank);

        WebElement submit=driver.findElement(By.name("Submit"));
        submit.click();

        String actual=driver.getCurrentUrl();

        //System.out.println("Invaliddata->"+actual);

        Assert.assertEquals(expectedurl, actual);

    }

    @org.junit.Test 
    public  void  validdata(){

        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        driver.get("http://example.com.au/loginregister/");   

        WebElement username=driver.findElement(By.name("log"));
        username.clear();
        username.sendKeys("sunny007");

        WebElement password=driver.findElement(By.name("pwd"));
        password.clear();
        password.sendKeys("123456Ss");

        WebElement submit=driver.findElement(By.name("Submit"));
        submit.click();

        String actual=driver.getCurrentUrl();

        Assert.assertEquals(expectedurl, actual);       
    }
    @AfterClass
    public static void close()
    {
        driver.close();
    }
}
  • I would suggest to use TestNG instead of Junit. TestNG have in build report functionality. – Sagar007 Dec 5 '16 at 5:52
  • i have already try for testng but for testng report is not generating – Rutvi Soni Dec 5 '16 at 5:54
  • As per your second question you have unchecked Disable default listeners. check it. – Sagar007 Dec 5 '16 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.