Dushyant Patil
Dushyant Patil

Reputation: 31

Serenity how to run on tests chrome emulator (mobile mode in chrome web browser)

I am new to Serenity and I wanted to run the test in the mobile mode present in the chome web browser, it is called as mobile emulation. I have refered this link and using selenium java i have managed to do it. https://chromedriver.chromium.org/mobile-emulation

I need to do the same with Serenity.

Can anybody tell me what needs to be done ? It can be added to the property file, if yes then how ?

Upvotes: 0

Views: 1203

Answers (3)

Pushparaj
Pushparaj

Reputation: 120

You need to create a new package and under that, you can implement a custom driver to handle mobile emulation by creating a class that should implement DriverSource. Also, bring the below changes in your serenity.properties file.

class CustomeDriver implements DriverSource {
    Webdriver driver;
    @Override
    public WebDriver newDriver() {

        Map<String, String> mobileEmulation = new HashMap<>();
        mobileEmulation.put("deviceName", "iPhone 6");

        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);

        driver = new ChromeDriver(chromeOptions);
        return driver;
    }

    @Override
    public boolean takesScreenshots() {
        return true;
    }
}


webdriver.driver = provided
webdriver.provided.type = mydriver
webdriver.provided.mydriver = **screenplay**.CustomeDriver 
serenity.driver.capabilities = mydriver

--> screenplay is the package name

Finally, you need to get the driver by calling getDriver()..navigate().to("https://www.google.com");

Upvotes: 2

SiKing
SiKing

Reputation: 10329

The link you provided gives you the Java code:

Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Nexus 5");

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
WebDriver driver = new ChromeDriver(chromeOptions);

A trivial search for "serenity chrome options" leads to (first hit!) this page, which says:

In Serenity, you would pass these using properties prefixed with the chrome_preferences prefix

So perhaps something like:

chrome_preferences.mobileEmulation.deviceName = "Nexus 5"

Upvotes: 0

Sergie Kischenko
Sergie Kischenko

Reputation: 1

For example, for iPhone 6/7/8 Plus you can use the "serenity.browser.width=414" and "serenity.browser.height=736" Serenity properties (http://thucydides.info/docs/serenity-staging/#_serenity_system_properties_and_configuration) and put them into the serenity.properties file in the root directory of your project

Upvotes: 0

Related Questions