码迷,mamicode.com
首页 > 其他好文 > 详细

软件测试实验2

时间:2018-04-12 23:58:43      阅读:378      评论:0      收藏:0      [点我收藏+]

标签:https   ndk   reg   als   class   下载   buffer   import   img   

Selenium上机实验说明

1、安装SeleniumIDE插件

下载Firefox 43.0.1,添加组件seleniumIDE,打开该组件,右上角红色圆为空心时为录制状态,实心时为停止录制:

技术分享图片

 

2、使用SeleniumIDE录制脚本和导出脚本

录制完成后,可以导出Test Case:

技术分享图片

导出的java代码为:

package com.example.tests;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class TestSelenium {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "https://psych.liebes.top/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testSelenium() throws Exception {
    driver.get(baseUrl + "/st");
    driver.findElement(By.id("username")).clear();
    driver.findElement(By.id("username")).sendKeys("3015218071");
    driver.findElement(By.id("password")).clear();
    driver.findElement(By.id("password")).sendKeys("218071");
    driver.findElement(By.id("submitButton")).click();
  }

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}

 

3、编写Selenium Java WebDriver程序,测试input.xlsx表格中的学号和git地址的对应关系是否正确。

 

软件测试实验2

标签:https   ndk   reg   als   class   下载   buffer   import   img   

原文地址:https://www.cnblogs.com/wll560/p/8811291.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!