Selenium软件测试-脚本录制

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

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

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

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

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

Selenium软件测试-脚本录制_第1张图片
上图为Selenium IDE的Git

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

Selenium软件测试-脚本录制_第2张图片
Selenium软件测试-脚本录制_第3张图片
Selenium软件测试-脚本录制_第4张图片
Selenium软件测试-脚本录制_第5张图片
Selenium软件测试-脚本录制_第6张图片
重新启动Firefox
Selenium软件测试-脚本录制_第7张图片
点击开始录制脚本
Selenium软件测试-脚本录制_第8张图片
Selenium软件测试-脚本录制_第9张图片
Selenium软件测试-脚本录制_第10张图片
结束录制,保存录制的脚本
Selenium软件测试-脚本录制_第11张图片
Selenium软件测试-脚本录制_第12张图片
导出Java测试脚本
Selenium软件测试-脚本录制_第13张图片
导出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 vars;
  JavascriptExecutor js;
  @Before
  public void setUp() {
    driver = new FirefoxDriver();
    js = (JavascriptExecutor) driver;
    vars = new HashMap();
  }
  @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();
  }
}

你可能感兴趣的:(Test)