From ec910ebd49ea691912f3aaedb8eebd36b778ebea Mon Sep 17 00:00:00 2001 From: haricharan-jaka Date: Wed, 10 Aug 2022 17:40:26 +0530 Subject: [PATCH] Added logger msgs in the Android tests client_connect code Signed-off-by: haricharan-jaka --- libs/perfecto_interop/ios_tests.py | 74 ++++++++++++------------------ 1 file changed, 30 insertions(+), 44 deletions(-) diff --git a/libs/perfecto_interop/ios_tests.py b/libs/perfecto_interop/ios_tests.py index 2c7dbe616..96f634fb2 100644 --- a/libs/perfecto_interop/ios_tests.py +++ b/libs/perfecto_interop/ios_tests.py @@ -1,3 +1,4 @@ +import logging from ast import Str from logging import exception import unittest @@ -17,7 +18,6 @@ import allure from ios_libs import ios_libs class ios_tests(ios_libs): - ios_devices = { "iPhone-11": { "model-iOS": "iPhone-11", @@ -62,6 +62,7 @@ class ios_tests(ios_libs): report.step_start("Set Wifi Network to " + WifiName) # Open Settings Application + logging.info("Opening IOS setting APP") self.openApp(self.connData["bundleId-iOS-Settings"], self.setup_perfectoMobile[0]) try: @@ -74,6 +75,7 @@ class ios_tests(ios_libs): element.click() except NoSuchElementException: print("Exception: Verify Xpath - unable to click on Wifi") + logging.error("Exception: Verify Xpath - unable to click on Wifi") time.sleep(2) driver.implicitly_wait(4) @@ -95,9 +97,11 @@ class ios_tests(ios_libs): get_wifi_switch_element_text = get_wifi_switch_element.text except: print("Switch is OFF") + logging.info("Wifi Switch is OFF") if get_wifi_switch_element_text == "1" or get_wifi_switch_element_text == 1: print("WIFI Switch is ON") + logging.info("Wifi Switch is ON") break else: try: @@ -106,24 +110,30 @@ class ios_tests(ios_libs): get_wifi_switch_element_text = get_wifi_switch_element.text except: print("WIFi switch is ON") + logging.info("Wifi Switch is ON") if (get_wifi_switch_element_text == "0" or get_wifi_switch_element_text == 0): print("switch is still OFF") + logging.error("Wifi Switch is OFF") self.closeApp(self.connData["bundleId-iOS-Settings"], self.setup_perfectoMobile[0]) self.teardown() return ip_address_element_text, is_internet else: print("Switch is Still OFF") + logging.error("Wifi Switch is OFF") self.closeApp(self.connData["bundleId-iOS-Settings"], self.setup_perfectoMobile[0]) self.teardown() return ip_address_element_text, is_internet except: print("No switch element found") + logging.error("No switch element found") except: print("get_wifi_switch_element is ON") + logging.warning("get_wifi_switch_element is ON") # --------------------To Turn on WIFi Switch if already OFF-------------------------------- except: print("Cannot find WIFI element") + logging.error("Cannot find WIFI element") self.closeApp(self.connData["bundleId-iOS-Settings"], self.setup_perfectoMobile[0]) self.teardown() return ip_address_element_text, is_internet @@ -135,16 +145,19 @@ class ios_tests(ios_libs): time.sleep(4) print("getting in to Additional details") report.step_start("Clicking More Info") + logging.info("getting in to Additional details") additional_details_element = driver.find_element_by_xpath( "//*[@label='selected']/parent::*/parent::*/XCUIElementTypeButton[@label='More Info']") additional_details_element.click() try: time.sleep(2) print("Forget Connected Network") + logging.info("Forget Connected Network") forget_ssid = WebDriverWait(driver, 30).until( EC.presence_of_element_located((MobileBy.XPATH, "//*[@label='Forget This Network']"))) forget_ssid.click() print("Forget old ssid") + logging.info("Forget old ssid") try: time.sleep(2) report.step_start("Forget SSID popup1") @@ -157,8 +170,10 @@ class ios_tests(ios_libs): print("Forget SSID popup not found") except: print("couldn't find forget ssid element") + logging.warning("couldn't find forget ssid element") except: print("No connected SSID") + logging.info("No connected SSID") try: report.step_start("Unexpected Captive Popup") print("Unexpeceted Captive Poped Up") @@ -232,6 +247,7 @@ class ios_tests(ios_libs): break except: print("SSID unable to select") + logging.error("Unable to select SSID") report.step_start("Selecting Unable SSID To Connect") self.closeApp(self.connData["bundleId-iOS-Settings"], self.setup_perfectoMobile[0]) self.teardown() @@ -239,6 +255,7 @@ class ios_tests(ios_libs): except: print("couldn't connect to " + WifiName) + logging.error("Couldn't Select ssid") # request.config.cache.set(key="SelectingWifiFailed", value=str(e)) self.closeApp(self.connData["bundleId-iOS-Settings"], self.setup_perfectoMobile[0]) self.teardown() @@ -247,6 +264,7 @@ class ios_tests(ios_libs): if not ssid_found: print("could not found " + WifiName + " in device") + logging.error("Couldn't Find ssid in device") self.closeApp(self.connData["bundleId-iOS-Settings"], self.setup_perfectoMobile[0]) self.teardown() return ip_address_element_text, is_internet @@ -266,6 +284,7 @@ class ios_tests(ios_libs): wifiPassword.send_keys(WifiPass) except NoSuchElementException: print("Enter Password Page Not Loaded") + logging.warning("Enter Password Page Not Loaded") # ---------------------Set Password------------------------------- # ---------------------Click on join------------------------------- @@ -277,6 +296,7 @@ class ios_tests(ios_libs): joinBTN.click() except Exception as e: print("Join Button Not Enabled...Password may not be needed") + logging.warning("Join Button Not Enabled...Password may not be needed") # ---------------------Click on join------------------------------- # ---------------------check if internet------------------------------- @@ -310,15 +330,17 @@ class ios_tests(ios_libs): print(ssidname_text) if (ssidname_text == WifiName): print("SSID Matched") + logging.info("SSID Matched") allure.attach(name="SSID Matched ", body=str(WifiName)) else: print("SSID Not Matched") + logging.info("SSID Not Matched") allure.attach(name="SSID Not Matched ", body=str(WifiName)) reportFlag = False assert reportFlag except: print("SSID is not Checked in more Info") - + logging.warning("SSID is not Checked in more Info") try: report.step_start("Checking WiFi Address") print("Checking WIFI address") @@ -329,10 +351,12 @@ class ios_tests(ios_libs): allure.attach(name="Connected SSID WiFi-Address: ", body=str(wifi_address_element_text)) except Exception as e: print("WiFi-Address not Found") + logging.warning("WiFi-Address not Found") try: time.sleep(4) report.step_start("Checking IP Address") print("Checking IP address") + logging.info("Checking IP address") # (//*[@label="IP Address"]/parent::*/XCUIElementTypeStaticText)[2] ip_address_element_text = driver.find_element_by_xpath( "(//*[@label='IP Address']/parent::*/XCUIElementTypeStaticText)[2]").text @@ -347,7 +371,7 @@ class ios_tests(ios_libs): print("ip_address_element_text: ", ip_address_element_text) except: print("IP Address not Found") - + logging.info("IP Address not Found") try: report.step_start("Forget Network") forget_ssid = WebDriverWait(driver, 30).until( @@ -363,51 +387,13 @@ class ios_tests(ios_libs): forget_ssid_popup.click() except: print("in popup exception") - + logging.warning("in popup exception") except: print("error on ssid element") - - # --------------------To Turn on WIFi Switch if already OFF-------------------------------- - # try: - # get_wifi_switch_element = driver.find_element_by_xpath("//*[@label='Wi-Fi' and @value='1']") - # get_wifi_switch_element_text = get_wifi_switch_element.text - # print("switch state is : ", get_wifi_switch_element_text) - # try: - # if get_wifi_switch_element_text == "1" or get_wifi_switch_element_text == 1: - # get_wifi_switch_element = driver.find_element_by_xpath("//*[@label='Wi-Fi' and @value='1']") - # driver.implicitly_wait(1) - # get_wifi_switch_element.click() - # driver.implicitly_wait(1) - # i = 0 - # for i in range(5): - # try: - # get_wifi_switch_element = driver.find_element_by_xpath("//*[@label='Wi-Fi' and @value='0']") - # get_wifi_switch_element_text = get_wifi_switch_element.text - # except: - # print("switch is ON") - # - # if get_wifi_switch_element_text == "0" or get_wifi_switch_element_text == 0: - # print("WIFI Switch is OFF") - # break - # else: - # try: - # get_wifi_switch_element = driver.find_element_by_xpath( - # "//*[@label='Wi-Fi' and @value='1']") - # get_wifi_switch_element.click() - # get_wifi_switch_element_text = get_wifi_switch_element.text - # except: - # print("WIFi switch is OFF") - # - # else: - # print("Switch is Still OFF") - # except: - # pass - # except: - # print("get_wifi_switch_element is ON") - # --------------------To Turn on WIFi Switch if already OFF-------------------------------- - + logging.warning("error on ssid element") except Exception as e: print("Select Additional Info failed") + logging.warning("Select Additional Info failed") # ---------------------Additional INFO------------------------------- # --------------------- close app-------------------------------