Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protractor ChromeDriver configuration for mobile emulation #728

Open
michaelerobertsjr opened this issue Dec 2, 2014 · 13 comments
Open

Comments

@michaelerobertsjr
Copy link

We're working on end to end testing with protractor. We need to test our website on a variety of mobile devices so we would like to use ChromeDriver Emulation

The docs on the site are really thin, can anyone point me in the correct direction to get the setup complete? Here is what I have so far:

Updated chromedriver to 2.9.248307 (chromedriver 2.11 appears to be the first version with mobile emulation but 2.10 was the default in the generator.

In protractor.conf.js have set chromeOnly: true

Device capabilities are shown below. It doesn't seem to matter what I provide, it runs chromedriver but it appears to ignore the capabilities set in protractor.conf.js:

{
  "browserName": "chrome",
  "device": "Apple iPhone 6",
  "deviceMetrics": {
    "width": 360,
    "height": 640,
    "pixelRatio": 3.0
  }
}

What else needs to be configured/provided?

@JaKXz JaKXz added the question label Mar 5, 2015
@drizgolovicha
Copy link

up, this question is also important for me

@Awk34 Awk34 added this to the 2.4.0 milestone Jul 16, 2015
@daniel-rabe
Copy link

try:

capabilities: {
  'browserName': 'chrome',
  'chromeOptions': {
    'args': ['show-fps-counter=true'],
    'mobileEmulation' : {
      'deviceName': 'Apple iPhone 6'
    }
  }
}

@Karpo72
Copy link

Karpo72 commented Oct 20, 2015

@daniel-rabe @michaelerobertsjr Nice I'm also interested in this kind of solution. Is there also a way to name the xml output files different by deviceName?

@LaiaPR
Copy link

LaiaPR commented Feb 10, 2016

@daniel-rabe @michaelerobertsjr Hi! thanks to your solution now I am able to run my tests of a Web with Chromedriver mobile emulation. This is my config:

capabilities: { 
    'browserName': 'chrome', 
    'chromeOptions': { 
      'mobileEmulation' : { 
        'deviceName': 'Google Nexus 5' 
      } 
    } 
  }

Is there a way to have an "array" of devices to run the tests on? What I really would like is to be able to run the same tests over a list of device

@aluzardo
Copy link

Thanks @LaiaPR your solution works pretty well.

I have a solution to add a list of devices. It is working for me but I think that maybe there is a clean solution.

Remove capabitities and add multCapabilities, example:

multiCapabilities: [
        {
            browserName: 'firefox'
        },
        {
            browserName: 'chrome'
        },
        {
            browserName: 'chrome',
            'chromeOptions': {
                'mobileEmulation': {
                    'deviceName': 'Google Nexus 5'
                }
            }
        },
        {
            browserName: 'chrome',
            'chromeOptions': {
                'mobileEmulation': {
                    'deviceName': 'Apple iPhone 6'
                }
            }
        },
    ]

Testing on desktop (firefox, chrome)
Testing on Google Nexus 5 (chrome)
Testing on Apple iPhone 6 (chrome)

@LaiaPR
Copy link

LaiaPR commented Jun 20, 2016

@aluzardo Hi!! Thanks for sharing your solution! I found the same solution as you (multicapabilities) and forgot to post it >_< Yes, it's the right one!

@bchuckles
Copy link

I implemented this now non of my swiping gestures work

@AndyForGit
Copy link

@daniel-rabe Thanks for sharing your solution!

@ingriddbritok3
Copy link

ingriddbritok3 commented Apr 15, 2020

Hi all, I am struggling to run the protractor emulating the mobile. my conf file is as you suggested:
exports.config = {
directConnect: true,

// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'mobileEmulation' : {
'deviceName': 'Google Nexus 5'
}
}
},
But I got this error: WebDriverError: invalid argument: cannot parse capability: chromeOptions
from invalid argument: cannot parse mobileEmulation
from invalid argument: 'Google Nexus 5' must be a valid device
from unknown error: must be a valid device

Am I missing something? Is there another place where I have to declare the device? Are you also using Appium?

@orlyohreally
Copy link

@ingriddbritok3 I have tried 'Nexus 5' instead of 'Google Nexus 5' and it worked.

@nishudixit
Copy link

Yes it worked with only giving 'Nexus 5'

I want to run single scenario on mobile emulation. How can I achieve that? Can it be possible using cucumber tagged hook? If yes then how? I am using protractor-cucumber-framework.

@offirpeer
Copy link

@nishudixit 'Nexus 5` is very old device, I added a custom device such as iPhone 12 but it doesn't work, any idea why it supports only these super old devices?

@ohlori
Copy link

ohlori commented Jun 17, 2021

How to set the orientation to landscape??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests