业务场景:在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. Mybatis 多个Mapper

    在实际应用中的,会有较多个mapper.如果每新建一个mapper,就向SqlMapConfig上加上对应的配置文件,会十分不便. 可以新建一个package,在其下面放置Mapper.java,同时 ...

  2. Java泛型(泛型接口、泛型类、泛型方法)

    转载 转载出处:https://www.cnblogs.com/JokerShi/p/8117556.html 泛型接口: 定义一个泛型接口: 通过类去实现这个泛型接口的时候指定泛型T的具体类型. 指 ...

  3. U盘安装Centos6.2

    原文地址:http://www.dedecms.com/knowledge/servers/linux-bsd/2012/0819/8452.html. 第一步:制作系统U盘(略). 第二步:设置BI ...

  4. Maven项目常见错误

    一.Cannot change version of project facet Dynamic Web Module to 3.0. 和 One or more constraints have n ...

  5. asp.net 汉字转拼音类

    前段时间公司人员反应OA里的汉字拼音首字母不准他们又要用,没办法自己就从网上搜有没有好的,看了很多都是首字母拼不出来或有些字母变为另一个,但最后找了很多还是有一个好用的,暂未发现有不准的. using ...

  6. C语言C++编程学习:排序原理分析

    C语言是面向过程的,而C++是面向对象的 C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到输出(或实现 ...

  7. node.js 转载:有效

    二.安装Node.js步骤 1.下载对应你系统的Node.js版本:https://nodejs.org/en/download/2.选安装目录进行安装3.环境配置4.测试 三.前期准备 1.Node ...

  8. 921. Minimum Add to Make Parentheses Valid

    Given a string S of '(' and ')' parentheses, we add the minimum number of parentheses ( '(' or ')', ...

  9. STR[#6]

    photo 小明在旅游的路上看到了一条美丽的河,河上有许多船只,有的船只向左航行,有的船只向右航行.小明希望拍下这一美丽的风景,并且把尽可能多的船只都完整地拍到一张照片中. 小明位于河的边上,并且可以 ...

  10. CH5101 LCIS

    CH5101 LCIS 题意: 求两个长度不超过3000的序列的最长公共上升子序列 思路: 朴素解法:用f[i,j]表示a1~ai与b1~bj可以构成的以bj为结尾的LCIS的长度,三重循环求解: ; ...