17

Selenium WebDriver(別名Selenium 2)は、FirefoxDriverを開いたときに使用する匿名プロファイルをどこで取得しますか?Firefoxのデフォルトである%appdata%/ roaming / Mozilla / firefox / profilesを使用した場合、firefoxプラグインを無効にすると、Selenium WebDriverでも無効にする必要がありますが、なぜそうではないのでしょうか。

4

4 に答える 4

21

@twallからのコメントをサポートして、それに答えます。Selenium2 WebDriverでFirefoxを起動すると、新しい匿名プロファイルが起動します。

ただし、変更したい場合は、新しいFirefoxプロファイルを作成して、なんらかの名前を付けることができます。たとえば、それが何であるかがわかります。SELENIUM

次に、コードでこれを行います。

 ProfilesIni profile = new ProfilesIni();
 FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
 WebDriver driver = new FirefoxDriver(ffprofile);

そうすれば、Firefoxは常にそのプロファイルを開始します。プロファイルでは、必要なすべての設定を行います

于 2012-08-20T07:33:09.317 に答える
5

各Seleniumグリッド2ノードに特定のFirefoxプロファイルを割り当てることができます。

java -jar selenium-server-standalone-2.37.0.jar -Dwebdriver.firefox.profile = my-profile -role node -hub http://example-server.org:4444/grid/register

webdriver.firefox.profileの値は、場所やフォルダー名ではなく、Firefoxプロファイル名である必要があることに注意してください。

于 2013-11-21T13:31:35.763 に答える
2

マシン上にプロファイルを作成するオプションがないテストサーバーでWebドライバーを実行する場合、プログラムでプロファイルを作成できます。

private FirefoxProfile GetFirefoxProfile()
{
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "http://localhost");
    return firefoxProfile;
}
于 2014-07-30T07:51:45.180 に答える
1

プロファイルのフェッチは、フェッチされた名前付きプロファイルの別のコピーを内部的に作成するため、役に立ちません。たとえば、テストカバレッジデータを複数の呼び出しにわたってデータストアに書き込む必要がある場合は、元のプロファイルにアクセスする必要があります。

SeleniumのProfilesIniクラスをオーバーライドすることで考えられる解決策は次のとおりです。

まず、firefox -pを使用してカスタムプロファイルを作成します。たとえば、「CustomSeleniumProfile」と言います。

ProfilesIni profileini = new ProfilesIni() {
    @Override
    public FirefoxProfile getProfile(String profileName) {
            File appData = locateAppDataDirectory(Platform.getCurrent());
            Map<String, File> profiles = readProfiles(appData);
            File profileDir = profiles.get(profileName);
            if (profileDir == null)
              return null;
            return new FirefoxProfile(profileDir);
     }
};
FirefoxProfile profile = profileini.getProfile("CustomSeleniumProfile");
//profile.setEnableNativeEvents(false);

driver = new FirefoxDriver(profile);
//ffDriver.manage().deleteAllCookies();
driver.get("http://www.google.com");
于 2015-03-04T03:09:27.527 に答える