CB-11232:
- Adding whitelist rule to config.xml before Appium tests launch
- Fixed tapElementByXPath to correctly tap on elements when their location has a fractional number
diff --git a/lib/appium/helpers/wdHelper.js b/lib/appium/helpers/wdHelper.js
index 766e2ee..367e425 100644
--- a/lib/appium/helpers/wdHelper.js
+++ b/lib/appium/helpers/wdHelper.js
@@ -134,7 +134,7 @@
module.exports.tapElementByXPath = function (xpath, driver) {
return driver
- .waitForElementByXPath(xpath, 60000)
+ .waitForElementByXPath(xpath, 30000)
.getLocation()
.then(function (loc) {
if (loc.x <= 0) {
@@ -143,10 +143,12 @@
if (loc.y <= 0) {
loc.y = 1;
}
+ loc.x = Math.floor(loc.x + 1);
+ loc.y = Math.floor(loc.y + 1);
+
var wd = module.exports.getWD();
- var tapChoose = new wd.TouchAction();
- tapChoose.tap(loc);
- return driver
- .performTouchAction(tapChoose);
+ var tapElement = new wd.TouchAction();
+ tapElement.tap(loc);
+ return driver.performTouchAction(tapElement);
});
};
diff --git a/medic/medic-appium.js b/medic/medic-appium.js
index 64f034a..7bc4637 100644
--- a/medic/medic-appium.js
+++ b/medic/medic-appium.js
@@ -293,6 +293,23 @@
fs.writeFileSync(configFile, xml.write({indent: 4}), util.DEFAULT_ENCODING);
}
+function permitAccess(appPath, origin) {
+ var configFile = getConfigPath(appPath);
+ var xml = parseElementtreeSync(configFile);
+ var rule = xml.find("access[@origin=\"" + origin + "\"]");
+
+ util.medicLog("Adding a whitelist 'access' rule for origin: " + origin);
+
+ if (rule) {
+ util.medicLog("It is already in place");
+ } else {
+ rule = new elementTree.Element("access");
+ rule.attrib.origin = origin;
+ xml.getroot().append(rule);
+ fs.writeFileSync(configFile, xml.write({indent: 4}), util.DEFAULT_ENCODING);
+ }
+}
+
// remove medic.json and rebuild the app
function prepareApp(options, callback) {
var fullAppPath = getFullAppPath(options.appPath);
@@ -312,6 +329,7 @@
setPreference(fullAppPath, "CameraUsesGeolocation", "true");
}
addCspSource(fullAppPath, "connect-src", "http://*");
+ permitAccess(fullAppPath, "*");
// rebuild the app
util.medicLog("Building the app...");