JVM argument – -Dswitch

Finally, the next example shows how to set the optional browser preferences as a JVM argument using the TestNG parameter attribute in the suite XML file:

// pass in the key:value pairs as a runtime argument
-Dbrowserprefs=applicationCacheEnabled:false,
network.cookie.cookieBehavior:0


// pass in the key:value pairs as a TestNG XML parameter
<test name="Selenium TestNG Test Suite">
<parameter name="browser" value="chrome" />
<parameter name="platform" value="Windows 10" />
<parameter name="browserPrefs" value="intl.accept_languages:fr" />

<classes>
<class name="com.myproject.MyTest" />
</classes>
</test>

// for convenience, create a setPreferences method
// to build the map to pass into the driver
public Map<String, Object> setPreferences() {
Map<String, Object> prefsMap = new HashMap<String, Object>();
List<String> allPrefs = Arrays.asList(
System.getProperty("browserPrefs").split(",", -1));

// extract the key/value pairs and pass to map...
for ( String getPref : allPrefs ) {
prefsMap.put(getPref.split(":")[0], getPref.split(":")[1]);
}

return prefsMap;
}

// set JVM arg, call this method on-the-fly, create new driver
if ( System.getProperty("browserPrefs") != null ) {
CreateDriver.getInstance().setDriver("firefox",
"Windows 10",
"local",
CreateDriver.getInstance().setBrowserPrefs()
);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.96.146