您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium配合sikuli script操作高德地圖
作者:網(wǎng)絡轉(zhuǎn)載 發(fā)布時間:[ 2015/6/2 10:22:13 ] 推薦標簽:功能測試工具

  實例二, 配合selenium webdriver 測試高德地圖
  1.打開地圖
  2.選擇北京
  3.打開地圖的工具,選擇測距
  3.選擇天安門
  4.選擇到這里去
  5.選擇輸入并搜索,火車站
  precondition:
  截圖:

Debug.setDebugLevel(3);
Screen s = new Screen();
String URL = "http://www.amap.com/";
WebDriver driver = DriverFactory.getFirefoxDriver();
Actions actions = new Actions(driver);
driver.get(URL);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
WebElement chooseCityElement = driver.findElement(By
.xpath("//div/span[@class='icon_expand cursor ml5']"));
chooseCityElement.click();
WebElement city_iframe = driver.findElement(By
.xpath("//iframe[@id='city_iframe']"));
driver.switchTo().frame(city_iframe);
//選擇北京
WebElement BJ = driver.findElement(By.xpath("//div/a[text()='北京']"));
BJ.click();
//等待頁面加載
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.switchTo().defaultContent();
//打開工具 選擇測距
WebElement tools=driver.findElement(By.xpath("//div/span[text()='工具']"));
actions.moveToElement(tools).click().perform();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
Pattern cj=new Pattern("D:\MyBlog\CJ.png");
if(s.find(cj) != null)
{
s.click(cj);
}
Pattern bjbz=new Pattern("D:\MyBlog\BJBZ.png");
s.click(bjbz);
Pattern bjnz=new Pattern("D:\MyBlog\BJNZ.png");
s.click(bjnz);
s.rightClick();
WebElement inputBoxElement = driver.findElement(By
.xpath("//input[@id='keywordTxt']"));
WebElement searchButton = driver.findElement(By
.xpath("//input[starts-with(@class,'magnifier_button')]"));
inputBoxElement.clear();
inputBoxElement.sendKeys("天安門");
searchButton.submit();
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
WebElement tiAnMenElement = driver.findElement(By
.xpath("//div[@title='天安門']"));
tiAnMenElement.click();
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
WebElement comeToHereElement = driver.findElement(By
.xpath("//div[@class='route']//li[text()='到這里去']"));
comeToHereElement.click();
WebElement setStartLocationElement = driver.findElement(By
.xpath("//div/input[@class='route-input srh-ipt']"));
setStartLocationElement.sendKeys("火車站");
WebElement routeByBus = driver.findElement(By
.xpath("//div[@id='rout-by-bus']"));
routeByBus.click();
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
WebElement startFrom = driver
.findElement(By
.xpath("//div[@class='start_end_item_title' and contains(text(),'北京站')]"));
actions.moveToElement(startFrom)
.click(driver.findElement(By
.xpath("//a[contains(text(),'設為起點') and @data-name='北京站']")))
.perform();
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//div[@class='amap-zoom-plus']")).click();
  到此為止,selenium配合sikuli的探索結(jié)束了,更多更好玩的玩法,會進一步更新

上一頁12下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd