从Chrome获取仿真器列表 [英] Get Emulator list from Chrome
问题描述
根据 ChromeDriver网站,用户可以使用在Chrome中创建/展示的用于Selenium执行的仿真器.
As per ChromeDriver site, the user can use the emulators created/present in the chrome for Selenium execution.
我想显示所有从Chrome
创建/可用的仿真器. Chrome
可能会将详细信息存储在某些json文件或其他内容中.
I wanted to display all the created/available emulators from Chrome
. Chrome
could be storing that details in some json file or something.If so how to access it and print it in Java
推荐答案
找到 Notepad ++ Find in Files
并找到它.
数据以JSON格式存储在文件中
The data is stored in JSON format in file
C:\ Users \您的用户名\ AppData \ Local \ Google \ Chrome \ User Data \ Default \ Preferences
C:\Users\Your UserName\AppData\Local\Google\Chrome\User Data\Default\Preferences
在密钥下
devtools> preferences> standardEmulatedDeviceList
devtools>preferences>standardEmulatedDeviceList
我已经用Jackson解析了JSON
I have used Jackson to parse the JSON
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Test {
public static void main(String[] args) {
try {
ObjectMapper mapper = new ObjectMapper();
Map map = mapper.readValue(
new File("C:\\Users\\<UserName>\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Preferences"),
Map.class);
Map devTools = (Map) map.get("devtools");
Map preferences = (Map) devTools.get("preferences");
String standardEmulatedDeviceList = (String) preferences.get("standardEmulatedDeviceList");
List emulatorMap = mapper.readValue(standardEmulatedDeviceList, List.class);
System.out.println(emulatorMap.size());
for (Object object : emulatorMap) {
Map device = (Map) object;
System.out.println(device.get("title"));
}
} catch (IOException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
这篇关于从Chrome获取仿真器列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!