From f887fcd10ef288f13ddacf3b06ed77c3400efcd2 Mon Sep 17 00:00:00 2001 From: Bruce Gordon Date: Mon, 15 Jun 2015 15:14:33 -0400 Subject: [PATCH 1/2] remove dependency on tuneup.js --- buttonHandler.js | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/buttonHandler.js b/buttonHandler.js index 3fa2f6b..40c7627 100644 --- a/buttonHandler.js +++ b/buttonHandler.js @@ -42,6 +42,23 @@ function ButtonHandler(buttonName, checkEveryNumber, useNavBar, optionalIsTrueFu this.statsHandleInvokedCount = 0; this.statsHandleNotValidAndVisibleCount = 0; this.statsHandleErrorCount = 0; + this.debugLogElementTreeOnIsTrue = false; +} + +ButtonHandler.prototype.setDebugLogElementTreeOnIsTrue = function(aBool) { + this.debugLogElementTreeOnIsTrue = aBool; +} + +ButtonHandler.prototype.isObjectNil = function(anObject) { + return anObject.toString() == "[object UIAElementNil]" +}; + +ButtonHandler.prototype.isValidAndVisible = function(aButtonOrNil) { + if (this.isObjectNil(aButtonOrNil)) { + return false; + } + //we now expect aButtonOrNil to be a button + return aButtonOrNil.checkIsValid() && aButtonOrNil.isVisible(); } // return true if we our button is visible @@ -49,19 +66,23 @@ ButtonHandler.prototype.isTrue = function(target, eventCount, mainWindow) { this.statsIsTrueInvokedCount++; var result; if (this.optionalIsTrueFunction == null) { + if (this.debugLogElementTreeOnIsTrue) { + UIATarget.localTarget().logElementTree(); + } var aButton = this.findButton(target); - result = aButton.isNotNil() && aButton.validAndVisible(); - } else { - result = this.optionalIsTrueFunction(target, eventCount, mainWindow); - } - if (result) { - this.statsIsTrueReturnedTrue++; - } else { - this.statsIsTrueReturnedFalse++; - }; - return result; + result = this.isValidAndVisible(aButton); + } else { + result = this.optionalIsTrueFunction(target, eventCount, mainWindow); + } + if (result) { + this.statsIsTrueReturnedTrue++; + } else { + this.statsIsTrueReturnedFalse++; + }; + return result; }; + ButtonHandler.prototype.findButton = function(target) { return this.useNavBar ? target.frontMostApp().mainWindow().navigationBar().buttons()[this.buttonName] : @@ -82,7 +103,7 @@ ButtonHandler.prototype.isExclusive = function() { ButtonHandler.prototype.handle = function(target, mainWindow) { this.statsHandleInvokedCount++; var button = this.findButton(target); - if (button.validAndVisible()) { + if (this.isValidAndVisible(button)) { try{ button.tap(); } catch(err) { From 4ec7c874750539e568ada43e4745da474bb5b6e3 Mon Sep 17 00:00:00 2001 From: Bruce Gordon Date: Tue, 30 Jun 2015 11:40:28 -0400 Subject: [PATCH 2/2] fixing white space --- buttonHandler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buttonHandler.js b/buttonHandler.js index 40c7627..0057d96 100644 --- a/buttonHandler.js +++ b/buttonHandler.js @@ -67,8 +67,8 @@ ButtonHandler.prototype.isTrue = function(target, eventCount, mainWindow) { var result; if (this.optionalIsTrueFunction == null) { if (this.debugLogElementTreeOnIsTrue) { - UIATarget.localTarget().logElementTree(); - } + UIATarget.localTarget().logElementTree(); + } var aButton = this.findButton(target); result = this.isValidAndVisible(aButton); } else {