业务场景:在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. ssm集合的配置

    web.xml <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quo ...

  2. Java设置jre通过java new Date()得到的时间的时区

    1.前提 由于公司有印尼的项目,该项目仅对印尼当地开放使用(公司在国内,用的是阿里云的ECS,但是阿里云在印尼没有服务器,所以就买了新加坡的服务器),印尼当地人用的是东七区的时间,所以比国内东八区的时 ...

  3. Linq集合操作之Intersect,Except,Union源码分析

    Linq集合操作之Intersect,Except,Union源码分析 linq的集合运算 常见的集合运算有哪些? 这三个扩展方法在我们实际使用中用的还是非常多的,而且这里还涉及到了“复杂度” 无算法 ...

  4. Intel Galileo development documentation

    Intel Galileo development Documentation Author:Liutianchen 1552227, Department of Computer Science,E ...

  5. Python【filter、map、reduce】

    filter和map和reduce map(function,iterable...) -> list 映射,对列表中的每个值操作 返回操作后的数值组成列表 # 给列表值+1 l = [1,2, ...

  6. IE6 IE7 IE8 FF兼容符号

    2.区别IE8.IE9 一般来说,我们写的结构比较好的时候,IE8/9下是没区别的.所以可能很少人关注只有IE8或只有IE9才识别的css hack. 因为IE8及以下版本是不支持CSS3的,但是我们 ...

  7. 趣图:当我捕获Bug的时候

      趣图:当我以为已捕获了所有可能的异常...的时候 趣图:程序员调 Bug 的感觉,就是这样的

  8. UITableViewCell笔记

    默认的四种cell的类型 原网站 还有这个带图的 据我自己试验,只有value2不自带imageview 不同的accessoryType 可以看到,一个tabelviewcell的contentvi ...

  9. Python爬取网上车市[http://www.cheshi.com/]的数据

    #coding:utf8 #爬取网上车市[http://www.cheshi.com/]的数据 import requests, json, time, re, os, sys, time,urlli ...

  10. 将SQLAlchemy对象转化为dict

    需求一,将数据对象转为dict,但是不包括relation, import BaseClass #所有模型的基础类 def getDictFromObj_nr(obj): return_dict={} ...