从Chrome获取仿真器列表 [英] Get Emulator list from Chrome

查看:118
本文介绍了从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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆