自动化测试题目某旅游网站题目
2020-12-13 03:33
标签:class java c ext http int import java.util.ArrayList; import javax.swing.Spring; import junit.framework.Assert; import org.openqa.selenium.By; public class SeleniumHelper { public static void main(String[] arg) { //
C:\Users\Administrator.PC-20121111FEJF\AppData\Local\Google\Chrome\Application List cityist = new
ArrayList int maxIteration = 1; String eCityname = (String) cityist.get(indexECity); Calendar c = getSpecifiedDay(7); } } /** /** // 执行规则验证 setSngStatus(driver);// 保证选择单选 WebElement sinput =
driver.findElement(By.name("fromCity")); List if (feeEveryParts == null) { WebElement emptyMark =
driver } WebElement feeEveryPart =
driver.findElement(By WebElement lineAClick = driver List // 有查查询列表 if (priceRange != null) { } WebElement result = (WebElement) ((JavascriptExecutor)
driver) Assert.assertEquals(result == null, "发生错误"); driver.quit(); } /** } // 获取随机数 } 不行了,实在困了。先写到这吧,欢迎大家批评啊。算是抛砖引玉,代码的实现不好啊,架构啊,方法名什么的都没考虑啊。以后在优化吧。 自动化测试题目某旅游网站题目,搜素材,soscw.com 自动化测试题目某旅游网站题目 标签:class java c ext http int 原文地址:http://www.cnblogs.com/wcLT/p/3726645.html
import java.util.Calendar;
import
java.util.List;
import java.util.Random;
import java.util.Date;
import
java.text.DateFormat;
import java.text.SimpleDateFormat;
import
org.openqa.selenium.JavascriptExecutor;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.chrome.ChromeDriver;
import
org.openqa.selenium.firefox.FirefoxDriver;
// 组和100组
数据
System.setProperty(
"webdriver.chrome.driver",
"C:\\Users\\Administrator.PC-20121111FEJF\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe");
cityist.add("北京");
cityist.add("上海");
cityist.add("昆明");
cityist.add("西安");
cityist.add("广州");
cityist.add("南京");
cityist.add("重庆");
cityist.add("大连");
cityist.add("青岛");
cityist.add("郑州");
cityist.add("成都");
// 总验证次数
for (int index = 0; index String sCityname = (String)
cityist.get(index);
for (int indexECity = 1; indexECity
if
(maxIteration > 3) {
//
最大次数,退出,防止无限制的迭代
break;
}
Date current = new Date();
try
{
validateWebPage(sCityname, eCityname, current, c.getTime());
}
catch (InterruptedException e) {
// TODO Auto-generated catch
block
e.printStackTrace();
}
maxIteration++;
}
* @param step
* @return
*/
private static Calendar
getSpecifiedDay(int step) {
Calendar c =
Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, step);
return
c;
}
* @param driver
*/
private static void
setSngStatus(WebDriver driver) {
WebElement sngWebElement =
driver.findElement(By.id("searchTypeSng"));
sngWebElement.click();
}
private static void validateWebPage(String sCityName, String
eCityName,
Date sDate, Date eDate) throws InterruptedException
{
WebDriver driver = new
ChromeDriver();
driver.get("http://flight.qunar.com");
sinput.sendKeys(sCityName);
WebElement
einput =
driver.findElement(By.name("toCity"));
einput.sendKeys(eCityName);
WebElement
sDateinput =
driver.findElement(By.name("fromDate"));
sDateinput.sendKeys(getStringFromDate(sDate));
//
显示数据,将不可用的状态的控件改为可用
((JavascriptExecutor)
driver)
.executeScript("$(\"#dom_arrivalDateDiv_disable\").click()");
WebElement
eDateinput =
driver.findElement(By.name("toDate"));
eDateinput.clear();
eDateinput.sendKeys(getStringFromDate(eDate));
WebElement
submitCtl =
driver.findElement(By.className("btn_txt"));
submitCtl.submit();//
发送请求
Thread.sleep(1000);// 页面等待1分钟
.cssSelector("span.highlight"));
.findElement(By.className("e_fly_lst"));
Assert.assertEquals(emptyMark
== null, "没有找到提示信息");
return;
.cssSelector("span.highlight"));
.findElement(By.className(".b_avt_lst
a"));
lineAClick.click();
// 分析结果
if (feeEveryPart != null)
{
// 此时,有AB2端
.cssSelector(".e_qvt_route h3"));
Boolean
first = elements.get(0).getText().contains("第一");
Assert.assertEquals(first,
"提示信息错误");
Boolean sencond =
elements.get(1).getText().contains("第二");
Assert.assertEquals(sencond,
"提示信息错误");
} else {
// 没有航费
WebElement priceRange =
driver.findElement(By
.cssSelector("qvt_col_more"));
String contente =
priceRange.getText();
Assert.assertEquals(contente.contains("报价范围"),
"发生错误");
}
.executeScript("var query= $(\".e_qvt_hd\"); return query;");
* @param eDate
* @return
*/
@SuppressWarnings("deprecation")
private static String
getStringFromDate(Date eDate) {
return
DateFormat.getDateInstance(DateFormat.DEFAULT).format(eDate);
private static int getSpecifiedRandom(int inputNo) {
if
(inputNo inputNo = 10;
Random random = new
Random();
return random.nextInt(inputNo);
}
上一篇:JS对象/数组/识别对象数组
下一篇:[JS2] JS是弱类型