首页 技术 正文
技术 2022年11月15日
0 收藏 476 点赞 2,671 浏览 1894 个字

1.切换浏览器类:其中包含了切换浏览器的方法,以及关闭浏览器,设置等待时间,以及重写的断言方法

package com.rrx.framework;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.Parameters;

public class BorwserEngin {
public String browserName;
public String URL;
public WebDriver driver;

public void initConfigDate() throws IOException {
browserName = PropertiesEngine.getProperties(“browserName”);
URL = PropertiesEngine.getProperties(“URL”);
//System.out.println(browserName);
}
@Parameters(“Browser”)
public WebDriver getDriver() throws IOException {
initConfigDate();
Logger.getLogger().info(“浏览器名称”+browserName);
Logger.getLogger().info(“URL:”+URL);
System.out.println(browserName);
if (browserName.equalsIgnoreCase(“Firefox”)) {
System.setProperty(“webdriver.firefox.bin”, “”);
driver = new FirefoxDriver();
} else if (browserName.equalsIgnoreCase(“Chrome”)) {
System.setProperty(“webdriver.chrome.driver”,
“C:\\Users\\Administrator\\workspace\\SeleniumKuangJia\\driver\\chromedriver.exe”);
driver = new ChromeDriver();
} else if (browserName.equalsIgnoreCase(“IE”)) {
System.setProperty(“webdriver.ie.driver”, “”);
driver = new InternetExplorerDriver();
}
driver.get(URL);
return driver;
}

/**
* //关闭浏览器并且推出
*/
public void tearDown() {
driver.quit();
}
/**
* 隐式时间等待方法
* imlicitlyWait是隐式等待,一般在查找元素的时候使用。例如,我设置一个查找元素最大时间为10秒,使用了
imlicitlyWait后,如果第一次没有找到元素,会在10秒之内不断循环去找元素,知道超过10秒,报超时错误。
*/
public void callTime(int time){

driver.manage().timeouts().implicitlyWait(time, TimeUnit.SECONDS);
}

/**
* 断言方法
*/
public static void assertEqual(Object object,Object object2){
try {
Assert.assertEquals(object, object2,”不相同”);
} catch (Error e) {

Reporter.log(“”+e);//断言错误是把日志打印在测试报告中
Logger.getLogger().info(e);//打印在logger日志中

}

}
}

2.日志的输出采用long4j和Reporter两种方法。Reporter会将日志打印到测试报告中。如果不知道具体方法的可以查看我之前的博客。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,903
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,429
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,245
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,057
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,689
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,726