IntelliJ IDEA java selenium

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.openqa.selenium.firefox;

import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.HashSet;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Platform;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebDriver.Options;
import org.openqa.selenium.WebDriver.Timeouts;
import org.openqa.selenium.firefox.ExtensionConnection;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.NewProfileExtensionConnection;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.internal.Killable;
import org.openqa.selenium.internal.Lock;
import org.openqa.selenium.internal.SocketLock;
import org.openqa.selenium.logging.LocalLogs;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.logging.NeedsLocalLogs;
import org.openqa.selenium.remote.BeanToJsonConverter;
import org.openqa.selenium.remote.Command;
import org.openqa.selenium.remote.CommandExecutor;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.FileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.Response;
import org.openqa.selenium.remote.SessionNotFoundException;
import org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriverOptions;
import org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriverOptions.RemoteTimeouts;

public class FirefoxDriver extends RemoteWebDriver implements Killable {
public static final String BINARY = "firefox_binary";
public static final String PROFILE = "firefox_profile";
public static final boolean DEFAULT_ENABLE_NATIVE_EVENTS;
/** @deprecated */
@Deprecated
public static final boolean ACCEPT_UNTRUSTED_CERTIFICATES = true;
/** @deprecated */
@Deprecated
public static final boolean ASSUME_UNTRUSTED_ISSUER = true;
protected FirefoxBinary binary;

public FirefoxDriver() {
    this((FirefoxBinary)(new FirefoxBinary()), (FirefoxProfile)null);
}

public FirefoxDriver(FirefoxProfile profile) {
    this(new FirefoxBinary(), profile);
}

public FirefoxDriver(Capabilities desiredCapabilities) {
    this(getBinary(desiredCapabilities), extractProfile(desiredCapabilities, (Capabilities)null), desiredCapabilities);
}

public FirefoxDriver(Capabilities desiredCapabilities, Capabilities requiredCapabilities) {
    this(getBinary(desiredCapabilities), extractProfile(desiredCapabilities, requiredCapabilities), desiredCapabilities, requiredCapabilities);
}

private static FirefoxProfile extractProfile(Capabilities desiredCapabilities, Capabilities requiredCapabilities) {
    FirefoxProfile profile = null;
    Object raw = null;
    if(desiredCapabilities != null && desiredCapabilities.getCapability("firefox_profile") != null) {
        raw = desiredCapabilities.getCapability("firefox_profile");
    }

    if(requiredCapabilities != null && requiredCapabilities.getCapability("firefox_profile") != null) {
        raw = requiredCapabilities.getCapability("firefox_profile");
    }

    if(raw != null) {
        if(raw instanceof FirefoxProfile) {
            profile = (FirefoxProfile)raw;
        } else if(raw instanceof String) {
            try {
                profile = FirefoxProfile.fromJson((String)raw);
            } catch (IOException var5) {
                throw new WebDriverException(var5);
            }
        }
    }

    profile = getProfile(profile);
    populateProfile(profile, desiredCapabilities);
    populateProfile(profile, requiredCapabilities);
    return profile;
}

static void populateProfile(FirefoxProfile profile, Capabilities capabilities) {
    if(capabilities != null) {
        Boolean nativeEventsEnabled;
        if(capabilities.getCapability("webStorageEnabled") != null) {
            nativeEventsEnabled = (Boolean)capabilities.getCapability("webStorageEnabled");
            profile.setPreference("dom.storage.enabled", nativeEventsEnabled.booleanValue());
        }

        if(capabilities.getCapability("acceptSslCerts") != null) {
            nativeEventsEnabled = (Boolean)capabilities.getCapability("acceptSslCerts");
            profile.setAcceptUntrustedCertificates(nativeEventsEnabled.booleanValue());
        }

        if(capabilities.getCapability("loggingPrefs") != null) {
            LoggingPreferences nativeEventsEnabled1 = (LoggingPreferences)capabilities.getCapability("loggingPrefs");
            Iterator var3 = nativeEventsEnabled1.getEnabledLogTypes().iterator();

            while(var3.hasNext()) {
                String logtype = (String)var3.next();
                profile.setPreference("webdriver.log." + logtype, nativeEventsEnabled1.getLevel(logtype).intValue());
            }
        }

        if(capabilities.getCapability("nativeEvents") != null) {
            nativeEventsEnabled = (Boolean)capabilities.getCapability("nativeEvents");
            profile.setEnableNativeEvents(nativeEventsEnabled.booleanValue());
        }

    }
}

private static FirefoxBinary getBinary(Capabilities capabilities) {
    if(capabilities != null && capabilities.getCapability("firefox_binary") != null) {
        Object raw = capabilities.getCapability("firefox_binary");
        if(raw instanceof FirefoxBinary) {
            return (FirefoxBinary)raw;
        } else {
            File file = new File((String)raw);
            return new FirefoxBinary(file);
        }
    } else {
        return new FirefoxBinary();
    }
}

public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile) {
    this(binary, profile, DesiredCapabilities.firefox());
}

public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile, Capabilities capabilities) {
    this(binary, profile, capabilities, (Capabilities)null);
}

public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile, Capabilities desiredCapabilities, Capabilities requiredCapabilities) {
    super(new FirefoxDriver.LazyCommandExecutor(binary, profile, null), dropCapabilities(desiredCapabilities, new String[]{"firefox_binary", "firefox_profile"}), dropCapabilities(requiredCapabilities, new String[]{"firefox_binary", "firefox_profile"}));
    this.binary = binary;
}

public void setFileDetector(FileDetector detector) {
    throw new WebDriverException("Setting the file detector only works on remote webdriver instances obtained via RemoteWebDriver");
}

public void kill() {
    this.binary.quit();
}

public Options manage() {
    return new RemoteWebDriverOptions(this) {
        public Timeouts timeouts() {
            return new RemoteTimeouts(this) {
                public Timeouts implicitlyWait(long time, TimeUnit unit) {
                    FirefoxDriver.this.execute("setTimeout", ImmutableMap.of("type", "implicit", "ms", Long.valueOf(TimeUnit.MILLISECONDS.convert(time, unit))));
                    return this;
                }

                public Timeouts setScriptTimeout(long time, TimeUnit unit) {
                    FirefoxDriver.this.execute("setTimeout", ImmutableMap.of("type", "script", "ms", Long.valueOf(TimeUnit.MILLISECONDS.convert(time, unit))));
                    return this;
                }
            };
        }
    };
}

protected void startClient() {
    FirefoxDriver.LazyCommandExecutor exe = (FirefoxDriver.LazyCommandExecutor)this.getCommandExecutor();
    FirefoxProfile profileToUse = getProfile(exe.profile);
    ExtensionConnection connection = this.connectTo(exe.binary, profileToUse, "localhost");
    exe.setConnection(connection);

    try {
        connection.start();
    } catch (IOException var5) {
        throw new WebDriverException("An error occurred while connecting to Firefox", var5);
    }
}

private static FirefoxProfile getProfile(FirefoxProfile profile) {
    FirefoxProfile profileToUse = profile;
    String suggestedProfile = System.getProperty("webdriver.firefox.profile");
    if(profile == null && suggestedProfile != null) {
        profileToUse = (new ProfilesIni()).getProfile(suggestedProfile);
        if(profileToUse == null) {
            throw new WebDriverException(String.format("Firefox profile \'%s\' named in system property \'%s\' not found", new Object[]{suggestedProfile, "webdriver.firefox.profile"}));
        }
    } else if(profile == null) {
        profileToUse = new FirefoxProfile();
    }

    return profileToUse;
}

protected ExtensionConnection connectTo(FirefoxBinary binary, FirefoxProfile profile, String host) {
    Lock lock = this.obtainLock(profile);

    try {
        FirefoxBinary e = binary == null?new FirefoxBinary():binary;
        return new NewProfileExtensionConnection(lock, e, profile, host);
    } catch (Exception var6) {
        throw new WebDriverException(var6);
    }
}

protected Lock obtainLock(FirefoxProfile profile) {
    return new SocketLock();
}

protected void stopClient() {
    ((FirefoxDriver.LazyCommandExecutor)this.getCommandExecutor()).quit();
}

private static Capabilities dropCapabilities(Capabilities capabilities, String... keysToRemove) {
    if(capabilities == null) {
        return new DesiredCapabilities();
    } else {
        final HashSet toRemove = Sets.newHashSet(keysToRemove);
        DesiredCapabilities caps = new DesiredCapabilities(Maps.filterKeys(capabilities.asMap(), new Predicate() {
            public boolean apply(String key) {
                return !toRemove.contains(key);
            }
        }));
        Proxy proxy = Proxy.extractFrom(capabilities);
        if(proxy != null) {
            caps.setCapability("proxy", (new BeanToJsonConverter()).convert(proxy));
        }

        return caps;
    }
}

public <X> X getScreenshotAs(OutputType<X> target) {
    String base64 = this.execute("screenshot").getValue().toString();
    return target.convertFromBase64Png(base64);
}

static {
    DEFAULT_ENABLE_NATIVE_EVENTS = Platform.getCurrent().is(Platform.WINDOWS);
}

public static class LazyCommandExecutor implements CommandExecutor, NeedsLocalLogs {
    private ExtensionConnection connection;
    private final FirefoxBinary binary;
    private final FirefoxProfile profile;
    private LocalLogs logs;

    private LazyCommandExecutor(FirefoxBinary binary, FirefoxProfile profile) {
        this.logs = LocalLogs.getNullLogger();
        this.binary = binary;
        this.profile = profile;
    }

    public void setConnection(ExtensionConnection connection) {
        this.connection = connection;
        connection.setLocalLogs(this.logs);
    }

    public void quit() {
        if(this.connection != null) {
            this.connection.quit();
            this.connection = null;
        }

        if(this.profile != null) {
            this.profile.cleanTemporaryModel();
        }

    }

    public Response execute(Command command) throws IOException {
        if(this.connection == null) {
            if(command.getName().equals("quit")) {
                return new Response();
            } else {
                throw new SessionNotFoundException("The FirefoxDriver cannot be used after quit() was called.");
            }
        } else {
            return this.connection.execute(command);
        }
    }

    public void setLocalLogs(LocalLogs logs) {
        this.logs = logs;
        if(this.connection != null) {
            this.connection.setLocalLogs(logs);
        }

    }

    public URI getAddressOfRemoteServer() {
        return this.connection.getAddressOfRemoteServer();
    }
}

public static final class SystemProperty {
    public static final String BROWSER_BINARY = "webdriver.firefox.bin";
    public static final String BROWSER_LOGFILE = "webdriver.firefox.logfile";
    public static final String BROWSER_LIBRARY_PATH = "webdriver.firefox.library.path";
    public static final String BROWSER_PROFILE = "webdriver.firefox.profile";
    public static final String DRIVER_XPI_PROPERTY = "webdriver.firefox.driver";
    public static final String DRIVER_USE_MARIONETTE = "webdriver.firefox.marionette";

    public SystemProperty() {
    }
}

}

转载于:https://www.cnblogs.com/ITniu/p/7475075.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在IntelliJ IDEA中搭建Java Selenium环境,您需要按照以下步骤进行操作: 1. 下载并安装Java Development Kit(JDK):访问Oracle官方网站,下载适用于您的操作系统的最新版本的JDK,并按照安装向导进行安装。 2. 下载并安装IntelliJ IDEA:访问JetBrains官方网站,下载适用于您的操作系统的最新版本的IntelliJ IDEA,并按照安装向导进行安装。 3. 创建新项目:打开IntelliJ IDEA,选择“Create New Project”(创建新项目)选项。在弹出的对话框中,选择“Java”作为项目类型,并设置项目名称和存储位置。 4. 配置项目依赖:在项目创建后,打开项目结构设置。选择“File”(文件)菜单中的“Project Structure”(项目结构)选项。在弹出的对话框中,选择“Modules”(模块)选项卡,并点击“Dependencies”(依赖)选项卡。点击“+”按钮,选择“JARs or directories”(JAR文件或目录),然后导航到您的Selenium JAR文件所在的位置,并添加到项目依赖中。 5. 编写测试代码:在IntelliJ IDEA中创建一个新的Java类,并编写您的Selenium测试代码。确保导入所需的Selenium库和其他必要的类。 6. 配置浏览器驱动程序:根据您要使用的浏览器类型,下载相应的浏览器驱动程序,并将其添加到系统的PATH环境变量中。 7. 运行测试:在IntelliJ IDEA中,右键单击您编写的测试类,并选择“Run”(运行)选项。您的Selenium测试将在所选浏览器中运行。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值