Facebook php-webdriver 设置Firefox Profile

Firefox Profile是用来指定firefox的设定档,透过profile我们可以用来停用部分browser功能来实现自动化测试的功能,一般selenium会自动建立一个新的Firefox Profile,这个profile预设是不能用来下载档案的,如果你用webdriver来点击下载档案的功能,那么页面就会跳出一个确认视窗,然后页面就会卡在那里,这时我们就可以透过profile的设定,让下载档案这件事不需要点击确认。

如何建立一个profile呢,首先你可以去看Mozilla官方文件

  • https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles
  • 这里我建立好一个profile叫“test_profile”,你可以在地址栏输入about:config, 就能打开Firefox的所有设定,因为我想停用档案下载的确认视窗,那个功能设定值为“browser.helperApps.neverAsk.saveToDisk”,找到这个值,然后设定允许下载的档案类型,例如Excel档为“application/vnd.ms-excel”。

    接着程序要设定“webdriver.firefox.profile”的值,指定我们要用的Profile名称即可

    $caps = DesiredCapabilities::firefox();
    $caps->setCapability("webdriver.firefox.profile", "test_profile"); 
    $driver = RemoteWebDriver::create("selenium url xxx", $caps, 5000);
    

    另外Facebook webdriver也提供了另一个方式,可以即时设定Firefox Profile。

    $profile = new FirefoxProfile();
    $profile->setPreference(
        'browser.helperApps.neverAsk.saveToDisk', 
        'application/vnd.ms-excel'  
    );
    $profile->addExtension('firebug-2.0.1.xpi'); 
    

    $caps = DesiredCapabilities::firefox();
    $caps->setCapability(FirefoxDriver::PROFILE, $profile);
    d r i v e r = R e m o t e W e b D r i v e r : : c r e a t e ( driver = RemoteWebDriver::create( driver=RemoteWebDriver::create(seleniumUrl, $caps, 5000);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值