软件测试实验2
Posted wll560
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了软件测试实验2相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
typescript Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming/angular-2/
typescript Angular最终版本的Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming
typescript Angular最终版本的Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming