读取配置文件-重构封装
来源:互联网 发布:mac 4k 字体太小 编辑:程序博客网 时间:2024/06/04 23:27
项目结构图
Login.java
package com.gubai.selenium;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.interactions.Actions;public class Login {public WebDriver driver;public void InitDriver() {String url = "http://www.imooc.com/";System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");driver = new ChromeDriver();driver.get(url);driver.manage().window().maximize();this.elemnet(By.id("js-signin-btn")).click();}public void loginscript(String username,String userpass) throws Exception {this.InitDriver();Thread.sleep(3000);WebElement user = this.elemnet(this.byStr("username"));user.isDisplayed();WebElement password = this.elemnet(this.byStr("userpass"));password.isDisplayed();WebElement loginButton = this.elemnet(this.byStr("loginbutton"));loginButton.isDisplayed();user.sendKeys(username);password.sendKeys(userpass);loginButton.click();Thread.sleep(3000);WebElement header = this.elemnet(this.byStr("header"));header.isDisplayed();Actions actions = new Actions(driver);actions.moveToElement(header).perform();;String userInfo = this.elemnet(this.byStr("nameInfo")).getText();System.out.println(userInfo);if(userInfo.equals("mushishi_xu1")) {System.out.print("登陆成功");}else {System.out.print("登录失败");}} /**封装By by **/ public By byStr(String username){ProUtil properties = new ProUtil("element.properties");String locator = properties.getPro(username);String locatorType =locator.split(">")[0];String locatorValue = locator.split(">")[1]; if(locatorType.equals("id")) { return By.id(locatorValue); }else if(locatorType.equals("name")){ return By.name(locatorValue); }else if(locatorType.equals("className")){ return By.className(locatorValue); }else if(locatorType.equals("xpath")){ return By.className(locatorValue); }else{ return By.xpath(locatorValue); } } /** * 封装Element * **/ public WebElement elemnet(By by) { WebElement ele = driver.findElement(by); return ele; }public static void main(String[] args) throws Exception{ Login login = new Login(); login.loginscript("账号","密码");}}element.properties
username=name>emailuserpass=name>passwordloginbutton=className>btn-redheader=id>header-avatornameInfo=className>nameProUtil.java(此部分代码未改动)
package com.gubai.selenium;import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.util.Properties;public class ProUtil {private Properties prop;private String filepaht;/** * 构造方法 * **/public ProUtil(String filepath) {this.filepaht = filepath;this.prop = readProperties();}/** * 读取配置文件 * **/private Properties readProperties() {Properties properties = new Properties();try {InputStream inputstream = new FileInputStream(filepaht);InputStream in = new BufferedInputStream(inputstream);properties.load(in);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return properties;}public String getPro(String key) {if(prop.containsKey(key)) {String username = prop.getProperty(key);return username;}else {System.out.println("你获取key值不对");return "";}}}
阅读全文
0 0
- 读取配置文件-重构封装
- 配置文件读取的封装
- 读取配置文件的封装Dao
- MFC 读取配置文件(封装)
- Python 封装读取CSV配置文件
- C++读取配置文件的封装类config
- 读取配置文件csv的接口封装类
- 读取配置文件封装类(GetPrivateProfileString)
- 重构--封装结构
- 【机房重构】配置文件
- JAVA读取classess下的.properties配置文件封装类
- JDBC中关于封装和读取配置文件properties的问题
- 关于重构---封装字段
- 重构与对象封装
- 机房重构-封装模块
- 代码重构-封装字段
- java读取配置文件封装类,支持同时读取多个文件
- 读取配置文件
- HDU-4565 So Easy! 矩阵快速幂 & 共轭构造
- CF428 (2) A. Arya and Bran
- Windows调试工具入门-3-WinDbg内核调试配置
- Windows 调试工具入门-2-基本调试操作
- hdu 6119 二分 OR 尺取
- 读取配置文件-重构封装
- MJPG-streamer源码分析-输出部分
- mysql删除重复记录语句的方法 作者: 字体:[增加 减小] 类型:转载 时间:2010-06-21 我要评论 查询及删除重复记录的SQL语句,虽然有点乱,但内容还是不错的。 . .
- 智能指针简单实现
- hdu 6115 Factory LCA
- django学习三--发邮件
- 程序控制过程机器级表示(访问条件码)-《深入理解计算机系统》笔记
- linux 压缩解压命令
- 计算机装系统