Webapplication automation on Browserstack -When we try to run WebApplication script with hardcoded URL > it runs successfully without any error on device Iphone 14 latest browser, same way when we are trying to read URL from configProperties - it is not picking up the tag based url or pick scenarios defined on feature file. Note-It is not an issue on desktopyour text
Driver code with hardcoded Url
public static RemoteWebDriver getBrowserStackDriver(Scenario scenario) throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
//Map<String,Object> bsCapabilities = new HashMap<>();
Map<String,String> bsCapabilities = new HashMap<>();
caps.setCapability("browserName", "safari");
caps.setCapability("device", "iPhone 14");
caps.setCapability("realMobile", "true");
caps.setCapability("os_version", "16");
bsCapabilities.put("browserstack.idleTimeout", "90");
bsCapabilities.put("browserstack.selenium_version", BasePage.setValue("bs_selenium_version"));
bsCapabilities.put("browserstack.use_w3c", BasePage.setValue("browserstack_use_w3c"));
caps.setCapability("name", scenario.getName());
bsCapabilities.forEach(caps::setCapability);
//bsCapabilities.put("device", BasePage.readConfig("chrome_emulation_device"));
//bsCapabilities.put("device", BasePage.readConfig("environment"));
WebDriver driver = new RemoteWebDriver(new URL(Objects.requireNonNull(setURL())), caps);
WebDriverWait wait = new WebDriverWait(driver, 10);
try {
driver.get("https://www.flexa.nl");
WebElement cookiepopUp=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='onetrust-accept-btn-handler']")));
cookiepopUp.click();
} catch (Exception e) {
logger.fatal("Browserstack driver is not initialized");
Assert.fail("ERROR: Browserstack driver is not initialized: " + e);
}
//quit the driver
//driver.quit();
return new RemoteWebDriver(new URL(Objects.requireNonNull(setURL())), caps);
//return null;
}
Code inside setURL() for BS
private static String setURL() {
String url = "";
if (endpoint.startsWith("saucelabs"))
url = "http://" + BasePage.setValue("sauce_username") + ":" + BasePage.setValue("sauce_accesskey")
+ "@ondemand.eu-central-1.saucelabs.com/wd/hub";
else if (endpoint.startsWith("browserstack"))
url = "https://" + BasePage.setValue("browserstack_username") + ":" + BasePage.setValue(
"browserstack_accesskey") + "@hub-cloud.browserstack.com/wd/hub";
return url;
}
Scenarios in feature file
@COATINGS_AUTOMOTIVE @Mobile_Smoke Feature: Atomotive_EN
@Search
Scenario: Verify search bar open-close
Given The user navigates to homepage
Then Homepage should be displayed
When User clicks open search bar
Then Search bar should be visible
When User clicks close search bar
Then Search bar should be invisible
@Search
Scenario: Verify search suggestion container for Market segment
Given The user navigates to homepage
Then Homepage should be displayed
When User clicks open search bar
Then Search bar should be visible
When User fills search input with Metal
Then Suggestion container overlay should be visible for EWT-918
It has to run script automatically by picking scenario from feature file and Url from configProperties
Note-Automation script runs on browserstack for Desktop without any issue, but same not working for Mobile( it is not picking the url or scenario from feature file or ConfigProperties) not an issue if I hardcode the URL
Also adding code which is working on windows 10 , chrome browser on mobile emulator
public static RemoteWebDriver getBrowserStackDriver(Scenario scenario) {
try {
setBrowserResolution();
//DesiredCapabilities caps = new DesiredCapabilities();
MutableCapabilities caps = new MutableCapabilities();
Map<String, String> bsCapabilities = new HashMap<>();
bsCapabilities.put("os", BasePage.setValue("bs_os"));
bsCapabilities.put("os_version", BasePage.setValue("bs_os_version"));
bsCapabilities.put("resolution", BasePage.setValue("bs_resolution"));
bsCapabilities.put("browser", BasePage.setValue("bs_browser"));
bsCapabilities.put("browser_version", BasePage.setValue("bs_browser_version"));
bsCapabilities.put("browserstack.selenium_version", BasePage.setValue("bs_selenium_version"));
bsCapabilities.put("name", scenario.getName());
bsCapabilities.put("browserstack.use_w3c", BasePage.setValue("browserstack_use_w3c"));
bsCapabilities.put("project", BasePage.setValue("bs_project_name"));
bsCapabilities.put("build", BasePage.setValue("cucumber.filter.tags") + "_" + LocalDate.now());
bsCapabilities.put("browserstack.idleTimeout", "90");
if (browser.equalsIgnoreCase("chrome")){
ChromeOptions withExtension = chromeOptions();
caps.setCapability(ChromeOptions.CAPABILITY, withExtension);
}
if (endpoint.endsWith("mobile")) {
ChromeOptions chromeOptions = new ChromeOptions();
Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", BasePage.readConfig("chrome_emulation_device"));
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
caps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
}
bsCapabilities.forEach(caps::setCapability);
return new RemoteWebDriver(new URL(Objects.requireNonNull(setURL())), caps);
} catch (Exception e) {
logger.fatal("Browserstack driver is not initialized");
Assert.fail("ERROR: Browserstack driver is not initialized: " + e);
}
logger.fatal("Browserstack driver is NULL : ");
return null;
}
And ChromeOption code for driver-Chrome
private static ChromeOptions chromeOptions() {
WebDriverManager.chromedriver().setup();
ChromeOptions chromeOptions = new ChromeOptions();
if (endpoint.endsWith("mobile")) {
Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", BasePage.readConfig("chrome_emulation_device"));
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
}
chromeOptions.setHeadless(Boolean.parseBoolean(BasePage.readConfig("headless")));
chromeOptions.addExtensions(new File("src/test/resources/extension/extension.crx"));
chromeOptions.setHeadless(Boolean.parseBoolean(BasePage.readConfig("headless")));
chromeOptions.addArguments("--remote-allow-origins=*", "ignore-certificate-errors");
return chromeOptions;
}