业务场景:在www.1905.com电影网中实现两个用户的登陆操作。

代码如下:

package com.m1905.junit;

import java.util.Arrays;
import java.util.Collection; import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait; @RunWith(Parameterized.class)
public class LoginParameterTest {
private static WebDriver driver;
private static Navigation navigate;
private static String url="http://www.1905.com"; @BeforeClass
public static void setUpBeforeClass() throws Exception {
driver = new FirefoxDriver();
navigate = driver.navigate();
navigate.to(url);
driver.manage().window().maximize();
}
private String username;
private String password;
public LoginParameterTest(String username,String password){
this.username = username;
this.password = password;
}
@Parameters
public static Collection<Object[]> prepareData(){
Object[][] object = {{"user1","pwd1"},{"user2","pwd2"}};
return Arrays.asList(object);
}
@Test
public void testLogin() {
try {
Thread.sleep(8000);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebElement LogAndReg = driver.findElement(By.xpath(".//*[@id='site_nav_md']/ul/li[2]/a"));
LogAndReg.click();
WebElement usernameBox = driver.findElement(By.xpath(".//*[@id='inputUsername']"));
WebElement passwordBox = driver.findElement(By.xpath(".//*[@id='inputPassword']"));
WebElement loginButton = driver.findElement(By.xpath(".//*[@id='loginreg']/div/div[1]/form/p/button"));
usernameBox.clear();
usernameBox.sendKeys(username);
passwordBox.sendKeys(password);
loginButton.click();
WebDriverWait wait = new WebDriverWait(driver,10);
WebElement logoutButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='site_nav_md']/ul/li[3]/a[2]")));
logoutButton.click();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
driver.close();
}
}

selenium+junit4实现参数化自动化测试的更多相关文章

  1. Selenium+excel实现参数化自动化测试

    使用到的技术:POI对excel的解析.selenium自动化测试.junit 测试用例:登陆www.1905.com执行登陆-退出的操作 执行步骤: 1.首先创建一个excel,里面有用户名和密码列 ...

  2. Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考

    Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考 //System.setProperty("webdriver.firefox.bin" ...

  3. 基于Selenium+Python的web自动化测试框架

    一.什么是Selenium? Selenium是一个基于浏览器的自动化测试工具,它提供了一种跨平台.跨浏览器的端到端的web自动化解决方案.Selenium主要包括三部分:Selenium IDE.S ...

  4. 爬虫(五)—— selenium模块启动浏览器自动化测试

    目录 selenium模块 一.selenium介绍 二.环境搭建 三.使用selenium模块 1.使用chrome并设置为无GUI模式 2.使用chrome有GUI模式 3.查找元素 4.获取标签 ...

  5. Selenium(Webdriver)自动化测试常问问题

    http://blog.sina.com.cn/s/blog_c189e2590102w3bv.html Selenium(Webdriver)自动化测试常问问题 (1)selenium中如何保证操作 ...

  6. Junit4进行参数化测试

    @RunWith, 当类被@RunWith注解修饰,或者类继承了一个被该注解修饰的类,JUnit将会使用这个注解所指明的运行器(runner)来运行测试,而不是JUnit默认的运行器. 要进行参数化测 ...

  7. 自动化测试基础篇--Selenium中数据参数化之TXT

    摘自https://www.cnblogs.com/sanzangTst/p/7722594.html 一.搜索参数化 在TXT文件中保存需要搜索的内容: 测试代码: 1 #!/usr/bin/env ...

  8. Selenium(十四):自动化测试模型介绍、模块化驱动测试案例、数据驱动测试案例

    1. 自动化测试模型介绍 随着自动化测试技术的发展,演化为了集中模型:线性测试.模块化驱动测试.数据驱动测试和关键字驱动测试. 下面分别介绍这几种自动化测试模型的特点. 1.1 线性测试 通过录制或编 ...

  9. selenium基础(参数化脚本)

    参数化脚本 什么是参数化 参数化就是用包含多组数据的参数列表,使之替换脚本中的响应常量值,这样,在脚本运行的时候,就会使用参数表中的数据来代替脚本中的常量值 由于参数表中包含了多组数据,所以执行用例时 ...

随机推荐

  1. sql 两大类 DDL数据定义语言 和DCL数据控制语言

    SQL分为五大类: DDL:数据定义语言   DCL:数据控制语言     DML:数据的操纵语言  DTL:数据事务语言  DQL:数据查询语言. DDL (date definition lang ...

  2. linux 学习管道 和重定向

    开源文化的理念之一 就是不要重新发明轮子 在linux 系统中大多是都是非常简单的命令,每个命令都是实现一个或者几个简单的功能,我们可以将不同的命令组合在一起 来达到复杂的功能的目的,在linux中因 ...

  3. System.Timers.Timer用法

    System.Timers.Timer t = new System.Timers.Timer(5000); //设置时间间隔为5秒 private void Form1_Load(object se ...

  4. Freemark与spring整合

    SpringMVC环境的搭建在这里就不多说了,我们这节主要是FreeMarker与SpringMVC整合 首先,在springmvc的配置文件普通视图之前,加入freemarker的视图 fre-se ...

  5. Nhibernate 存储过程获取返回值

    写在前面:因为项目使用ssh.net所以做着做着要调用存储过程,而且是有返回值的,按照以前的做法直接在参数里指定下就可以获取,但是在nhibernate里调用就有点陌生了,百度一下得出的结果有两种:第 ...

  6. 7z文件格式及其源码的分析(四)

    这是7z文件格式及其源码的分析系列的第四篇. 上一篇讲到了7z文件静态结构的尾header部分.这一篇开始,将从7z实际压缩流程开始详细介绍7z文件尾header的详细结构. 一, 第一个概念: co ...

  7. Android之常用开发框架

    1.Rajawali介绍:安卓的OpenGL ES 2.0/3.0 引擎.可以用于制作普通应用或者动态壁纸,当然也可以用于制作游戏.项目地址: https://github.com/Rajawali/ ...

  8. windows中卸载Jenkins

    背景: 之前安装的Jenkins没有pipeline选项,可能是之前安装时没有选择建议插件.后面使用最新版本时还是没有插件 解决: 卸载Jenkins,删除掉C:\Users\用户名\.jenkins ...

  9. mysqli扩展库---事务控制

    1, 有一张银行账号表 create table account( id int primary key, balance float ); 2,现在有一段php程序,要完成把1号10元钱,转到2号账 ...

  10. Android 中 DrawerLayout + ViewPager 怎么解决滑动冲突?

    DrawerLayout 是 Android 官方的侧滑菜单控件,而 ViewPager 相信大家都很熟悉了.今天这里就讲一下当在 DrawerLayout 中嵌套 ViewPager 时,要如何解决 ...