输入框选择用例java_Selenium学习_java/testNG编写测试用例实践1

Selenium学习_java/testNG编写测试用例实践1

上一篇 /

下一篇  2015-08-17 14:18:18

/ 个人分类:selenium

对某个登录页面的测试,使用了testNG测试框架

包括两个测试用例:

1、正确的用户名、密码,登录成功,验证title正确

2、错误的用户名、密码,登录失败,验证title正确

源码:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.firefox.FirefoxProfile;

import org.openqa.selenium.firefox.internal.ProfilesIni;

import org.testng.Assert;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

public class Login {

ProfilesIni allProfiles = new ProfilesIni();

FirefoxProfile profile = allProfiles.getProfile("default");

WebDriver driver;

@BeforeMethod

public void beforeLogin(){

driver=new FirefoxDriver(profile);

driver.get("http://***/auth/login");

}

//用例1:正确用户名、密码,登录成功,title正确为验证方式

@Test

public void testCase1() throws InterruptedException {

WebElement username= driver.findElement(By.id("username"));

WebElement password= driver.findElement(By.id("password"));

WebElement login = driver.findElement(By.linkText("登录"));

username.sendKeys("******");  //输入用户名

password.sendKeys("******");  //输入密码

login.click();

Thread.sleep(5000);

driver.switchTo().window(driver.getWindowHandle());

Assert.assertEquals(driver.getTitle(), "XXX");

}

//用例2:错误密码,登录失败,title正确为验证方式

@Test

public void testCase2() throws InterruptedException {

WebElement username= driver.findElement(By.id("username"));

WebElement password= driver.findElement(By.id("password"));

WebElement login = driver.findElement(By.linkText("登录"));

username.sendKeys("******");

password.sendKeys("******");

login.click();

Thread.sleep(5000);

driver.switchTo().window(driver.getWindowHandle());

Assert.assertEquals(driver.getTitle(), "登录 - XXX");

}

@AfterMethod

public void afterLogin(){

driver.close();

}

}

运行项目(run as testNG test)输出测试结果。

项目目录下生成test-output的文件夹,文件夹内的index.html页面是测试用例的运行结果报告。

TAG:

java

我来说两句

显示全部

d8a3dac35532145b347031a8fb402eba.gif

4d73fc83cb27b31041650c043e06fdc8.gif

5d06f4dc9b08a7e1fecdedaf9fe87c66.gif

659391f05d11818e0d3bd694a6d99ddc.gif

f27d7d9f67d98cc858fe74ff4d76554e.gif

b0d82b880d66765dd2a1af173b20f406.gif

e87f042c31e114675541bb49e0fbf138.gif

97a372eda248bf63679ecf2d47467589.gif

a14a392968e29ace4cb2ca390d53264e.gif

ff31a40db0d852c3704276b17a1dd158.gif

46298ad80746c3790e9535ce3396efec.gif

ef97f2303f935b723744c0c99db267f8.gif

46add61d58ae5b455d8994b1485357d3.gif

701ffdce43c5ac45c241dba6a7ae431d.gif

4ac0c1a50de5d21a8087006d0295547a.gif

e54bbadbdbb00b0b5cc4182352ca2352.gif

afb655844bdfda4cf47fef6d239f009d.gif

bf5c12b671f1179ba425de53370ebd3d.gif

865ad24093d248b0ec3b85ea66a6aaa7.gif

ab80f8b6419577f8a8ad7bb690794024.gif

内容

昵称

验证

ada834077f6a48ad60a11ec0354fde86.png

提交评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值