TA的每日心情 | 慵懒 2016-4-26 12:45 |
---|
签到天数: 3 天 连续签到: 2 天 [LV.2]测试排长
|
代码如下:每执行一个@Test的时候,都要重启一个浏览器,怎么让每一个test都是 在第一次开启的浏览器上操作呢?
package com.parking;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestLogin {
private static String url="http://app.xmparking.net:58080/regulation/login/login";
WebDriver dr=null;
WebElement element=null;
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "E:/chromedriver_win32/chromedriver.exe");
dr=new ChromeDriver();
dr.get(url);
}
@After
public void tearDown() throws Exception {
dr.close();
}
@Test
public void testUsername() {
element=dr.findElement(By.id("loginName"));
element.clear();
String name=element.getAttribute("placeholder");
assertEquals("手机号",name);
}
@Test
public void testPassWord(){
element=dr.findElement(By.id("password"));
element.clear();
String password=element.getAttribute("placeholder");
assertEquals("6位以上任意字符,区分大小写!",password);
}
@Test
public void testSaveid(){
boolean flag;
element=dr.findElement(By.xpath(".//*[@id='loginForm']/div[3]/div[2]/input[@id='saveId']"));
//element.clear();
flag=element.isSelected();
if(flag=false){element.click();}
element.click();
assertTrue(element.isEnabled());
assertTrue(element.isDisplayed());
assertTrue(element.isSelected());
}
@Test
public void testFogetPassWord(){
element=dr.findElement(By.xpath(".//*[@id='loginForm']/div[3]/div[2]/a"));
element.click();
assertEquals("http://app.xmparking.net:58080/regulation/forgot/forgotPassword",dr.getCurrentUrl());
dr.navigate().back();
}
@Test
public void testRegsiter(){
element=dr.findElement(By.xpath(".//*[@id='loginForm']/div[3]/div[4]/a"));
element.click();
assertEquals("http://app.xmparking.net:58080/regulation/register/register",dr.getCurrentUrl());
dr.navigate().back();
}
}
|
|