Selenium软件测试-脚本录制

Selenium是软件功能自动化测试工具,功能测试的工作量非常巨大,研发团队每提交一个Build,所有的功能测试用例都需要重新验证一次,如果辅助功能自动化测试工具,测试人员的工作量将大大减低,可以腾出更多时间研究新测试工具和性能测试工具。

Selenium分为很多组件,每个组件专注不同的功能,并且有些组件也会被新版本产品中放弃。

Selenium IDE 脚本录制工具,当前只能在Firefox中使用,其他浏览器的还没有退出,使用它可以将用户操作录制为脚本。脚本可以转化为为Java,Python,C#等。

如下解释按照和录制脚本过程

一、进入官网
https://www.seleniumhq.org/download/

在这里插入图片描述
上图为Selenium IDE的Git

二、打开Firefox,查询组件Selenium-IDE

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
重新启动Firefox
在这里插入图片描述
点击开始录制脚本
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
结束录制,保存录制的脚本
在这里插入图片描述
在这里插入图片描述
导出Java测试脚本
在这里插入图片描述
导出Java测试脚本

// Generated by Selenium IDE
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNot.not;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
public class Test {
  private WebDriver driver;
  private Map<String, Object> vars;
  JavascriptExecutor js;
  @Before
  public void setUp() {
    driver = new FirefoxDriver();
    js = (JavascriptExecutor) driver;
    vars = new HashMap<String, Object>();
  }
  @After
  public void tearDown() {
    driver.quit();
  }
  @Test
  public void test() {
    driver.get("http://localhost:6060/");
    driver.manage().window().setSize(new Dimension(1382, 744));
    driver.findElement(By.id("loginId")).click();
    driver.findElement(By.id("loginId")).sendKeys("admin");
    driver.findElement(By.id("pwd")).click();
    driver.findElement(By.id("pwd")).sendKeys("1");
    driver.findElement(By.id("loginbtn")).click();
    driver.findElement(By.cssSelector(".easyui-linkbutton .l-btn-text")).click();
  }
}

发布了189 篇原创文章 · 获赞 34 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qixiang_chen/article/details/89447839