添加火狐浏览器,并修改信息输出方法的位置
This commit is contained in:
parent
3bb5040b82
commit
d4094520e1
Binary file not shown.
|
@ -10,6 +10,7 @@ import java.util.Set;
|
|||
import org.openqa.selenium.JavascriptExecutor;
|
||||
import org.openqa.selenium.NoSuchWindowException;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
@ -188,6 +189,11 @@ public abstract class AbstractBrower {
|
|||
// 打开浏览器
|
||||
openBrower();
|
||||
|
||||
// 添加操作信息
|
||||
informationJson.put("浏览器名称", ((RemoteWebDriver) driver).getCapabilities().getBrowserName());
|
||||
informationJson.put("浏览器版本", ((RemoteWebDriver) driver).getCapabilities().getVersion());
|
||||
informationJson.put("操作系统版本", System.getProperties().getProperty("os.name"));
|
||||
|
||||
// 若存在需要打开的页面,则打开第一个页面
|
||||
if (nowPage != null) {
|
||||
openUrl(nowPage, false);
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package pres.auxiliary.work.selenium.brower;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||
|
||||
public class FirefoxBrower extends AbstractBrower {
|
||||
/**
|
||||
* 用于存储与火狐浏览器相关的配置
|
||||
*/
|
||||
FirefoxOptions firefoxOption = new FirefoxOptions();
|
||||
|
||||
/**
|
||||
* 指定驱动文件路径并添加一个待测站点
|
||||
*
|
||||
* @param driverFile 驱动文件对象
|
||||
* @param page {@link Page}类对象
|
||||
*/
|
||||
public FirefoxBrower(File driverFile, Page page) {
|
||||
super(driverFile, page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定驱动文件路径并添加一个待测站点
|
||||
*
|
||||
* @param driberFile 驱动文件对象
|
||||
* @param url 待测站点
|
||||
* @param pageName 待测站点名称,用于切换页面
|
||||
*/
|
||||
public FirefoxBrower(File driverFile, String url, String pageName) {
|
||||
super(driverFile, url, pageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定驱动文件所在路径
|
||||
*
|
||||
* @param driberFile 驱动文件对象
|
||||
*/
|
||||
public FirefoxBrower(File driverFile) {
|
||||
super(driverFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于设置火狐浏览器的启动路径,在启动浏览器时,将打开该路径下的浏览器。
|
||||
* 通过该方法可用于打开为谷歌浏览器内核的浏览器
|
||||
* </p>
|
||||
* <p>
|
||||
* <b>注意:</b>若浏览器启动后再设置浏览器启动路径时,会重新打开一个新的浏览器,且
|
||||
* {@link WebDriver}对象将重新构造,指向新打开的浏览器
|
||||
* </p>
|
||||
* @param binaryPath
|
||||
*/
|
||||
public void setBinary(File binaryPath) {
|
||||
firefoxOption.setBinary(binaryPath.getAbsolutePath());
|
||||
driver = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
void openBrower() {
|
||||
driver = new FirefoxDriver(firefoxOption);
|
||||
}
|
||||
|
||||
@Override
|
||||
String getBrowerDriverSetName() {
|
||||
return "webdriver.gecko.driver";
|
||||
}
|
||||
|
||||
}
|
|
@ -77,10 +77,6 @@ public class IeBrower extends AbstractBrower {
|
|||
void openBrower() {
|
||||
//构造浏览器
|
||||
driver = new InternetExplorerDriver(ieOption);
|
||||
//添加浏览器信息
|
||||
informationJson.put("浏览器名称", ((InternetExplorerDriver) driver).getCapabilities().getBrowserName());
|
||||
informationJson.put("浏览器版本", ((InternetExplorerDriver) driver).getCapabilities().getVersion());
|
||||
informationJson.put("操作系统版本", System.getProperties().getProperty("os.name"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package pres.auxiliary.work.selenium.brower;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class FirefoxBrowerTest {
|
||||
/**
|
||||
* 指向driver文件
|
||||
*/
|
||||
private final File driverFile = new File("Resource/BrowersDriver/Firefox/82.0.2/geckodriver.exe");
|
||||
|
||||
/**
|
||||
* 指向浏览器对象
|
||||
*/
|
||||
FirefoxBrower fb;
|
||||
|
||||
/**
|
||||
* 关闭浏览器
|
||||
*/
|
||||
@AfterClass(alwaysRun = true)
|
||||
public void quit() {
|
||||
System.out.println(fb.getAllInformation());
|
||||
System.out.println("输入任意字符继续:");
|
||||
Scanner sc = new Scanner(System.in);
|
||||
sc.next();
|
||||
fb.closeBrower();
|
||||
sc.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试打开浏览器后加载预设界面
|
||||
*/
|
||||
@Test
|
||||
public void firefoxBrowerTest_FilePage() {
|
||||
fb = new FirefoxBrower(driverFile, new Page("https://www.baidu.com", "百度"));
|
||||
fb.getDriver();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue