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;
public class Test {
static WebDriver driver;
String expectedurl="http://examplezone.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 test1_login(){
driver.get("http://examplezone.com.au/");
WebElement loginmain=driver.findElement(By.id("menu-item-14235"));
loginmain.click();
}
@org.junit.Test
public void test2_blankdata()
{
driver.get("http://examplezone.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 test3_blankpassword()
{
driver.get("http://examplezone.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 test4_blankusername()
{
driver.get("http://examplezone.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 test5_invaliddata()
{
driver.get("http://examplezone.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 test6_validdata(){
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.get("http://examplezone.com.au/loginregister/");
WebElement username=driver.findElement(By.name("log"));
username.clear();
username.sendKeys("rutvisoni");
WebElement password=driver.findElement(By.name("pwd"));
password.clear();
password.sendKeys("12Abcd");
WebElement submit=driver.findElement(By.name("Submit"));
submit.click();
String actual=driver.getCurrentUrl();
Assert.assertEquals(expectedurl, actual);
}
@AfterClass
public static void test7_close()
{
driver.close();
}
}
我已經在eclipse IDE中使用JUnit創建了登錄頁面的測試用例。我想運行順序功能這樣way-如何設置junit中的函數序列
test2_blankdata()
test3_blankpassword()
test4_blankusername()
test5_invaliddata()
test6_validdata()
但它不能正常工作,請通過上面的代碼,並給我在這個問題上有什麼建議?