package testweb;
import static org.junit.Assert.*;
import java.io.File;
import java.nio.Buffer;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
public class testLR {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Parameters
/* public int getSpecifyNum(int min, int max) {
Random random = new Random();
return random.nextInt(max) % (max - min + 1) + min;
}
private int tt;
public void TestClass(int tt)
{
this.tt=getSpecifyNum(2016109,9999999);
}
*/
public static String getAlphanumString_(int length) {
StringBuffer buf = new StringBuffer();
Random random = new Random();
for (int i = 0; i < length; i++) {
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; // 输出字母还是数字
if ("char".equalsIgnoreCase(charOrNum)) {
// 字符串
int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; // 取得大写字母还是小写字母
buf.append((char) (choice + random.nextInt(26)));
} else if ("num".equalsIgnoreCase(charOrNum)) {
// 数字
buf.append(String.valueOf(random.nextInt(10)));
}
}
return buf.toString();
}
private String tt;
public void TestClass(String tt)
{
this.tt=getAlphanumString_(5);
}
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.firefox.bin", "E:\\Firefox\\firefox.exe");
driver = new FirefoxDriver();
baseUrl = "https://www.zy.com";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testUntitled() throws Exception {
driver.get(baseUrl + "/admin/login.html");
driver.findElement(By.xpath("//input[@type='text']")).clear();
driver.findElement(By.xpath("//input[@type='text']")).sendKeys("admin");
driver.findElement(By.xpath("//input[@type='password']")).clear();
driver.findElement(By.xpath("//input[@type='password']")).sendKeys("zyxr123456");
driver.findElement(By.cssSelector("button")).click();
driver.findElement(By.cssSelector("span.ml5.ng-binding")).click();
driver.findElement(By.xpath("//div[@id='nav_box']/ul/li/ul/li[3]/p/span")).click();
driver.switchTo().frame("myFrame");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
new Select(driver.findElement(By.xpath("//select"))).selectByVisibleText("车贷抵押");
driver.findElement(By.xpath("//input[@type='text']")).clear();
driver.findElement(By.xpath("//input[@type='text']")).sendKeys("15888888880");
driver.findElement(By.cssSelector("button.btn.btn-primary")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("(//input[@type='text'])[5]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[5]")).sendKeys(tt);
driver.findElement(By.xpath("(//input[@type='text'])[6]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[6]")).sendKeys("1");
driver.findElement(By.xpath("(//input[@type='text'])[7]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[7]")).sendKeys("9");
new Select(driver.findElement(By.xpath("//li[13]/select"))).selectByVisibleText("担保借款");
driver.findElement(By.xpath("(//input[@type='text'])[9]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[9]")).sendKeys("10000");
new Select(driver.findElement(By.xpath("//li[15]/select"))).selectByVisibleText("等额本息");
new Select(driver.findElement(By.xpath("//li[16]/select"))).selectByVisibleText("中业众信");
new Select(driver.findElement(By.xpath("//li[17]/select"))).selectByVisibleText("遵明担保");
new Select(driver.findElement(By.xpath("//li[18]/select"))).selectByVisibleText("环城东路店");
new Select(driver.findElement(By.xpath("//li[19]/select"))).selectByVisibleText("消费");
driver.findElement(By.xpath("(//input[@type='text'])[10]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[10]")).sendKeys("1");
driver.findElement(By.xpath("(//input[@type='text'])[11]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[11]")).sendKeys("1");
driver.findElement(By.xpath("(//input[@type='text'])[12]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[12]")).sendKeys("1");
driver.findElement(By.xpath("(//input[@type='text'])[13]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[13]")).sendKeys("1");
driver.findElement(By.xpath("(//input[@type='text'])[14]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[14]")).sendKeys("1");
driver.findElement(By.xpath("(//input[@type='text'])[15]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[15]")).sendKeys("1");
driver.findElement(By.xpath("(//input[@type='text'])[16]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[16]")).sendKeys("1");
driver.findElement(By.xpath("(//input[@type='text'])[17]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[17]")).sendKeys("1");
driver.findElement(By.xpath("(//input[@type='text'])[18]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[18]")).sendKeys("1");
driver.findElement(By.xpath("(//input[@type='text'])[19]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[19]")).sendKeys("1");
driver.findElement(By.xpath("(//input[@type='text'])[20]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[20]")).sendKeys("1");
driver.findElement(By.xpath("//input[@type='checkbox']")).click();
driver.findElement(By.xpath("(//input[@type='checkbox'])[2]")).click();
driver.findElement(By.xpath("(//input[@type='checkbox'])[3]")).click();
driver.findElement(By.xpath("(//input[@type='checkbox'])[4]")).click();
driver.findElement(By.xpath("(//input[@type='checkbox'])[5]")).click();
driver.findElement(By.xpath("(//input[@type='checkbox'])[6]")).click();
driver.findElement(By.cssSelector("button.btn.btn-public")).click();
driver.findElement(By.cssSelector("div.tcMsgOut")).click();
driver.findElement(By.xpath("//li[3]/button")).click();
driver.findElement(By.cssSelector("div.tcMsgOut")).click();
new Select(driver.findElement(By.xpath("//td/select"))).selectByVisibleText("身份证");
driver.findElement(By.name("file")).clear();
driver.findElement(By.name("file")).sendKeys("C:\\Users\\Administrator\\Desktop\\1.png");
driver.findElement(By.xpath("//td[2]/button")).click();
driver.findElement(By.xpath("//li[3]/button")).click();
driver.switchTo().window(null);
/*
* 借款初审
*/
driver.findElement(By.xpath("//div[@id='nav_box']/ul/li/ul/li[4]/p/span")).click();
driver.switchTo().frame("myFrame");
driver.findElement(By.xpath("//td[7]/button")).click();
driver.findElement(By.xpath("//li[4]/button[3]")).click();
driver.switchTo().window(null);
driver.findElement(By.xpath("//div[@id='nav_box']/ul/li/ul/li[5]/p/span")).click();
driver.switchTo().frame("myFrame");
driver.findElement(By.xpath("//td[7]/button")).click();
driver.findElement(By.xpath("//li[5]/button[3]")).click();
driver.findElement(By.xpath("//div[@id='nav_box']/ul/li/ul/li[6]/p/span")).click();
driver.findElement(By.xpath("//td[15]/button")).click();
driver.findElement(By.xpath("(//input[@name='assetType'])[2]")).click();
driver.findElement(By.cssSelector("div.modal-footer > button.btn.btn-primary")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}