Software Testing Lab2

本文介绍了如何使用SeleniumIDE插件录制和导出脚本,通过编写Java程序验证学号与Git地址匹配性,实现自动化测试流程。

实验内容:

1、安装SeleniumIDE插件

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

3、访问https://psych.liebes.top/st使用学号登录系统(账户名为学号,密码为学号后6位),进入系统后可以看到该同学的git地址。

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

5、将测试代码提交到github上(4月15日23:59:59前)。

实验过程:

(1) 由于本机FireFox版本过新,故安装 FireFox 浏览器,版本为 42.0。并且关闭FireFox的自动更新。

(2) 安装Selenium IDE 插件

(3) 出现,表明安装成功

Selenium IDE界面如图

 

(4) 打开 Selenium IDE 插件,并开启录制。在浏览器中输入地址 https://psych.liebes.top/st 并进行访问,输入自己的学号和对应的密码后跳转到包含个人信息的页面,关闭录制

 

 

(5) 点击 “文件->Export Test Case As->Java/Junit4->WebDriver”导出脚本

 

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

用ideaIDE新建java项目,将Selenium.java 复制到src目录中。添加相关jar包

代码如下:

package cn.tju.selenium;

 

import static org.junit.Assert.assertEquals;

import static org.junit.Assert.fail;

 

import java.io.File;

import java.io.FileInputStream;

import java.util.Arrays;

import java.util.Collection;

import java.util.NoSuchElementException;

import java.util.concurrent.TimeUnit;

 

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.junit.runners.Parameterized;

import org.openqa.selenium.Alert;

import org.openqa.selenium.By;

import org.openqa.selenium.NoAlertPresentException;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

 

@RunWith(Parameterized.class)

public class Script {

private WebDriver driver;

private String baseUrl;

private boolean acceptNextAlert = true;

private StringBuffer verificationErrors = new StringBuffer();

 

private String testName;

private String testPwd;

private String gitHubUrl;

private Script sc;

 

public Script(String testName, String testPwd, String githubUrl) {

    this.testName = testName;

    this.testPwd = testPwd;

    this.gitHubUrl = githubUrl;

}

 

@Before

public void setUp() throws Exception {

    driver = new FirefoxDriver();

    baseUrl = "https://psych.liebes.top";

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

}

 

@Parameterized.Parameters

public static Collection<Object[]> getData() {

    Object[][] obj = new Object[97][];

    try {

 

        // 指定excel的路径

        File src = new File("input.xlsx");

 

        // 加载文件

        FileInputStream fis = new FileInputStream(src);

 

        // 加载workbook

        @SuppressWarnings("resource")

        XSSFWorkbook wb = new XSSFWorkbook(fis);

 

        // 加载sheet,这里我们只有一个sheet,默认是sheet1

        XSSFSheet sh1 = wb.getSheetAt(0);

        for (int i = 0; i < sh1.getPhysicalNumberOfRows(); i++) {

           obj[i] = new Object[] {

                  sh1.getRow(i).getCell(0).getStringCellValue(),

                  sh1.getRow(i).getCell(0).getStringCellValue()

                         .substring(4),

                  sh1.getRow(i).getCell(1).getStringCellValue() };

 

        }

    } catch (Exception e) {

        e.printStackTrace();

    }

    return Arrays.asList(obj);

}

 

@Test

public void testUntitledTestCase() throws Exception {

    driver.get(baseUrl + "/st");

    driver.findElement(By.id("username")).clear();

    driver.findElement(By.id("username")).sendKeys(this.testName);

    driver.findElement(By.id("password")).clear();

    driver.findElement(By.id("password")).sendKeys(this.testPwd);

    driver.findElement(By.id("submitButton")).click();

    assertEquals(this.gitHubUrl.trim(),

           driver.findElement(By.cssSelector("p.login-box-msg")).getText()

                  .trim());

}

 

@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;

    }

}

}

运行结果:

 

 

转载于:https://www.cnblogs.com/zhuchenlu/p/8849209.html

### CS61B Lab 6 Materials and Instructions The course **CS 61B** at UC Berkeley focuses on data structures, algorithms, and software engineering principles. While specific lab materials may not be directly referenced in the provided citations, similar courses such as Stanford's **CS 198B**, which covers additional topics in teaching computer science[^1], often include labs that emphasize practical implementation of theoretical concepts. For **CS 61B Lab 6**, students typically work on implementing or analyzing complex data structures like hash tables, graphs, or advanced tree structures. The exact content depends on the curriculum but generally involves: #### Task Overview Students are expected to complete tasks involving memory management or performance optimization techniques. For instance, tools mentioned in other contexts, such as `mdriver-emulate`, might simulate large-scale memory allocations across extensive address spaces[^3]. This could relate to testing custom allocators designed during the lab session. Below is an example code snippet demonstrating how one might implement part of a dynamic array structure—a common theme in Labs for this level: ```java public class DynamicArray<T> { private T[] elements; private int size; @SuppressWarnings("unchecked") public DynamicArray() { this.elements = (T[]) new Object[10]; // Initial capacity set to 10. this.size = 0; } public void add(T element) { if (size >= elements.length) { resize(); } elements[size++] = element; } private void resize() { int newSize = elements.length * 2; T[] newArray = (T[]) new Object[newSize]; System.arraycopy(elements, 0, newArray, 0, size); elements = newArray; } public T get(int index) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); return elements[index]; } } ``` This Java-based implementation showcases fundamental operations required when working with arrays dynamically resizing themselves based on input growth patterns—relevant knowledge applicable within many assignments under **CS 61B** coursework. #### Additional Resources To explore further details about potential exercises included in **Lab 6**, consider reviewing supplementary resources from comparable programs listed online through official university portals where descriptions reside[^2]. ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值