业务场景:在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();
}
}

最新文章

  1. 对iOS10新增Api的详细探究
  2. 20145218&amp;20145240 《信息安全系统设计基础》实验二 固件设计
  3. SpringMVC对异常进行全局处理,并区分对待ajax和普通请求
  4. 使用Html5+C#+微信 开发移动端游戏详细教程: (四)游戏中层的概念与设计
  5. zend framework2 入门实例代码album模型
  6. ServiceLocator是反模式
  7. GTD_百度百科
  8. QueryInterface
  9. C#使用sharppcap实现网络抓包
  10. Oauth认证简介
  11. JDK环境变量配置贺Tomcat环境搭建
  12. Ubuntu14.04LST 安装Oracle SQL Developer 4.0.2
  13. Django中的许可(Permissions)和用户组(Group)
  14. JavaScript函数之作用域 / 作用链域 / 预解析
  15. day2--计算机基础
  16. hdu 5011(博弈)
  17. 常用数据库:MongoDB
  18. 【C#】使用user32.dll的MessageBox弹窗消息
  19. [uboot]uboot中am437对应的GPIO配置
  20. 在C#中使用依赖注入

热门文章

  1. 再次学习linux文件特殊权限:SUID、SGID、Sticy Bit
  2. GitHub操作总结
  3. 利用 StartLoadingStatus 和 FinishLoadingStatus 读取数据特别是大数据时增加渐隐渐显等待特效 - Ehlib学习(三)
  4. C# WPF Application 下的文件操作
  5. 腾讯云/阿里云/微软云安装ISO镜像系统方法
  6. CF455C Civilization | luogu HXY造公园
  7. fatal: Authentication failed for又不弹出用户名和密码 解决办法
  8. 模糊查询中Like的使用
  9. chrome cpu占用100%
  10. To 高一