Web UI自动化测试 - 多浏览器支持Java实现

Base class

package com.wbsn.mobile.env;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;

public abstract class Browser{
    
    private String browserName;
    private String browserType;
    private String browserBinary;
    private String browserProfile;
    public WebDriver browserDriver;
    

    public String getBrowserName() {
        return browserName;
    }
    public void setBrowserName(String browserName) {
        this.browserName = browserName;
    }
    public String getBrowserType() {
        return browserType;
    }
    public void setBrowserType(String browserType) {
        this.browserType = browserType;
    }
    public String getBrowserBinary() {
        return browserBinary;
    }
    public void setBrowserBinary(String browserBinary) {
        this.browserBinary = browserBinary;
    }
    public String getBrowserProfile() {
        return browserProfile;
    }
    public void setBrowserProfile(String browserProfile) {
        this.browserProfile = browserProfile;
    }
    
    public abstract WebDriver getDriver();
    
}


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Chrome browser

package com.wbsn.mobile.env;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;


public class Chrome extends Browser {

    public WebDriver getDriver(){
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--disable-extensions");
        return new ChromeDriver(options);
    }

}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Firefox browser

package com.wbsn.mobile.env;

import java.io.File;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.FirefoxBinary;


public class Firefox extends Browser {
    
    
    
    public void init() throws Exception{
        //super.init();
    }
    
    public void close(){
        //super.close();
        
    }
    
    public WebDriver getDriver(){
        
        WebDriver driver;
        FirefoxProfile firefoxProfile;
        FirefoxBinary firefoxBinary;
        
        if(this.getBrowserProfile()!=null && !this.getBrowserProfile().isEmpty()){
            File profile=new File(this.getBrowserProfile());
            firefoxProfile=new FirefoxProfile(profile);

            if(this.getBrowserBinary()!=null && !this.getBrowserBinary().isEmpty()){
                File binary=new File(this.getBrowserBinary());
                firefoxBinary=new FirefoxBinary(binary);
                driver=new FirefoxDriver(firefoxBinary, firefoxProfile);
                return driver;
            }
            
            driver=new FirefoxDriver(firefoxProfile);
            return driver;
        }
        driver=new FirefoxDriver();
        return driver;
        
    }
    
    

}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

IE browser


package com.wbsn.mobile.env;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class IExplorer extends Browser {
    
    public void init() throws Exception{
        //super.init();
    }
    
    public void close(){
        //super.close();
        
    }
    
    public WebDriver getDriver(){
        return new InternetExplorerDriver();
    }

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值