PHPUnit + Selenium:如何设置Firefox about:config选项? [英] PHPUnit + Selenium: How to set Firefox about:config options?

查看:174
本文介绍了PHPUnit + Selenium:如何设置Firefox about:config选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用PHPUnit和Firefox远程运行Selenium测试时,onChange事件不会像当用户正在操作浏览器



解决方案似乎是设置 focusmanager.testmode 在Firefox的首选项(即 about:config )中选择 true ,如硒缺陷报告

然而所有的例子都直接使用了Selenium,而我正在使用PHPUnit,它有自己的API来隐藏Selenium的内部。我无法弄清楚如何使用PHPUnit设置这个Firefox选项,所以我希望别人能告诉我如何做到这一点!



(不,我无法进入 about:config 并手动设置它,因为每次测试运行时测试都会创建一个新的干净的浏览器配置文件,因此任何手动配置更改都会丢失。 )

解决方案

感谢Selenium开发者,我有一个解决方案!

Short version



把它放到你的测试中,以便在 setUp()函数中调用它: >

  // Firefox的小配置文件在about:config中设置focusmanager.testmode = true $ b $ define('FIREFOX_PROFILE',
UEsDBAoAAAAAADqAxkSBK46tKgAAACoAAAAIABwAcHJlZnMuanNVVAkAA1BZkVM6WZFTdXgLAAEE
6AMAAARkAAAAdXNlcl9wcmVmKCJmb2N1c21hbmFnZXIudGVzdG1vZGUiLCB0cnVlKTsKUEsBAh4D
CgAAAAAAOoDGRIErjq0qAAAAKgAAAAgAGAAAAAAAAQAAAKSBAAAAAHByZWZzLmpzVVQFAANQWZFT
dXgLAAEE6AMAAARkAAAAU EsFBgAAAAABAAEATgAAAGwAAAAAAA ==);

protected function setUp()
{
$ this-> setDesiredCapabilities(Array('firefox_profile'=> FIREFOX_PROFILE));

设置 focusmanager.testmode true 。



长版



您需要根据您要设置的偏好创建您自己的迷你Firefox配置文件,并在测试开始时将其传递给您。下面是如何做到这一点:


  1. 创建一个新文件夹,并将您想要的文件放在Firefox配置文件中。这可以是任何东西(书签,扩展名,你自己的配置文件的副本等),但我们需要的是一个名为 prefs.js 的文件,它存储我们的 about:config settings。

  2. 创建 prefs.js 在这个文件夹中包含以下内容:

    $ $ $ $ $ $ $ user_pref(focusmanager.testmode,true);


  3. 将文件夹( prefs.js

    如果您正在使用Linux,你可以这样做:

      mkdir firefox-profile 
    cd firefox-profile
    echo'user_pref(focusmanager.testmode,true);'>> prefs.js
    zip -r ../firefox-profile.zip *
    base64< ../firefox-profile.zip

    然后取base64值并设置为firefox_profile能力按照上面的短版本。


    When running Selenium tests remotely with PHPUnit and Firefox, onChange events are not fired as they are when a user is operating the browser.

    The solution to this seems to be to set the focusmanager.testmode option to true in Firefox's preferences (i.e. about:config), as suggested in a Selenium bug report.

    However all the examples are using Selenium directly, while I am using PHPUnit which has its own API hiding the Selenium internals. I can't figure out how to set this Firefox option using PHPUnit, so I'm hoping someone else can tell me how this can be done!

    (No, I can't go into about:config and set it myself manually because the tests create a new clean browser profile each time the tests are run, so any manual config changes are lost.)

    解决方案

    Thanks to the Selenium developers I have a solution!

    Short version

    Put this in your test so that it gets called in the setUp() function:

    // Firefox mini-profile that sets focusmanager.testmode=true in about:config
    define('FIREFOX_PROFILE',
    'UEsDBAoAAAAAADqAxkSBK46tKgAAACoAAAAIABwAcHJlZnMuanNVVAkAA1BZkVM6WZFTdXgLAAEE
    6AMAAARkAAAAdXNlcl9wcmVmKCJmb2N1c21hbmFnZXIudGVzdG1vZGUiLCB0cnVlKTsKUEsBAh4D
    CgAAAAAAOoDGRIErjq0qAAAAKgAAAAgAGAAAAAAAAQAAAKSBAAAAAHByZWZzLmpzVVQFAANQWZFT
    dXgLAAEE6AMAAARkAAAAUEsFBgAAAAABAAEATgAAAGwAAAAAAA==');
    
    protected function setUp()
    {
        $this->setDesiredCapabilities(Array('firefox_profile' => FIREFOX_PROFILE));
    }
    

    This sets focusmanager.testmode to true.

    Long version

    You need to create your own mini Firefox profile with the preferences you want set, and pass it along at the start of your tests. Here's how to do it:

    1. Create a new folder and put the files you want in the Firefox profile in there. This can be anything (bookmarks, extensions, a copy of your own profile, etc.) but all we need here is a file called prefs.js which stores our about:config settings.

    2. Create prefs.js in this folder with the following content:

      user_pref("focusmanager.testmode", true);
      

    3. Zip up the folder (prefs.js should be in the root of the archive), and base64 encode it.

    If you're using Linux, you can do it all like this:

    mkdir firefox-profile
    cd firefox-profile
    echo 'user_pref("focusmanager.testmode", true);' >> prefs.js
    zip -r ../firefox-profile.zip *
    base64 < ../firefox-profile.zip
    

    Then take the base64 value and set it as the "firefox_profile" capability as per the short version above.

    这篇关于PHPUnit + Selenium:如何设置Firefox about:config选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆