如何使用geckodriver检索Firefox的崩溃数据(Java) [英] How to retrieve the crash data of Firefox using geckodriver (in Java)

查看:110
本文介绍了如何使用geckodriver检索Firefox的崩溃数据(Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求提供对Firefox崩溃数据的分析,所以我试图遵循此

I was asked to provide analyzing crash data of Firefox, so I'm trying to follow the steps in this Firefox docs.

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

I have to add this Python code before my own test code which is in Java :

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);

但是我绝对不知道如何在我的最后一个Java行中集成此python代码:

but I have absolutely no idea how to integrate this python code in my last Java line :

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

有什么主意吗?

推荐答案

对于任何使用Java编写代码的人来说,这段代码对我来说都是有效的:

For anybody having trouble to do it in Java, this code worked for me :

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

这篇关于如何使用geckodriver检索Firefox的崩溃数据(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆