How to automate the mobile emulation in chrome browser in browserstack? - java

I'm trying to automate the mobile emulation in chrome browser. So I have done in local chrome execution successfully, not sure about the browserstack chrome mobile emulators. I just wanted to know how should we do the same in browserstack.
Similar to local chrome execution, just have to open a chrome browser with the given chrome options(android,ipad,iphone) in browserstack.
https://chromedriver.chromium.org/mobile-emulation
Local chrome Execution code snippet:
`"chromeAndroid": {
"deviceName": "Nexus 5"
},
"chromeiPhone": {
"deviceName": "iPhone 5"
},
"chromeiPad": {
"deviceName": "iPad"
},
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put(pair.getKey().toString(), pair.getValue().toString());
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
driver = new ChromeDriver(chromeOptions);`
We are parsing the data from above json file and pass it onto the chrome options.
Local chrome execution Screenshot:
Please suggest me by providing some details or code snippet for remoteWebdriver as we are running the browser stack tests from Jenkins and browserstack local.
Please help me!

What do you mean by the "mobile emulation in chrome browser" in browserstack? If it's a desktop Chrome with the mobile emulation enabled (according to your code) then everything should work the same as locally.
If you are testing Chrome in a physical device in browserstack then you need to pass a few more capabilities like
realMobile - should be set to true
device - specify a device
os_version - OS version of a device you want to test
browserstack.appium_version - Appium version
You can find more by the link
Also, here is a guide on Selenium tests with Chrome

Related

selenium user profile in headless mode, chrome browser

Situation: i'm running chrome in headless mode (see arguments in section part of code), when i connect to page (let say i sign into the page before i run my app that's using selenium) i'm already login to page (because it's using existing profile and i login to page before i started my app) that's on first computer, correct PROFILE is used.
On second computer i'm running Chrome with same settings (same as on computer one) and when i go to the same page as on computer one i'm NOT login to the page (because the profile with existing session is not used)...
If i remove the --headless option everything works... however i want to running it in HEADLESSS mode with current profile used by chrome.
Driver: Chrome driver version 101
Java version: 15
Browser: Google Chrome (version 101.0.4951.64)
Operating system: both computers have Windows 10
Part of code:
String userP=getChromeUserProfilePath();
options.addArguments(String.format("--user-data-dir=%s",userP));
if(getChromeUserProfileName()!=null){
options.addArguments(String.format("--profile-directory=%s",getChromeUserProfileName()));
}
options.addArguments("--headless",
"--disable-gpu",
"--window-size=1920,1200",
"--ignore-certificate-errors",
"--disable-extensions",
"--no-sandbox",
"--disable-dev-shm-usage");
ChromeDriver webDriver = new ChromeDriver(options);
Questions:
Where's the catch ? How do i make it work for second computer?

Run selenium with cache on centos/linux

I'm able to run selenium on non GUI centos/linux machine in headless mode.
I have been trying to run it with cache enable by passing below chromeoptions arguments.
chromeOptions.addArguments("user-data-dir=~/.config/google-chrome");
It has started fine and identified elements till login page(which is first page) and couldn't identify any locators after that.
Is it the right approach to run cache enabled selenium run?
It's not that super clear when you mention about executing your tests with cache enabled. However, adding the argument user-data-dir is the canonical way to use a specific Chrome Profile.
You can find a couple of detailed discussions in:
How to open a Chrome Profile through Python
How to use Chrome Profile in Selenium Webdriver Python 3
Adding those options helps me to prevent crashes and errors on a linux remote machine
ChromeOptions options = new ChromeOptions();
options.addArguments(
"--disable-gpu",
"--headless",
"--window-size=1920,1200",
"--ignore-certificate-errors",
"--disable-extensions",
"--no-sandbox",
"--disable-dev-shm-usage",
"--hide-scrollbars",
"--allow-running-insecure-content",
"--disable-infobars",
"--ignore-certificate-errors");
Webdriver driver = new ChromeDriver(options);

Issue while opening headless chrome in remote jenkins server using selenium java

I am having trouble in using headless chrome on jenkins remote server. the test is failed at the time of url invoking or takes to much of a time like 5+mins and test failed as it wont have waiting time for that long, i have tried different chromeoption like disable gpu, nosandbox etc still the issue is not solved.There is no issue in opening those url in normal mode but its not working on headless mode. i am using this chromeoptions for test:
enter code here
``` chromeOptions.addArguments("--window-size=1366,768");
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("--disable-extensions");
chromeOptions.addArguments("--proxy-server='direct://'");
chromeOptions.addArguments("--proxy-bypass-list=*");
chromeOptions.addArguments("--start-maximized");
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("no-sandbox", "--disable-infobars", "--disable-dev-shm-usage", "--disable-browser-side-navigation",
"--ignore-certificate-errors");```

Unable to launch "https" mobile websites in emulator using selenium webdriver under proxy settings

Unable to launch "HTTPS" mobile sites, normal web sites in emulator using selenium webdriver.
What are the proxy settings to be used for opening these sites in Emulator. I am using windows XP
Please let me know how to set
proxy settings and
hOW TO handle SSL certificates using Android driver in selenium
The connection code is as follows
DesiredCapabilities caps = DesiredCapabilities.android();
caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new AndroidDriver(caps);
driver.get("https://www.xyz.co.in/");
System.out.println(driver.getTitle());

Can't test a remote HTML/CSS/JS/Java website with Cucumber + Selenium Webdriver + Chrome + Capybara

I'm trying to test with Cucumber + Selenium + Capybara a remote HTML/CSS/JS website which uses a Java .
The website works fine on the Chrome browser, but when I launch my test, the Chrome browser is launched on the website, but the Java applet is not loaded at all.
Looks like the Chrome browser environment launched by Webdriver does not load any third party chrome plugins like Java.
Is there any way to circumvent this ?
Thanks in advance, best regards
Geoffroy
You can load a custom profile with the following code:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir=/path/to/profile/directory"));
WebDriver driver = new ChromeDriver(capabilities);
See the selenium chrome documentation: http://code.google.com/p/selenium/wiki/ChromeDriver
You can maybe try Selenium Remote Control instead of Webdriver. I haven't personally tried Selenium RC with third party tools, but it could an option to try while you're looking for alternatives.

Categories

Resources