How do I run Firebug within Selenium WebDriver (Selenium 2)?

流过昼夜 提交于 2019-12-29 02:56:17

问题


What's the best way to activate Firebug in Firefox when running Selenium 2?

Edit: Ok, I realize "best" is open to interpretation, but the profile-based solution really used to be a pain with selenium 1.0. So any alternative is considered better until proved worse ;)


回答1:


You can create your profile in code and dynamically add required add-ons. Let's assume that you saved Firebug XPI into the C:\FF_Profile folder as firebug.xpi (go to Firebug download page, right-click on the "Add To Firefox" and save as C:\FF_Profile\firebug.xpi).

In code:

   final String firebugPath = "C:\\FF_Profile\\firebug.xpi";
   FirefoxProfile profile = new FirefoxProfile();       
   profile.addExtension(new File(firebugPath));
   // Add more if needed
   WebDriver driver = new FirefoxDriver(profile);

This is described in WebDriver FAQ




回答2:


Do you mean having firebug installed in the browser instance that webdriver launches? If so, you can pass an extension when you instantiate the driver, but the eaisest way is to create a firefox profile with firebug installed and then use the following code before you instantiate the driver:

System.setProperty("webdriver.firefox.profile", "NAME_OF_FIREFOX_PROFILE_WITH_FIREBUG");




回答3:


Just reference your profile by name. Example in Ruby:

@driver = Selenium::WebDriver.for :firefox, :profile => "default"

Then, load Firefox normally, and add your desired extensions. They will now show up in your Selenium test runs.




回答4:


Apparently the way the firefox-profile options are consumed has changed in Selenium WebDriver.

The old commandline (Selenium RC):

java -jar selenium-2.28.0.jar -firefoxProfileTemplate ~/.mozilla/firefox/3knu5vz0.selenium

Updated for WebDriver: (note that it wants the profile name rather than the directory)

java -jar selenium-2.28.0.jar -Dwebdriver.firefox.profile=selenium



回答5:


modify your firefox location to something like C:\Users\user-name\AppData\Roaming\Mozilla\Firefox\Profiles\sgmqi7hy.default launch your firefox from selenium / webdriver make all your required settings close and restart firefox browser from selenium / webdriver that's it, it solves your problem !!




回答6:


I found a profiles.ini in ~/.mozialla/firefox/. In there was a profile named default, which I specified a like the following and then firefox was opened in test just like I opened it regularly (with all plugins etc).

java -jar selenium.jar -Dwebdriver.firefox.profile=default



回答7:


If none of the above option works. Then try this.

  • 1) Open terminal and type below command (close all existing firefox sessions first)

firefox -p

  • 2) This will open an option to create a new Firefox profile.
  • 3) Create a profile lets say "SELENIUM".
  • 4) Once the firefox is open straight away install firebug or any other plugins extension that you want. once done close the window.
  • 5) Now load this new profile via selenium , use below java statements.

    ProfilesIni profile = new ProfilesIni();

    FirefoxProfile ffprofile = profile.getProfile("SELENIUM");

    WebDriver driver = new FirefoxDriver(ffprofile);

  • 6) Done. Enjoy.




回答8:


I have observed that the firebug is adding to browser and it is disabled by default and not enabled ,when i add firebug to firefox at runtime by using webdriver. So to make it enable we may need to add the below line to profile.

profile.setEnableNativeEvents(true);



回答9:


Assuming that, Firebug is installed. Your objective is to run Firebug. Firebug can be run/execute by pressing F12 key. So Firebug can be run by following command of Selenium WebDriver with Java:

Actions action = new Actions(driver);
action.sendKeys(Keys.F12).build().perform();


来源:https://stackoverflow.com/questions/3421793/how-do-i-run-firebug-within-selenium-webdriver-selenium-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!