zoukankan      html  css  js  c++  java
  • 在SoapUI中模拟用户操作

    SoapUI作为一款接口测试工具,具有极大的灵活性和拓展性。它可以通过安装插件,拓展其功能。Selenium作为一款Web自动化测试插件可以很好的与SoapUI进行集成。如果要在SoapUI中模拟用户点击界面的功能,不借助selenium是无法完成的。

    一、准备工作 - 给SoapUI安装selenium插件

    1. 首先,我们需要下载selenium的网站(https://docs.seleniumhq.org/download/)下载server-standalone版本,这里以selenium-server-standalone.jar 2.25.0为例。由于官网的下载地址需要经过google网址才能下载到,这里提供从maven仓库下载的办法:进入http://www.mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server-standalone,找到适合的版本,将maven的配置copy到项目中,然后等maven下载jar到本地。找到maven本地缓存的目录,在里面可以找到selenium的jar包了。

    2. 将这个jar复制一份放入"${SoapUI安装目录inext}"。如果你的SoapUI是默认安装的,则这个目录为:C:Program FilesSmartBearSoapUI-5.3.0inext。复制完之后,重启SoapUI(如果你在复制之前已经打开了SoapUI的话)

    二、测试场景

    这里以模拟用户在百度输入关键字“test”进行搜索为例。首先我们在项目里面新建一个Grovvy Script,输入以下脚本,执行之后就可以找到百度第一页的所有搜索结果的联接了:

     完整的脚本:

     1 import org.openqa.selenium.By;
     2 import org.openqa.selenium.WebElement;
     3 import org.openqa.selenium.firefox.FirefoxDriver;
     4 import org.openqa.selenium.firefox.FirefoxProfile;
     5 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
     6 import org.openqa.selenium.ie.InternetExplorerDriver;
     7 import org.openqa.selenium.remote.CapabilityType;
     8 import org.openqa.selenium.remote.DesiredCapabilities;
     9 import org.openqa.selenium.support.ui.ExpectedConditions;
    10 import org.openqa.selenium.support.ui.WebDriverWait;
    11 
    12 def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    13 
    14 //初始化HTMLUnitDriver(headless browser)
    15 HtmlUnitDriver driver = new HtmlUnitDriver();
    16 
    17 //在headless browser中打开网址
    18 driver.get("https://www.baidu.com");
    19 
    20 //log.info(driver.getPageSource());
    21 
    22 //找到输入框,并在框中输入“test”
    23 WebElement input = driver.findElement(By.name("wd"));
    24 input.sendKeys("test");
    25 
    26 //找到搜索按钮,并点击
    27 WebElement button = driver.findElement(By.id("su"));
    28 button.click();
    29 
    30 
    31 //寻找出左边显示搜索结果的div
    32 //System.out.println(driver.getPageSource());
    33 WebElement container = driver.findElement(By.id("content_left"));
    34 
    35 //将所有超链接打印出来
    36 List<WebElement> list = container.findElements(By.tagName("a"));
    37 
    38 for (WebElement ele : list) {
    39   log.info(ele.getAttribute("href"));
    40 }
    41 
    42 //4. close browser window
    43 driver.close();
    44 driver.quit();
    45 
    46 //5. assert
    47 assert list.size()>0
  • 相关阅读:
    软件工程个人作业01
    动手动脑
    大道至简感想终结篇
    课后作业
    反思
    课后作业
    不忘初心,方得始终
    课后作业
    沟通,让一切变得简单

  • 原文地址:https://www.cnblogs.com/liszt/p/8695670.html
Copyright © 2011-2022 走看看