# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1481889755 -19800
#      Fri Dec 16 17:32:35 2016 +0530
# Node ID c59c4e0486fe72a58eb7bb61e30dfc54b74384c3
# Parent  1441e29753f30f449e6d29354bdef05a078662ba
Verifies issue 34730 : Added automated test 'I34730_VerifyRFIDOnPaymentTab'

diff -r 1441e29753f3 -r c59c4e0486fe src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/rfid/I34730_VerifyRFIDOnPaymentTab.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/rfid/I34730_VerifyRFIDOnPaymentTab.java	Fri Dec 16 17:32:35 2016 +0530
@@ -0,0 +1,137 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo S.L.U.
+ * All portions are Copyright (C) 2016 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @Author RAN
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.rfid;
+
+import org.openbravo.test.mobile.common.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.common.selenium.utils.OBWait;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSRFIDTerminalHelper;
+
+public class I34730_VerifyRFIDOnPaymentTab extends WebPOSRFIDTerminalHelper {
+
+  @Override
+  public void testRun() {
+    verify(TestIdPack.LABEL_NEW_RECEIPT, "New Receipt");
+
+    // Verify RFID Enabled on Scan tab
+    verifyRFIDIconEnabled();
+    sendEpcCode(BASE_CAMP_DUFFEL_EPC_NUMBER);
+    verify(TestIdPack.LABEL_RECEIPT_ROW1_TITLE, "Base camp duffel 70 L");
+    verify(TestIdPack.LABEL_RECEIPT_ROW1_SERIAL_NUMBER, "Serial Number: 000000000001");
+    verify(TestIdPack.LABEL_TOTALTOPAY, "89.50");
+    tap(TestIdPack.BUTTON_PAY);
+
+    // Verify RFID Disabled on Payment tab
+    verifyRFIDIconDisabled();
+
+    tap(TestIdPack.BUTTON_SCAN);
+
+    // Verify RFID Enabled on Scan tab
+    verifyRFIDIconEnabled();
+
+    tap(TestIdPack.BUTTON_PAY);
+
+    // Verify RFID Disabled on Payment tab
+    verifyRFIDIconDisabled();
+
+    // Verify RFID Disabled on Payment tab With Popup
+    tap(TestIdPack.LABEL_DOCUMENTNUMBER);
+    verifyRFIDIconDisabled();
+    tap(TestIdPack.BUTTON_RECEIPT_PROPERTIES_CANCEL);
+
+    tap(TestIdPack.BUTTON_PAYMENTSWITCH);
+    tap(TestIdPack.BUTTON_KEYPAD_5);
+    tap(TestIdPack.BUTTON_KEYPAD_0);
+    tap(TestIdPack.BUTTON_KEYPAD_ENTER);
+    verify(TestIdPack.LABEL_RECEIPT_PAY_REMAINING, "39.50€");
+    tap(TestIdPack.BUTTON_RECEIPT_PAYMENT_ROW1_REMOVE);
+
+    // Verify RFID Disabled on Popup
+    tap(TestIdPack.BUTTON_DELETERECEIPT);
+    verifyRFIDIconDisabled();
+    tap(TestIdPack.BUTTON_DELETERECEIPT_CONFIRM);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+
+    // Verify RFID Enabled on Scan tab
+    verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+    verifyRFIDIconEnabled();
+  }
+
+  private void verifyRFIDIconEnabled() {
+    new OBWait() {
+      @Override
+      protected boolean until(final int currentIteration) {
+        return (Boolean) TestIdPack.LABEL_RFID_ICON.enyoNode().executeExtensionWithReturn(
+            ".attributes.class === '" + CSSRFIDICONENABLED + "'");
+      }
+
+      @Override
+      protected void timeout() {
+        throw new RuntimeException("Scanning focus was expected to turn on with green color icon.");
+      }
+    };
+    new OBWait() {
+      @Override
+      protected boolean until(final int currentIteration) {
+        return (Boolean) SeleniumHelper.executeScriptWithReturn(
+            "OB.UTIL.RfidController.get('isRFIDEnabled')", (Object) null);
+      }
+
+      @Override
+      protected void timeout() {
+        throw new RuntimeException("isRfidController was expected to be true.");
+      }
+    };
+  }
+
+  private void verifyRFIDIconDisabled() {
+    new OBWait() {
+      @Override
+      protected boolean until(final int currentIteration) {
+        return (Boolean) TestIdPack.LABEL_RFID_ICON.enyoNode().executeExtensionWithReturn(
+            ".attributes.class === '" + CSSRFIDICONDISABLED + "'");
+      }
+
+      @Override
+      protected void timeout() {
+        throw new RuntimeException("Scanning focus was expected to turn on with green color icon.");
+      }
+    };
+    verifyRFIDDisabled();
+  }
+
+  private void verifyRFIDDisabled() {
+    new OBWait() {
+      @Override
+      protected boolean until(final int currentIteration) {
+        return !(Boolean) SeleniumHelper.executeScriptWithReturn(
+            "OB.UTIL.RfidController.get('isRFIDEnabled')", (Object) null);
+      }
+
+      @Override
+      protected void timeout() {
+        throw new RuntimeException("isRfidController was expected to be true.");
+      }
+    };
+  }
+}
