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

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

问题描述

我正在使用以下所需功能启动chrome应用程序

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

我希望了解启用请求桌面网站"复选框的情况下启动chrome应用程序所需的功能.

参考屏幕:

解决方案

在移动自动化中,要在桌面模式下实现浏览器的自动化,我们可以借助 user-agent 来执行.

要遵循的步骤:

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

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

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

    代码:

      DesiredCapabilities上限= new DesiredCapabilities();caps.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");caps.setCapability(MobileCapabilityType.PLATFORM_VERSION,"1.0&");caps.setCapability(MobileCapabilityType.DEVICE_NAME,"Nexus_10&");caps.setCapability("chromedriverExecutable","\\ driver \\ chromedriver_74.exe");caps.setCapability(MobileCapabilityType.BROWSER_NAME,"chrome");ChromeOptions选项=新的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天全站免登陆