在 android 中启动带有桌面视图的 chrome 浏览器应用程序 [英] Launching chrome browser application with desktop view in android

查看:62
本文介绍了在 android 中启动带有桌面视图的 chrome 浏览器应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下所需功能启动 Chrome 应用

DesiredCapabilities capabilities = new DesiredCapabilities();capabilities.setCapability("deviceName", "Android");capabilities.setCapability("platformName", "Android");capability.setCapability(CapabilityType.BROWSER_NAME, "Chrome");capabilities.setCapability("platformVersion", "5.0.2");capabilities.setCapability("appPackage", "com.android.chrome");capabilities.setCapability("appActivity", "com.google.android.apps.chrome.ChromeTabbedActivity");capabilities.setCapability("disable-popup-blocking", true);driverC = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

我想知道在启用请求桌面站点"复选框的情况下启动 Chrome 应用程序所需的功能.

屏幕供参考:

解决方案

在移动自动化中,为了在桌面模式下自动化浏览器,我们可以在 user-agent 的帮助下执行.

要遵循的步骤:

  1. 为您的设备和浏览器找到用户代理.在您的设备/模拟器中导航到

  2. --user-agent 标志的帮助下,将上述用户代理添加到 ChromeOptions.然后分配具有所需功能的标志选项,如下所示.

    在用户代理上,您可以添加所有浏览器或您想要自动化的浏览器.

    代码:

    DesiredCapabilities caps = new DesiredCapabilities();caps.setCapability(MobileCapabilityType.PLATFORM_NAME,Android");caps.setCapability(MobileCapabilityType.PLATFORM_VERSION,10.0");caps.setCapability(MobileCapabilityType.DEVICE_NAME,Nexus_10");caps.setCapability(chromedriverExecutable",\\driver\\chromedriver_74.exe");caps.setCapability(MobileCapabilityType.BROWSER_NAME,chrome");ChromeOptions options = new ChromeOptions();options.addArguments("--user-agent=Chrome/74.0.3729.185");caps.setCapability(ChromeOptions.CAPABILITY,选项);url = "http://127.0.0.1:4723/wd/hub";driver = new AndroidDriver<>(new URL(url), caps);

  3. 现在运行程序并验证执行情况.浏览器会在自动化设备上以桌面模式自动打开.

(这是用 Java 语言执行的,类似的方法可以用其他语言执行)

I am launching chrome app using the following desired capabilities

DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName", "Android");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
    capabilities.setCapability("platformVersion", "5.0.2");
    capabilities.setCapability("appPackage", "com.android.chrome");
    capabilities.setCapability("appActivity", "com.google.android.apps.chrome.ChromeTabbedActivity");
    capabilities.setCapability("disable-popup-blocking", true);
    driverC = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

I wish to know the capabilities required to launch chrome app with Request desktop site check box enabled.

Screen for referrence:

解决方案

In Mobile automation, to automate the browser in Desktop mode we can perform with the help of user-agent.

Steps to follow:

  1. Find the user agent for your device and browser. In your device/emulator navigate to the find my user agent website and it automatically displays the user agent as below. (make a note of it)

  2. Add the above user agent to the ChromeOptions with the help of --user-agent flag. Then assign the flag option with the desired capabilities as below.

    On the user agent you can add all the browsers OR the one you wanted to automate.

    CODE:

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.0");
    caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus_10");                
    caps.setCapability("chromedriverExecutable","\\driver\\chromedriver_74.exe");
    caps.setCapability(MobileCapabilityType.BROWSER_NAME, "chrome");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--user-agent=Chrome/74.0.3729.185");
    caps.setCapability(ChromeOptions.CAPABILITY, options);
    url = "http://127.0.0.1:4723/wd/hub";
    driver = new AndroidDriver<>(new URL(url), caps);
    

  3. Now run the program and verify the execution. The browser automatically opens in desktop mode on the automation device.

(This was performed with the Java language and similar approach could be performed with the other languages)

这篇关于在 android 中启动带有桌面视图的 chrome 浏览器应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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