Reputation: 31
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
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
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
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