您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源功能測(cè)試工具 > Selenium
Selenium右鍵下載圖片,結(jié)合sikuli
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2015/6/9 13:57:31 ] 推薦標(biāo)簽:功能測(cè)試工具

  有關(guān)sikuli的介紹,和簡(jiǎn)單使用請(qǐng)參考:http://www.cnblogs.com/tobecrazy/p/4516369.html
  關(guān)于sikuli的缺點(diǎn):
  1.運(yùn)行腳本時(shí)候,必須截圖,圖片比較占用系統(tǒng)空間
  2.腳本執(zhí)行過程中,不能移動(dòng)鼠標(biāo),而selenium可以小化,任意移動(dòng)鼠標(biāo)
  話不多說,介紹一下場(chǎng)景:
  1.打開百度
  2.右鍵單擊百度logo
  3.點(diǎn)擊彈出菜單的save as
  4. 輸入保存位置和文件名
  5. 點(diǎn)擊保存菜單
  首先要做的是,截圖,截圖保存位置c:/selenium
  腳本如下:
//create chrome webDriver with parameter
ChromeOptions options = new ChromeOptions();
options.addArguments("--test-type");
Screen screen=new Screen();
System.setProperty("webdriver.chrome.driver", "C:\webdriver\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
String login_url="https://www.baidu.com/";
driver.get(login_url);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
//find baidu logo
WebElement baiduLogo=driver.findElement(By.xpath("//div[@id='lg']/img"));
Actions actions = new Actions(driver);
//right click
actions.contextClick(baiduLogo).perform();
Pattern saveAs =new Pattern("c:\selenium\saveAs.png");
screen.click(saveAs);
Pattern inputBox1 =new Pattern("c:\selenium\inputBox1.png");
screen.find(inputBox1);
screen.type("c:\selenium\baiduLogo.png");
Pattern saveButton =new Pattern("c:\selenium\saveButton.png");
screen.click(saveButton);
//wait for 60s to verify download success or not
try
{
Thread.sleep(60000);
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
File f=new File("c:\selenium\baiduLogo.png");
if(f.exists())
{
System.out.println("PASS");
}
driver.close();
}

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