Last active
September 6, 2016 10:07
-
-
Save evaisse/8279840 to your computer and use it in GitHub Desktop.
HAR exporter using selenium webdriver & firefox custom profile using netexport & firebug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# php : http://stackoverflow.com/a/7549723 | |
# compile standalone server with extension to display current profile path | |
javac -cp selenium-server-standalone-2.39.0.jar HarProxy.java | |
# launch server & display path to profile directory | |
java -cp .:selenium-server-standalone-2.39.0.jar HarProxy | |
# copy profile directory... () | |
cd /your/profile | |
zip -r profile * | |
base64 profile.zip profile.zip.b64 | |
# when you run up your selenium server, ensure to set memory enough | |
# memory to load custom firefox profile with extentions (2gigs here) | |
java -Xmx2g -jar selenium-server-standalone-2.39.0.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.concurrent.TimeUnit; | |
import java.util.concurrent.*; | |
import java.lang.InterruptedException; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.firefox.FirefoxProfile; | |
import org.openqa.selenium.support.ui.Wait; | |
import org.openqa.selenium.support.ui.WebDriverWait; | |
public class HarProxy { | |
public static void main(String[] args) { | |
FirefoxProfile profile = new FirefoxProfile(); | |
File firebug = new File("firebug-1.12.5-fx.xpi"); | |
File netExport = new File("netExport-0.8b22.xpi"); | |
try | |
{ | |
profile.addExtension(firebug); | |
profile.addExtension(netExport); | |
} | |
catch (IOException err) | |
{ | |
System.out.println(err); | |
} | |
// Set default Firefox preferences | |
profile.setPreference("app.update.enabled", false); | |
String domain = "extensions.firebug."; | |
// Set default Firebug preferences | |
// profile.setPreference(domain + "currentVersion", "2.0"); | |
profile.setPreference(domain + "allPagesActivation", "on"); | |
profile.setPreference(domain + "defaultPanelName", "net"); | |
profile.setPreference(domain + "net.enableSites", true); | |
// Set default NetExport preferences | |
profile.setPreference(domain + "netexport.alwaysEnableAutoExport", true); | |
profile.setPreference(domain + "netexport.showPreview", false); | |
profile.setPreference(domain + "netexport.defaultLogDir", "/tmp/har"); | |
profile.setPreference(domain + "netexport.autoExportToFile", true); | |
profile.setPreference(domain + "netexport.sendToConfirmation", false); | |
WebDriver driver = new FirefoxDriver(profile); | |
try | |
{ | |
// Wait till Firebug is loaded | |
Thread.sleep(5000); | |
try { | |
// System.out.println(profile.toJson()); | |
System.out.println("Profile name:" + profile.layoutOnDisk() + "."); | |
String suggestedProfile = System.getProperty("webdriver.firefox.profile"); | |
System.out.println("Profile name:"+ suggestedProfile); | |
} catch (Exception err) { | |
System.out.println("Ouaich gros."); | |
} | |
// Load test page | |
// driver.get("http://www.janodvarko.cz"); | |
// Wait till HAR is exported | |
Thread.sleep(10000); | |
} | |
catch (InterruptedException err) | |
{ | |
System.out.println(err); | |
} | |
// driver.quit(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$webdriver->connect("firefox", "", array( | |
"firefox_profile" => file_get_contents("/your/profile/profile.zip.b64"), | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment