package testweb;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.runners.Parameterized.Parameters;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;
public class Test_web {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Parameters
public static List<String[]> getParams()
{
return Arrays.asList(new String[][]{{"13999999998","123456"},
{"17166666666","123456"},
{"15989486910","a123456"}});
}
private String loginName; //用户名
private String passWd; //密码
public void TestClass(String loginName,String passWd)
{
this.loginName=loginName;
this.passWd=passWd;
}
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.firefox.bin", "E:\\Firefox\\firefox.exe");
driver = new FirefoxDriver();
baseUrl = "xxxxxx";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
//登录测试
@Test
public void testDL() throws Exception {
//driver.switchTo().frame("xxName");
driver.get(baseUrl);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// WebElement element = (new WebDriverWait(getDriver(), 10)).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input#houseName")));
// WebDriverWait wait = new WebDriverWait(driver, 40);
//WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
driver.findElement(By.cssSelector("input.pc-register-input.login-phone")).clear();
driver.findElement(By.cssSelector("input.pc-register-input.login-phone")).sendKeys("13999999998");
driver.findElement(By.cssSelector("input.pc-register-input.login-psd")).clear();
driver.findElement(By.cssSelector("input.pc-register-input.login-psd")).sendKeys("123456");
driver.findElement(By.cssSelector("button.register-bottom-btn")).click();
Thread.sleep(5000);
try{
if(driver.findElement(By.cssSelector("a.go-out")).equals("退出"))
System.out.println("登录成功!");
}
catch (Exception e){
System.out.println("登录失败,请检查服务!");
}
//截图
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
driver.findElement(By.cssSelector("button.register-bottom-btn")).click();
driver.findElement(By.cssSelector("button.account-mask-recharge")).click();
driver.findElement(By.xpath("//input[@type='text']")).click();
driver.findElement(By.xpath("//input[@type='text']")).clear();
driver.findElement(By.xpath("//input[@type='text']")).sendKeys("卜民佑");
driver.findElement(By.xpath("(//input[@type='text'])[2]")).click();
driver.findElement(By.xpath("(//input[@type='text'])[2]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[2]")).sendKeys("");
driver.findElement(By.xpath("(//input[@type='text'])[3]")).clear();
driver.findElement(By.xpath("(//input[@type='text'])[3]")).sendKeys("");
driver.findElement(By.id("prov")).click();
new Select(driver.findElement(By.id("prov"))).selectByVisibleText("河北省");
new Select(driver.findElement(By.id("city"))).selectByVisibleText("秦皇岛市");
driver.findElement(By.xpath("//input[@type='password']")).clear();
driver.findElement(By.xpath("//input[@type='password']")).sendKeys("123456");
driver.findElement(By.xpath("(//input[@type='password'])[2]")).clear();
driver.findElement(By.xpath("(//input[@type='password'])[2]")).sendKeys("123456");
driver.findElement(By.cssSelector("button.zyxr-btn")).click();
driver.findElement(By.xpath("//input[@type='password']")).click();
}
//开户
//充值测试
@Test
public void testCZ() throws Exception {
driver.findElement(By.cssSelector("button.perc-head-btn")).click();
driver.findElement(By.cssSelector("input.zyxr-input.recharge-input-width")).clear();
driver.findElement(By.cssSelector("input.zyxr-input.recharge-input-width")).sendKeys("100");
driver.findElement(By.xpath("//div[3]/div/span/i")).click();
driver.findElement(By.cssSelector("div.recharge-bank-one.recharge-bank-click")).click();
driver.findElement(By.cssSelector("button.zyxr-btn.recharge-btn-left")).click();
driver.findElement(By.cssSelector("button.zyxr-btn.recharge-btn-left")).click();
driver.findElement(By.cssSelector("button.zyxr-btn.recharge-btn-left")).click();
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
try{
} catch (Exception e) {
// TODO: handle exception
}
}
//提现测试
@Test
public void testTX() throws Exception {
driver.get(baseUrl + "/personal_center/withdraw_cash.html");
driver.findElement(By.linkText("提现")).click();
driver.findElement(By.cssSelector("input.zyxr-input.recharge-input-width")).clear();
driver.findElement(By.cssSelector("input.zyxr-input.recharge-input-width")).sendKeys("100");
driver.findElement(By.cssSelector("button.zyxr-btn.recharge-btn-left")).click();
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
}
@After
public void tearDown() throws Exception {
//driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
//driver.switchTo().frame();
//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;
}
}
}