-
在火狐浏览器安装selenium IDE插件
-
在搜索框搜索selenium并添加到Firefox
安装好后便会在右上角显示,点击即可打开。
3 Web软件功能界面测试
3.1.创建一个新的测试项目,并命名,然后点击OK
3.2 输入当测试的web应用URL地址,点击START RECORDING开始录制。我做的是超星学习通登录测试 。
点击START RECORDING 跳出以下网页
登录测试,输入错误的验证码
输入错误的密码
正确输入,成功登录系统
完成录制
将录制的脚本导出为你想要的语言,此处我选择的Java语言
选择保存位置及文件名,点击保存进行保存
4.录制的脚本代码为:
// 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.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
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.*;
import java.net.MalformedURLException;
import java.net.URL;
public class UntitledTest {
private WebDriver driver;
private Map<String, Object> vars;
JavascriptExecutor js;
@Before
public void setUp() {
driver = new FirefoxDriver();
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}
@After
public void tearDown() {
driver.quit();
}
@Test
public void untitled() {
driver.get("http://passport2.chaoxing.com/login?fid=1867&refer=http://i.mooc.chaoxing.com");//测试网址
driver.manage().window().setSize(new Dimension(1295, 735));
driver.findElement(By.id("unameId")).click();
driver.findElement(By.id("unameId")).sendKeys("18673910272");//账号
driver.findElement(By.cssSelector("body")).click();
driver.findElement(By.id("passwordId")).click();
driver.findElement(By.id("passwordId")).sendKeys("11121112");//密码
driver.findElement(By.cssSelector(".zlogin1")).click();
driver.findElement(By.id("passwordId")).click();
driver.findElement(By.id("passwordId")).sendKeys("111211");
driver.findElement(By.cssSelector(".table_nvc > div")).click();
driver.findElement(By.id("numcode")).click();
driver.findElement(By.id("numcode")).sendKeys("8641");//验证码
driver.findElement(By.cssSelector(".zl_btn_right")).click();
{
WebElement element = driver.findElement(By.cssSelector(".zl_btn_right"));
Actions builder = new Actions(driver);
builder.moveToElement(element).perform();
}
{
WebElement element = driver.findElement(By.tagName("body"));
Actions builder = new Actions(driver);
builder.moveToElement(element, 0, 0).perform();
}
driver.findElement(By.id("passwordId")).click();
driver.findElement(By.id("passwordId")).sendKeys("1232144");
driver.findElement(By.id("numcode")).click();
driver.findElement(By.id("numcode")).sendKeys("3717");
driver.findElement(By.cssSelector(".zl_btn_right")).click();
driver.findElement(By.id("passwordId")).click();
driver.findElement(By.id("passwordId")).sendKeys("11121112");
driver.findElement(By.cssSelector(".table_nvc > div")).click();
driver.findElement(By.id("numcode")).click();
driver.findElement(By.id("numcode")).sendKeys("5850");
driver.findElement(By.cssSelector(".zl_btn_right")).click();
driver.close();
driver.findElement(By.id("unameId")).click();
driver.findElement(By.id("unameId")).sendKeys("15660260444");
driver.findElement(By.cssSelector("tr:nth-child(3) > .zl_name")).click();
driver.findElement(By.id("passwordId")).click();
driver.findElement(By.id("passwordId")).sendKeys("112324112345");
driver.findElement(By.cssSelector(".table_nvc > div")).click();
driver.findElement(By.id("numcode")).click();
driver.findElement(By.id("numcode")).sendKeys("7324");
driver.findElement(By.cssSelector(".zl_btn_right")).click();
driver.findElement(By.id("passwordId")).click();
driver.findElement(By.id("passwordId")).sendKeys("12412341235");
driver.findElement(By.id("numcode")).click();
driver.findElement(By.id("numcode")).click();
driver.findElement(By.id("numcode")).sendKeys("0670");
driver.findElement(By.cssSelector(".zl_btn_right")).click();
driver.findElement(By.id("passwordId")).click();
driver.findElement(By.id("passwordId")).sendKeys("11121112");
driver.findElement(By.id("numcode")).click();
driver.findElement(By.id("numcode")).sendKeys("1581");
driver.findElement(By.cssSelector(".zl_btn_right")).click();
driver.findElement(By.id("passwordId")).click();
driver.findElement(By.id("passwordId")).sendKeys("11121112");
driver.findElement(By.id("numcode")).click();
driver.findElement(By.id("numcode")).sendKeys("5885");
driver.findElement(By.cssSelector(".zl_btn_right")).click();
}
}