多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

Selenium结合sikuli右键下载图片-自动化测试

更新时间:2022-04-29 09:09:12 作者:多测师 浏览:71

  1.打开百度

  2.右键单击百度logo

  3.点击弹出菜单的save as

  4. 输入保存位置和文件名

  5. 点击保存菜单

  首先要做的是,截图,截图保存位置c:/selenium

Selenium结合sikuli右键下载图片-自动化测试

  脚本如下:

  //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();

  }

  以上内容为大家介绍了自动化测试中的Selenium结合sikuli右键下载图片,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部