import unittest
from appium import webdriver
import time
import os
import HtmlTestRunner


class JustPayTest(unittest.TestCase):

    def setUp(self):
        desired_cap = {
            "automationName": "UiAutomator2",
            "platformName": "Android",
            "platformVersion": "8.0",
            "deviceName": "Galaxy J4",
            "udid": "42002e57ce412557",
            "newCommandTimeout": "500",
            "noReset": "true",
            "app": "C:\\Users\\Fatin Nur\\Desktop\\Staging2.2.0.apk",
            "appPackage": "com.justpaybd.app",
            "appActivity": "com.justpaybd.app.MainActivity",
        }

        self.driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_cap)
        time.sleep(5)

    def test_a_login(self):
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='+880']").send_keys("1716642408")
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='PIN']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,676][694,769]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='SIGN-IN']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Menu']").click()
        time.sleep(5)

    def test_b_send(self):
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='PIN']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,608][540,702]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Authorize']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Menu']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@bounds='[129,550][340,630]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@bounds='[581,268][654,336]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Jamuna Bank-7260']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='Amount']").send_keys("100")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,502][694,596]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@bounds='[581,740][654,808]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Bebesh Barua']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Now']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='PIN Code']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,576][540,669]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Authorize']").click()
        time.sleep(5)

    def test_c_request(self):
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='PIN']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,608][540,702]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Authorize']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Menu']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@bounds='[129,676][340,756]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.view.ViewGroup[@bounds='[26,248][694,355]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Jamuna Bank-7260']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='Amount']").send_keys("100")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,502][694,596]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@bounds='[581,740][654,808]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Bebesh Barua']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Request Money']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='PIN Code']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,576][540,669]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Authorize']").click()
        time.sleep(5)

    def test_d_instruction(self):
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='PIN']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,608][540,702]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Authorize']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Menu']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@bounds='[463,550][675,630]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.view.ViewGroup[@bounds='[26,248][694,355]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Jamuna Bank-7260']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='Amount']").send_keys("100")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,502][694,596]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@bounds='[581,740][654,808]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Bebesh Barua']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Schedule/Repeat']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='Instruction']").send_keys("Test")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,390][694,483]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='SELECT DATE']").click()
        time.sleep(5)
        for x in range(3):
            self.driver.find_element_by_id("android:id/next").click()
        self.driver.find_element_by_xpath("//android.view.View[@content-desc='31 August 2019']").click()
        self.driver.find_element_by_id("android:id/button1").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Confirm']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,576][540,669]']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,576][540,669]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Authorize']").click()
        time.sleep(5)

    def test_e_topUp(self):
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='PIN']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,608][540,702]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Authorize']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Menu']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@bounds='[129,957][340,1037]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@bounds='[581,352][654,420]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Banglalink']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='01XXXXXXXXX']").send_keys("01970211290")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,553][694,647]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@bounds='[581,791][654,859]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Jamuna Bank-7260']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='Amount']").send_keys("10")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,1025][694,1118]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Top Up']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='PIN Code']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,576][540,669]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Authorize']").click()
        time.sleep(5)

    def test_f_addNewMember(self):
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='PIN']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,608][540,702]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Authorize']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Menu']").click()
        time.sleep(5)
        self.driver.swipe(373, 1221, 373, 614)
        time.sleep(5)
        self.driver.tap([(515, 706)])
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.view.ViewGroup[@bounds='[427,203][476,252]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.view.ViewGroup[@bounds='[26,367][694,474]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Jamuna Bank']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='Account Number']").send_keys("00060318000056")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,621][694,715]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.ImageView[@bounds='[35,822][88,857]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath(
            "//android.widget.TextView[@text='United Arab Emirates (‫الإمارات العربية المتحدة‬‎)']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='+971']").send_keys("589050712")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[105,822][668,857]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.view.ViewGroup[@bounds='[26,978][694,1085]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Co-Worker']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@bounds='[251,1156][469,1224]']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='PIN Code']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,576][540,669]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Authorize']").click()
        time.sleep(5)

    def test_g_searchBranch(self):
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='PIN']").send_keys("123123")
        self.driver.find_element_by_xpath("//android.widget.EditText[@bounds='[26,608][540,702]']").click()
        self.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Authorize']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.TextView[@text='Menu']").click()
        time.sleep(5)
        self.driver.swipe(373, 1221, 373, 614)
        time.sleep(10)
        self.driver.tap([(515, 1025)])
        time.sleep(5)
        self.driver.find_element_by_xpath("//android.widget.EditText[@text='Search']").send_keys("Chokoria")

    def tearDown(self):
        self.driver.quit()


if __name__ == '__main__':
    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='D:\\smoke_test.html', report_name='Ver 2.2.0', report_title='SPP V2 Smoke Test Result', verbosity=2))
