简体   繁体   English

如何在Work Space中永久添加Selenium Firefox配置文件

[英]How to add Selenium Firefox profile in Work Space permanent

I have created Firefox profile for webDriver. 我已经为webDriver创建了Firefox配置文件。

Code is below for the created profile: 下面是创建的配置文件的代码:

    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile myProfile = profile.getProfile("Selenium");
    driver = new FirefoxDriver(myProfile);

Where "Selenium" is profile name. 其中“ Selenium”是配置文件名称。 It is working fine in my machine. 我的机器运行正常。 Now, I want to deploy this project to some one else. 现在,我想将该项目部署到其他项目。 But he has not set the preferences in firefox profile as same as mine. 但是他没有像我一样在firefox配置文件中设置首选项。 So, he cant use the script. 所以,他不能使用脚本。

How can i add this firefox profile in my framework/project, so if i give the same framework to some else, he can use the same functionality. 我如何在我的框架/项目中添加此firefox配置文件,所以如果我将相同的框架提供给其他框架,他可以使用相同的功能。

You need to backup your profile as described in this tutorial from Mozilla. 您需要按照本教程中的说明从Mozilla备份个人资料。 Than make that profile part of you project (so drop it somewhere into src/test/resources ) and just do 比将配置文件作为项目的一部分(因此将其放置到src/test/resources某个位置),然后执行

File profileDir = new File(profileLocation);
FirefoxProfile profile = new FirefoxProfile(profileDir);
WebDriver driver = new FirefoxDriver(profile);

Or alternatively you can create your own inside Java code, it depends how much settings your profile has. 或者,您也可以创建自己的内部Java代码,这取决于您的配置文件有多少设置。

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "some UA string");
WebDriver driver = new FirefoxDriver(profile);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM