Selenium WebDriver(別名Selenium 2)は、FirefoxDriverを開いたときに使用する匿名プロファイルをどこで取得しますか?Firefoxのデフォルトである%appdata%/ roaming / Mozilla / firefox / profilesを使用した場合、firefoxプラグインを無効にすると、Selenium WebDriverでも無効にする必要がありますが、なぜそうではないのでしょうか。
4 に答える
@twallからのコメントをサポートして、それに答えます。Selenium2 WebDriverでFirefoxを起動すると、新しい匿名プロファイルが起動します。
ただし、変更したい場合は、新しいFirefoxプロファイルを作成して、なんらかの名前を付けることができます。たとえば、それが何であるかがわかります。SELENIUM
次に、コードでこれを行います。
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);
そうすれば、Firefoxは常にそのプロファイルを開始します。プロファイルでは、必要なすべての設定を行います
各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プロファイル名である必要があることに注意してください。
マシン上にプロファイルを作成するオプションがないテストサーバーでWebドライバーを実行する場合、プログラムでプロファイルを作成できます。
private FirefoxProfile GetFirefoxProfile()
{
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "http://localhost");
return firefoxProfile;
}
プロファイルのフェッチは、フェッチされた名前付きプロファイルの別のコピーを内部的に作成するため、役に立ちません。たとえば、テストカバレッジデータを複数の呼び出しにわたってデータストアに書き込む必要がある場合は、元のプロファイルにアクセスする必要があります。
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");