Parameter processing methods

Once the optional preferences are passed into the setDriver method, the user then has to process those options. For instance, there may be DesiredCapabilities,  ChromeOptions, or FirefoxProfile preferences that need to be processed. First, for each driver-type instance, there needs to be a check to see if the options have been passed in, then if so, they have to be processed. Each type will be outlined as shown here:

/**
* Process Desired Capabilities method to override default browser
* or mobile driver behavior
*
* @param caps - the DesiredCapabilities object
* @param options - the key: value pair map
* @throws Exception
*/

private void processDesiredCaps(DesiredCapabilities caps,
Map<String,
Object>[] options
)
throws Exception {

for
( int i = 0; i < options.length; i++ ) {
Object[] keys = options[i].keySet().toArray();
Object[] values = options[i].values().toArray();

for
( int j = 0; j < keys.length; j++ ) {
if ( values[j] instanceof Integer ) {
caps.setCapability(keys[j].toString(),
(int) values[j]);
}
else if ( values[j] instanceof Boolean) {
caps.setCapability(keys[j].toString(),
(boolean) values[j]);
}
else if ( isStringInt(values[j].toString()) ) {
caps.setCapability(keys[j].toString(),

Integer.valueOf(values[j].toString()));
}
else if ( Boolean.parseBoolean(values[j].toString()) ) {
caps.setCapability(keys[j].toString(),

Boolean.valueOf(values[j].toString()));
}
else {
caps.setCapability(keys[j].toString(),
values[j].toString());
}
}
}
}
/**
* Process Firefox Profile Preferences method to override default
* browser driver behavior
*
* @param caps - the FirefoxProfile object
* @param options - the key: value pair map
* @throws Exception
*/
private void processFFProfile(FirefoxProfile profile, Map<String, Object>[] options) throws Exception {
for (int i = 0; i < options.length; i++) {
Object[] keys = options[i].keySet().toArray();
Object[] values = options[i].values().toArray();

// same as Desired Caps except the following difference
for (int j = 0; j < keys.length; j++) {
if (values[j] instanceof Integer) {
profile.setPreference(keys[j].toString(),
(int) values[j]);
}

// etc...
}
}
}
/**
* Process Chrome Options method to override default browser
* driver behavior
*
* @param caps - the ChromeOptions object
* @param options - the key: value pair map
* @throws Exception
*/
private void processCHOptions(ChromeOptions chOptions, Map<String, Object>[] options) throws Exception {
for (int i = 0; i < options.length; i++) {
Object[] keys = options[i].keySet().toArray();
Object[] values = options[i].values().toArray();

// same as Desired Caps except the following difference

for (int j = 0; j < keys.length; j++) {
if (values[j] instanceof Integer) {
values[j] = (int) values[j];
chOptions.setExperimentalOption("prefs", options[i]);
}

// etc...
}
}
}
..................Content has been hidden....................

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