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

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.

主站蜘蛛池模板: 洛阳市| 汾阳市| 中西区| 景泰县| 清流县| 华阴市| 都兰县| 天祝| 黎平县| 饶阳县| 惠安县| 宜丰县| 孝昌县| 潮州市| 吉安市| 祁门县| 许昌市| 祁门县| 枣强县| 彝良县| 新乡市| 双辽市| 德令哈市| 醴陵市| 临颍县| 福建省| 清徐县| 沾益县| 余姚市| 山丹县| 东丰县| 恩平市| 彩票| 微山县| 和田市| 常山县| 哈密市| 宁晋县| 镇巴县| 双辽市| 呼玛县|