1. 程式人生 > >軟件測試實驗2

軟件測試實驗2

rtt AR 打開 停止 user man package urn test case

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