资源简介

西北工业大学,软件学院,软件测试实验4,实验 - Selenium实现web测试,包含实验报告,实验代码,测试用例

资源截图

代码片段和文件信息

// 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.chrome.ChromeDriver;
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.*;
public class Test4Test {
  private WebDriver driver;
  private Mapject> vars;
  javascriptExecutor js;
  @Before
  public void setUp() {
    driver = new FirefoxDriver();
    js = (javascriptExecutor) driver;
    vars = new HashMapject>();
  }
  @After
  public void tearDown() {
    driver.quit();
  }
  public String waitForWindow(int timeout) {
    try {
      Thread.sleep(timeout);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    Set whNow = driver.getWindowHandles();
    Set whThen = (Set) vars.get(“window_handles“);
    if (whNow.size() > whThen.size()) {
      whNow.removeAll(whThen);
    }
    return whNow.iterator().next();
  }
  @Test
  public void test4() {
    driver.get(“https://www.jd.com/“);
    driver.manage().window().setSize(new Dimension(1550 838));
    vars.put(“window_handles“ driver.getWindowHandles());
    driver.findElement(By.linkText(“你好,请登录“)).click();
    vars.put(“win8286“ waitForWindow(2000));
    vars.put(“root“ driver.getWindowHandle());
    driver.switchTo().window(vars.get(“win8286“).toString());
    driver.close();
    driver.switchTo().window(vars.get(“root“).toString());
    driver.findElement(By.id(“key“)).click();
    driver.findElement(By.id(“key“)).sendKeys(“羽毛球“);
    driver.findElement(By.id(“key“)).sendKeys(Keys.ENTER);
    driver.findElement(By.id(“key“)).sendKeys(“羽毛球“);
    driver.findElement(By.id(“key“)).sendKeys(Keys.ENTER);
    driver.findElement(By.id(“key“)).sendKeys(“羽毛球“);
    vars.put(“window_handles“ driver.getWindowHandles());
    driver.findElement(By.cssSelector(“.hover .p-img img“)).click();
    vars.put(“win9“ waitForWindow(2000));
    driver.switchTo().window(vars.get(“win9“).toString());
    js.executescript(“window.scrollTo(082.4000015258789)“);
    driver.findElement(By.linkText(“+“)).click();
    driver.findElement(By.linkText(“+“)).click();
    {
      WebElement element = driver.findElement(By.linkText(“+“));
      Actions builder = new Actions(driver);
      builder.doubleClick(element).perform();
    }
    {
      WebElement element = driver.findElement(By.linkText(“+“));
      Actions builder = new Actions(driver);
      builder.doubleClick(element).perf

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件      582492  2018-11-23 09:47  lab4\Selenium插件安装及场景录制 - FireFox.docx
     文件     1016832  2018-11-23 10:23  lab4\selenium介绍.ppt
     目录           0  2020-07-13 20:53  lab4\web测试\
     文件        3049  2019-11-23 11:18  lab4\web测试\Test4Test.java
     文件     1967329  2019-11-23 14:27  lab4\web测试\实验报告.docx
     文件         115  2019-11-23 13:51  lab4\web测试\测试用例.txt
     文件       36352  2019-11-15 20:45  lab4\实验 - Selenium实现web测试.doc
     目录           0  2020-07-13 20:53  lab4\

评论

共有 条评论