gpt4 book ai didi

java - 如何使用 geckodriver 检索 Firefox 的崩溃数据(Java 中)

转载 作者:行者123 更新时间:2023-12-02 09:54:13 25 4
gpt4 key购买 nike

我被要求提供 Firefox 崩溃数据的分析,所以我尝试按照此 Firefox docs 中的步骤操作。 .

我必须在我自己的 Java 测试代码之前添加此 Python 代码:

import tempfile

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

# Custom profile folder to keep the minidump files
profile = tempfile.mkdtemp(".selenium")
print("*** Using profile: {}".format(profile))

# Use the above folder as custom profile
opts = Options()
opts.add_argument("-profile")
opts.add_argument(profile)
opts.binary = "/Applications/Firefox.app/Contents/MacOS/firefox"

driver = webdriver.Firefox(options=opts,
# hard-code the Marionette port so geckodriver can connect
service_args=["--marionette-port", "2828"])

# Your test code which crashes Firefox

所以我写了这个:

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

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


final Path basedir = FileSystems.getDefault().getPath("/tmp");
final String tmp_dir_prefix = ".selenium";
final Path tmp_dir = Files.createTempDirectory(basedir, tmp_dir_prefix);

File firefoxProfileFolder = new File(tmp_dir.toString());
FirefoxProfile customProfile = new FirefoxProfile(firefoxProfileFolder);

File pathToBinary = new File("/usr/bin/firefox-trunk");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathToBinary);

FirefoxOptions options = new FirefoxOptions();
options.setBinary(firefoxBinary);
options.setProfile(customProfile);

WebDriver driver = new FirefoxDriver(options);

但我完全不知道如何将此 python 代码集成到我的最后一个 Java 行中:

driver = webdriver.Firefox(options=opts,
# hard-code the Marionette port so geckodriver can connect
service_args=["--marionette-port", "2828"])

有什么想法吗?

最佳答案

对于任何在 Java 中遇到困难的人来说,这段代码对我有用:

File pathToGeckoDriver = new File("/path/to/geckodriver/executable");
File pathToFirefoxBinary = new File("/path/to/firefox/executable");

# Custom profile folder to keep the minidump files
Path basedir = FileSystems.getDefault().getPath("/tmp");
String tmp_dir_prefix = ".selenium";
Path tmp_dir = Files.createTempDirectory(basedir, tmp_dir_prefix);

# Use the above folder as custom profile
FirefoxBinary ffBinary = new FirefoxBinary(pathToFirefoxBinary);
ffBinary.addCommandLineOptions("-profile");
ffBinary.addCommandLineOptions(tmp_dir.toString()); # Use the above folder as custom profile

WebDriver driver = new FirefoxDriver(
new GeckoDriverService.Builder()
.usingFirefoxBinary(ffBinary)
.usingPort(2828) # hard-code the Marionette port so geckodriver can connect
.usingDriverExecutable(pathToGeckoDriver))
.build()
);

# Your test code which crashes Firefox

关于java - 如何使用 geckodriver 检索 Firefox 的崩溃数据(Java 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56112904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com