Как получить данные о сбое Firefox с помощью geckodriver (на Java) - PullRequest
0 голосов
/ 13 мая 2019

Меня попросили предоставить анализ данных о сбоях в Firefox, поэтому я пытаюсь выполнить действия, описанные в этих Документах Firefox .

Мне нужно добавить этот код Python до того, как ятестовый код на 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);

, но я совершенно не представляю, как интегрировать этот код Python в мою последнюю строку Java:

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

есть идеи?

1 Ответ

1 голос
/ 16 мая 2019

Для тех, кто испытывает затруднения, чтобы сделать это в 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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...