官术网_书友最值得收藏!

Storing and retrieving a profile

We can also write the profile information of the browser to the JSON file and later instantiate new browsers with the same profile. The FirefoxProfile class provides a method to export the profile information as JSON. The following is its API syntax:

public String toJson()

The output or return type is a String, which contains the JSON information in it.

Now, to create a browser with the same profile, the FirefoxProfile class provides a static method that takes the JSON string as the input. The following is the API syntax:

public static FirefoxProfile fromJson(java.lang.String json) throws java.io.IOException

This is a static method in the FirefoxProfile class that takes the JSON string to create a profile from. The following is the code example for that:

FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(
new File("./src/test/resources/extensions/xpath_finder.xpi"));
String json = profile.toJson();
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(FirefoxProfile.fromJson(json));

In the preceding code, we have exported the profile as a JSON string. In your test case, you can write that JSON information to a file and store it. Later, you can read the JSON file using FirefoxOptions and create FirefoxDriver from that.

主站蜘蛛池模板: 古田县| 阿坝县| 七台河市| 吉木乃县| 乌鲁木齐县| 南靖县| 瑞丽市| 清原| 紫阳县| 花莲县| 林芝县| 平果县| 贵溪市| 宝兴县| 贡觉县| 博乐市| 深圳市| 纳雍县| 镇巴县| 库尔勒市| 沙洋县| 万山特区| 松江区| 龙陵县| 湘潭市| 视频| 吉首市| 绥德县| 贺兰县| 徐州市| 永丰县| 新密市| 丹寨县| 湄潭县| 易门县| 甘谷县| 石嘴山市| 阜康市| 江门市| 远安县| 瑞昌市|