- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 191字
- 2021-08-13 16:08:14
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.
- 物聯網安全:理論、實踐與創新
- Hands-On Industrial Internet of Things
- 互聯網安全的40個智慧洞見:2015年中國互聯網安全大會文集
- 網絡的琴弦:玩轉IP看監控
- Metasploit Penetration Testing Cookbook
- 物聯網之霧:基于霧計算的智能硬件快速反應與安全控制
- 網絡AI+:2030后的未來網絡
- 物聯網頂層設計與關鍵技術
- Microsoft Power Platform Enterprise Architecture
- 一本書讀懂物聯網
- 互聯網安全的40個智慧洞見(2016)
- 中國互聯網發展報告2021
- Web用戶查詢日志挖掘與應用
- Intelligent Mobile Projects with TensorFlow
- 移動互聯網環境下的核心網剖析及演進