diff --git a/libs/perfecto_libs/android_lib.py b/libs/perfecto_libs/android_lib.py index dd3d978c8..a03923559 100644 --- a/libs/perfecto_libs/android_lib.py +++ b/libs/perfecto_libs/android_lib.py @@ -5504,98 +5504,277 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf check_if_no_internet_popup(driver) # ------------------------------------------------------- - #Verify if WiFi is connected + # Verify if WiFi is connected # ------------------------------------------------------- - try: - report.step_start("Verify if Wifi is Connected") - WifiInternetErrMsg = WebDriverWait(driver, 35).until( - EC.presence_of_element_located((MobileBy.XPATH, - "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) - ssid_with_internet = True - print("Wifi Successfully Connected") - # time.sleep(5) - check_if_no_internet_popup(driver) - except: + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, + search_this="osVersion") != "12": try: - check_if_no_internet_popup(driver) + report.step_start("Verify if Wifi is Connected") WifiInternetErrMsg = WebDriverWait(driver, 35).until( EC.presence_of_element_located((MobileBy.XPATH, - "//*[@resource-id='com.android.settings:id/summary' and @text='Connected without internet']/parent::*/android.widget.TextView[@text='" - + WifiName + "']"))) - print("Wifi Successfully Connected without internet") + "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + # time.sleep(5) check_if_no_internet_popup(driver) except: try: - report.step_start("Verify if Wifi is Connected") - WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( - MobileBy.XPATH, - "//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) - ssid_with_internet = True - print("Wifi Successfully Connected") - except NoSuchElementException: - print("Wifi Connection Error: " + WifiName) + check_if_no_internet_popup(driver) + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/summary' and @text='Connected without internet']/parent::*/android.widget.TextView[@text='" + + WifiName + "']"))) + print("Wifi Successfully Connected without internet") + check_if_no_internet_popup(driver) + except: + try: + report.step_start("Verify if Wifi is Connected - 2") + WifiInternetErrMsg = WebDriverWait(driver, 60).until( + EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + except NoSuchElementException: + print("Wifi Connection Error: " + WifiName) + closeApp(connData["appPackage-android"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + else: + try: + report.step_start("Verifying wifi connection status connected/connected without internet") + check_if_no_internet_popup(driver) + check_if_no_internet_popup(driver) + + wifi_connection_name = WebDriverWait(driver, 50).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/connected_list']/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]/android.widget.TextView[1]" + ))) + if wifi_connection_name.text == WifiName: + wifi_connection_status = WebDriverWait(driver, 50).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/summary']" + ))) + if wifi_connection_status.text == "Connected": + ssid_with_internet = True + print("Connected with internet") + + else: + ssid_with_internet = False + print("Wifi Successfully Connected without internet") + check_if_no_internet_popup(driver) + # Go into additional details here + else: + # Connected to some other wifi, makes sense to close app and fail this testcase closeApp(connData["appPackage-android"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet + except: + closeApp(connData["appPackage-android"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- - #Get into Additional Details - #To Get an IP Address - #To Forget connection - #To turn off auto. connect + # Get into Additional Details + # To Get an IP Address + # To Forget connection + # To turn off auto. connect # ------------------------------------------------------- - try: - print("Into additional details") - time.sleep(2) - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") - additional_details_element.click() + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, + search_this="osVersion") != "12": try: + print("Into additional details") time.sleep(2) - ip_address_element = driver.find_element_by_xpath( - "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='com.android.settings:id/summary']") - ip_address_element_text = ip_address_element.text - print("Device IP address is :", ip_address_element_text) - except: + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/layout_details']") + additional_details_element.click() try: time.sleep(2) ip_address_element = driver.find_element_by_xpath( - "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='android:id/summary']") + "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='com.android.settings:id/summary']") ip_address_element_text = ip_address_element.text print("Device IP address is :", ip_address_element_text) except: - print("IP address element not found") - #allure.attach(name= body=str("IP address element not found")) - - # closeApp(connData["appPackage-android"], setup_perfectoMobile) - # return ip_address_element_text, ssid_with_internet - - try: - check_if_no_internet_popup(driver) - driver.implicitly_wait(3) - time.sleep(2) - auto_reconnect_off = driver.find("//*[@resource-id='android:id/switch_widget']") - auto_reconnect_off_text = auto_reconnect_off.text - if auto_reconnect_off_text != "On": - auto_reconnect_off.click() - print("Auto reconnect turning on") + try: + time.sleep(2) + ip_address_element = driver.find_element_by_xpath( + "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='android:id/summary']") + ip_address_element_text = ip_address_element.text + print("Device IP address is :", ip_address_element_text) + except: + print("IP address element not found") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + assert False + # allure.attach(name= body=str("IP address element not found")) + # --------------------Added for ssid security check-------------------------- + try: + time.sleep(2) + security_name_element = driver.find_element_by_xpath( + "//*[@text='Security']/parent::*/android.widget.TextView[@resource-id='com.android.settings:id/summary']") + security_name_element_text = security_name_element.text + print("Ssid security is :", security_name_element_text) + allure.attach(name="Ssid Security:", body=str(security_name_element_text)) + except: + print("Security is not available") + # --------------------Added for ssid Name check-------------------------- + try: + time.sleep(2) + ssid_name_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/entity_header_title']") + ssid_name_element_text = ssid_name_element.text + print("Ssid Name is :", ssid_name_element_text) + allure.attach(name="Ssid connected:", body=str(ssid_name_element_text)) + except: + print("Ssid name not available") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + assert False + if (ssid_name_element_text == WifiName): + print("Wifi is connected to the expected ssid") else: - print("Auto reconnect is already on") + print("Wifi is not connected to the expected ssid") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + assert False + try: + check_if_no_internet_popup(driver) + driver.implicitly_wait(3) + time.sleep(2) + auto_reconnect_off = driver.find("//*[@resource-id='android:id/switch_widget']") + auto_reconnect_off_text = auto_reconnect_off.text + if auto_reconnect_off_text != "Off": + auto_reconnect_off.click() + print("Auto reconnect turning off") + else: + print("Auto reconnect is already off") + except: + print("Couldn't find auto reconnect element") + + # ------------------------------- Forget SSID ---------------- + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/forget_button']//*[@resource-id='com.android.settings:id/icon']") + forget_ssid.click() + print("Forgetting ssid") + + # ------------------------------- Wifi Switch ---------------- + # try: + # print("clicking on wifi switch") + # get_switch_element = driver.find_element_by_xpath( + # "//*[@resource-id='com.android.settings:id/switch_widget']") + # driver.implicitly_wait(2) + # get_switch_element.click() + # except: + # print("couldn't click on wifi switch") + # #allure.attach(name= body=str("couldn't click on wifi switch")) + except: + print("Couldn't forget ssid") + # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet except: - print("Couldn't find auto reconnect element") - except: - print("Couldn't get into Additional settings") + print("Couldn't get into Additional settings") + # ------------------------------------------------------- + else: + try: + print("Into additional details") + time.sleep(2) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/wifi_details']") + additional_details_element.click() + + try: + print("click on view more") + additional_details_element = WebDriverWait(driver, 50).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='View more']"))) + additional_details_element.click() + except: + pass + + try: + time.sleep(2) + ssid_name_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/entity_header_title']") + ssid_name_element_text = ssid_name_element.text + print("Ssid Name is :", ssid_name_element_text) + allure.attach(name="Ssid connected:", body=str(ssid_name_element_text)) + except: + print("Ssid name not available") + pass + + if (ssid_name_element_text == WifiName): + print("Wifi is connected to the expected ssid") + ip_address_element_text = "SSID Match, S20 Does Not support scrolling" + ssid_with_internet = "SSID Match, S20 Does Not support scrolling" + # return ip_address_element_text, ssid_with_internet + else: + print("Wifi is not connected to the expected ssid") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + + report.step_start("Scrolling for ip address - 1") + # if deviceModelName == "Galaxy S20": + # print("Scrolling for S20") + driver.swipe(470, 1400, 470, 1000, 400) + # else: + # scrollDown(setup_perfectoMobile) + + report.step_start("Scrolling for ip address - 2") + # if deviceModelName == "Galaxy S20": + # print("Scrolling for S20") + driver.swipe(470, 1400, 470, 1000, 400) + # else: + # scrollDown(setup_perfectoMobile) + + report.step_start("Scrolling for ip address - 3") + # if deviceModelName == "Galaxy S20": + # print("Scrolling for S20") + driver.swipe(470, 1400, 470, 1000, 400) + # else: + # scrollDown(setup_perfectoMobile) + report.step_start("looking for ip address") + + try: + ip_address_element_text = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.LinearLayout[4]/android.widget.RelativeLayout[1]/android.widget.TextView[2]") + ip_address_element_text = ip_address_element_text.text + ssid_with_internet = True + except: + print("Unable to get IP address") + pass + + # report.step_start("Forget SSID") + # + # try: + # check_if_no_internet_popup(driver) + # forget_ssid = driver.find_element_by_xpath( + # "//*[@text='Forget']") + # forget_ssid.click() + # print("Forgetting ssid") + # + # # ------------------------------- Wifi Switch ---------------- + # # try: + # # print("clicking on wifi switch") + # # get_switch_element = driver.find_element_by_xpath( + # # "//*[@resource-id='com.android.settings:id/switch_widget']") + # # driver.implicitly_wait(2) + # # get_switch_element.click() + # # except: + # # print("couldn't click on wifi switch") + # # #allure.attach(name= body=str("couldn't click on wifi switch")) + # except: + # print("Couldn't forget ssid") + # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into Additional settings") + # ------------------------------------------------------- + # ------------------------------------------------------- except: print("No Switch element found") - # ---------------------To Turn on WIFi Switch if already OFF------------------------------- + # ---------------------To Turn on WIFi Switch if already OFF------------------------------- except: print("Couldn't find wifi Button") - # ------------------Open WIFI page---------------------------------- + # ------------------Open WIFI page---------------------------------- except: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") - # -----------------To Open Connections page--------------------------- #--------------------Pixel 4 code--------------------------- else: report.step_start("Set Wifi Network to " + WifiName) @@ -6122,98 +6301,277 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw check_if_no_internet_popup(driver) # ------------------------------------------------------- - #Verify if WiFi is connected + # Verify if WiFi is connected # ------------------------------------------------------- - try: - report.step_start("Verify if Wifi is Connected") - WifiInternetErrMsg = WebDriverWait(driver, 35).until( - EC.presence_of_element_located((MobileBy.XPATH, - "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) - ssid_with_internet = True - print("Wifi Successfully Connected") - # time.sleep(5) - check_if_no_internet_popup(driver) - except: + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, + search_this="osVersion") != "12": try: - check_if_no_internet_popup(driver) + report.step_start("Verify if Wifi is Connected") WifiInternetErrMsg = WebDriverWait(driver, 35).until( EC.presence_of_element_located((MobileBy.XPATH, - "//*[@resource-id='com.android.settings:id/summary' and @text='Connected without internet']/parent::*/android.widget.TextView[@text='" - + WifiName + "']"))) - print("Wifi Successfully Connected without internet") + "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + # time.sleep(5) check_if_no_internet_popup(driver) except: try: - report.step_start("Verify if Wifi is Connected") - WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( - MobileBy.XPATH, - "//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) - ssid_with_internet = True - print("Wifi Successfully Connected") - except NoSuchElementException: - print("Wifi Connection Error: " + WifiName) + check_if_no_internet_popup(driver) + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/summary' and @text='Connected without internet']/parent::*/android.widget.TextView[@text='" + + WifiName + "']"))) + print("Wifi Successfully Connected without internet") + check_if_no_internet_popup(driver) + except: + try: + report.step_start("Verify if Wifi is Connected - 2") + WifiInternetErrMsg = WebDriverWait(driver, 60).until( + EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + except NoSuchElementException: + print("Wifi Connection Error: " + WifiName) + closeApp(connData["appPackage-android"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + else: + try: + report.step_start("Verifying wifi connection status connected/connected without internet") + check_if_no_internet_popup(driver) + check_if_no_internet_popup(driver) + + wifi_connection_name = WebDriverWait(driver, 50).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/connected_list']/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]/android.widget.TextView[1]" + ))) + if wifi_connection_name.text == WifiName: + wifi_connection_status = WebDriverWait(driver, 50).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/summary']" + ))) + if wifi_connection_status.text == "Connected": + ssid_with_internet = True + print("Connected with internet") + + else: + ssid_with_internet = False + print("Wifi Successfully Connected without internet") + check_if_no_internet_popup(driver) + # Go into additional details here + else: + # Connected to some other wifi, makes sense to close app and fail this testcase closeApp(connData["appPackage-android"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet + except: + closeApp(connData["appPackage-android"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- - #Get into Additional Details - #To Get an IP Address - #To Forget connection - #To turn off auto. connect + # Get into Additional Details + # To Get an IP Address + # To Forget connection + # To turn off auto. connect # ------------------------------------------------------- - try: - print("Into additional details") - time.sleep(2) - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") - additional_details_element.click() + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, + search_this="osVersion") != "12": try: + print("Into additional details") time.sleep(2) - ip_address_element = driver.find_element_by_xpath( - "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='com.android.settings:id/summary']") - ip_address_element_text = ip_address_element.text - print("Device IP address is :", ip_address_element_text) - except: + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/layout_details']") + additional_details_element.click() try: time.sleep(2) ip_address_element = driver.find_element_by_xpath( - "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='android:id/summary']") + "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='com.android.settings:id/summary']") ip_address_element_text = ip_address_element.text print("Device IP address is :", ip_address_element_text) except: - print("IP address element not found") - #allure.attach(name= body=str("IP address element not found")) - - # closeApp(connData["appPackage-android"], setup_perfectoMobile) - # return ip_address_element_text, ssid_with_internet - - try: - check_if_no_internet_popup(driver) - driver.implicitly_wait(3) - time.sleep(2) - auto_reconnect_off = driver.find("//*[@resource-id='android:id/switch_widget']") - auto_reconnect_off_text = auto_reconnect_off.text - if auto_reconnect_off_text != "On": - auto_reconnect_off.click() - print("Auto reconnect turning on") + try: + time.sleep(2) + ip_address_element = driver.find_element_by_xpath( + "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='android:id/summary']") + ip_address_element_text = ip_address_element.text + print("Device IP address is :", ip_address_element_text) + except: + print("IP address element not found") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + assert False + # allure.attach(name= body=str("IP address element not found")) + # --------------------Added for ssid security check-------------------------- + try: + time.sleep(2) + security_name_element = driver.find_element_by_xpath( + "//*[@text='Security']/parent::*/android.widget.TextView[@resource-id='com.android.settings:id/summary']") + security_name_element_text = security_name_element.text + print("Ssid security is :", security_name_element_text) + allure.attach(name="Ssid Security:", body=str(security_name_element_text)) + except: + print("Security is not available") + # --------------------Added for ssid Name check-------------------------- + try: + time.sleep(2) + ssid_name_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/entity_header_title']") + ssid_name_element_text = ssid_name_element.text + print("Ssid Name is :", ssid_name_element_text) + allure.attach(name="Ssid connected:", body=str(ssid_name_element_text)) + except: + print("Ssid name not available") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + assert False + if (ssid_name_element_text == WifiName): + print("Wifi is connected to the expected ssid") else: - print("Auto reconnect is already on") + print("Wifi is not connected to the expected ssid") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + assert False + try: + check_if_no_internet_popup(driver) + driver.implicitly_wait(3) + time.sleep(2) + auto_reconnect_off = driver.find("//*[@resource-id='android:id/switch_widget']") + auto_reconnect_off_text = auto_reconnect_off.text + if auto_reconnect_off_text != "Off": + auto_reconnect_off.click() + print("Auto reconnect turning off") + else: + print("Auto reconnect is already off") + except: + print("Couldn't find auto reconnect element") + + # ------------------------------- Forget SSID ---------------- + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/forget_button']//*[@resource-id='com.android.settings:id/icon']") + forget_ssid.click() + print("Forgetting ssid") + + # ------------------------------- Wifi Switch ---------------- + # try: + # print("clicking on wifi switch") + # get_switch_element = driver.find_element_by_xpath( + # "//*[@resource-id='com.android.settings:id/switch_widget']") + # driver.implicitly_wait(2) + # get_switch_element.click() + # except: + # print("couldn't click on wifi switch") + # #allure.attach(name= body=str("couldn't click on wifi switch")) + except: + print("Couldn't forget ssid") + # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet except: - print("Couldn't find auto reconnect element") - except: - print("Couldn't get into Additional settings") + print("Couldn't get into Additional settings") + # ------------------------------------------------------- + else: + try: + print("Into additional details") + time.sleep(2) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/wifi_details']") + additional_details_element.click() + + try: + print("click on view more") + additional_details_element = WebDriverWait(driver, 50).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='View more']"))) + additional_details_element.click() + except: + pass + + try: + time.sleep(2) + ssid_name_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/entity_header_title']") + ssid_name_element_text = ssid_name_element.text + print("Ssid Name is :", ssid_name_element_text) + allure.attach(name="Ssid connected:", body=str(ssid_name_element_text)) + except: + print("Ssid name not available") + pass + + if (ssid_name_element_text == WifiName): + print("Wifi is connected to the expected ssid") + ip_address_element_text = "SSID Match, S20 Does Not support scrolling" + ssid_with_internet = "SSID Match, S20 Does Not support scrolling" + # return ip_address_element_text, ssid_with_internet + else: + print("Wifi is not connected to the expected ssid") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + + report.step_start("Scrolling for ip address - 1") + # if deviceModelName == "Galaxy S20": + # print("Scrolling for S20") + driver.swipe(470, 1400, 470, 1000, 400) + # else: + # scrollDown(setup_perfectoMobile) + + report.step_start("Scrolling for ip address - 2") + # if deviceModelName == "Galaxy S20": + # print("Scrolling for S20") + driver.swipe(470, 1400, 470, 1000, 400) + # else: + # scrollDown(setup_perfectoMobile) + + report.step_start("Scrolling for ip address - 3") + # if deviceModelName == "Galaxy S20": + # print("Scrolling for S20") + driver.swipe(470, 1400, 470, 1000, 400) + # else: + # scrollDown(setup_perfectoMobile) + report.step_start("looking for ip address") + + try: + ip_address_element_text = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.LinearLayout[4]/android.widget.RelativeLayout[1]/android.widget.TextView[2]") + ip_address_element_text = ip_address_element_text.text + ssid_with_internet = True + except: + print("Unable to get IP address") + pass + + # report.step_start("Forget SSID") + # + # try: + # check_if_no_internet_popup(driver) + # forget_ssid = driver.find_element_by_xpath( + # "//*[@text='Forget']") + # forget_ssid.click() + # print("Forgetting ssid") + # + # # ------------------------------- Wifi Switch ---------------- + # # try: + # # print("clicking on wifi switch") + # # get_switch_element = driver.find_element_by_xpath( + # # "//*[@resource-id='com.android.settings:id/switch_widget']") + # # driver.implicitly_wait(2) + # # get_switch_element.click() + # # except: + # # print("couldn't click on wifi switch") + # # #allure.attach(name= body=str("couldn't click on wifi switch")) + # except: + # print("Couldn't forget ssid") + # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into Additional settings") + # ------------------------------------------------------- + # ------------------------------------------------------- except: print("No Switch element found") - # ---------------------To Turn on WIFi Switch if already OFF------------------------------- + # ---------------------To Turn on WIFi Switch if already OFF------------------------------- except: print("Couldn't find wifi Button") - # ------------------Open WIFI page---------------------------------- + # ------------------Open WIFI page---------------------------------- except: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") - # -----------------To Open Connections page--------------------------- else: #--------------------Pixel code----------------------------------- report.step_start("Set Wifi Network to " + WifiName) @@ -6637,119 +6995,275 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup closeApp(connData["appPackage-android"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- - try: - report.step_start("Verify if Wifi is Connected") - WifiInternetErrMsg = WebDriverWait(driver, 35).until( - EC.presence_of_element_located((MobileBy.XPATH, - "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) - ssid_with_internet = True - print("Wifi Successfully Connected") - # time.sleep(5) - check_if_no_internet_popup(driver) - except: + # Verify if WiFi is connected + # ------------------------------------------------------- + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, + search_this="osVersion") != "12": try: - check_if_no_internet_popup(driver) + report.step_start("Verify if Wifi is Connected") WifiInternetErrMsg = WebDriverWait(driver, 35).until( EC.presence_of_element_located((MobileBy.XPATH, - "//*[@resource-id='com.android.settings:id/summary' and @text='Connected without internet']/parent::*/android.widget.TextView[@text='" - + WifiName + "']"))) - print("Wifi Successfully Connected without internet") + "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + # time.sleep(5) check_if_no_internet_popup(driver) except: try: - report.step_start("Verify if Wifi is Connected") - WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( - MobileBy.XPATH, - "//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) - ssid_with_internet = True - print("Wifi Successfully Connected") - except NoSuchElementException: - print("Wifi Connection Error: " + WifiName) + check_if_no_internet_popup(driver) + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/summary' and @text='Connected without internet']/parent::*/android.widget.TextView[@text='" + + WifiName + "']"))) + print("Wifi Successfully Connected without internet") + check_if_no_internet_popup(driver) + except: + try: + report.step_start("Verify if Wifi is Connected - 2") + WifiInternetErrMsg = WebDriverWait(driver, 60).until( + EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + except NoSuchElementException: + print("Wifi Connection Error: " + WifiName) + closeApp(connData["appPackage-android"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + else: + try: + report.step_start( + "Verifying wifi connection status connected/connected without internet") + check_if_no_internet_popup(driver) + check_if_no_internet_popup(driver) + + wifi_connection_name = WebDriverWait(driver, 50).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/connected_list']/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]/android.widget.TextView[1]" + ))) + if wifi_connection_name.text == WifiName: + wifi_connection_status = WebDriverWait(driver, 50).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android.settings:id/summary']" + ))) + if wifi_connection_status.text == "Connected": + ssid_with_internet = True + print("Connected with internet") + + else: + ssid_with_internet = False + print("Wifi Successfully Connected without internet") + check_if_no_internet_popup(driver) + # Go into additional details here + else: + # Connected to some other wifi, makes sense to close app and fail this testcase closeApp(connData["appPackage-android"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet + except: + closeApp(connData["appPackage-android"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- - #Get into Additional Details - #To Get an IP Address - #To Forget connection - #To turn off auto. connect + # Get into Additional Details + # To Get an IP Address + # To Forget connection + # To turn off auto. connect # ------------------------------------------------------- - try: - print("Into additional details") - time.sleep(2) - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") - additional_details_element.click() + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, + search_this="osVersion") != "12": try: + print("Into additional details") time.sleep(2) - ip_address_element = driver.find_element_by_xpath( - "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='com.android.settings:id/summary']") - ip_address_element_text = ip_address_element.text - print("Device IP address is :", ip_address_element_text) - except: + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/layout_details']") + additional_details_element.click() try: time.sleep(2) ip_address_element = driver.find_element_by_xpath( - "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='android:id/summary']") + "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='com.android.settings:id/summary']") ip_address_element_text = ip_address_element.text print("Device IP address is :", ip_address_element_text) except: - print("IP address element not found") - #allure.attach(name= body=str("IP address element not found")) - - # closeApp(connData["appPackage-android"], setup_perfectoMobile) - # return ip_address_element_text, ssid_with_internet - - try: - check_if_no_internet_popup(driver) - driver.implicitly_wait(3) - time.sleep(2) - auto_reconnect_off = driver.find("//*[@resource-id='android:id/switch_widget']") - auto_reconnect_off_text = auto_reconnect_off.text - if auto_reconnect_off_text != "Off": - auto_reconnect_off.click() - print("Auto reconnect turning off") + try: + time.sleep(2) + ip_address_element = driver.find_element_by_xpath( + "//*[@text='IP address']/parent::*/android.widget.TextView[@resource-id='android:id/summary']") + ip_address_element_text = ip_address_element.text + print("Device IP address is :", ip_address_element_text) + except: + print("IP address element not found") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + assert False + # allure.attach(name= body=str("IP address element not found")) + # --------------------Added for ssid security check-------------------------- + try: + time.sleep(2) + security_name_element = driver.find_element_by_xpath( + "//*[@text='Security']/parent::*/android.widget.TextView[@resource-id='com.android.settings:id/summary']") + security_name_element_text = security_name_element.text + print("Ssid security is :", security_name_element_text) + allure.attach(name="Ssid Security:", body=str(security_name_element_text)) + except: + print("Security is not available") + # --------------------Added for ssid Name check-------------------------- + try: + time.sleep(2) + ssid_name_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/entity_header_title']") + ssid_name_element_text = ssid_name_element.text + print("Ssid Name is :", ssid_name_element_text) + allure.attach(name="Ssid connected:", body=str(ssid_name_element_text)) + except: + print("Ssid name not available") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + assert False + if (ssid_name_element_text == WifiName): + print("Wifi is connected to the expected ssid") else: - print("Auto reconnect is already off") - except: - print("Couldn't find auto reconnect element") + print("Wifi is not connected to the expected ssid") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + assert False + try: + check_if_no_internet_popup(driver) + driver.implicitly_wait(3) + time.sleep(2) + auto_reconnect_off = driver.find("//*[@resource-id='android:id/switch_widget']") + auto_reconnect_off_text = auto_reconnect_off.text + if auto_reconnect_off_text != "Off": + auto_reconnect_off.click() + print("Auto reconnect turning off") + else: + print("Auto reconnect is already off") + except: + print("Couldn't find auto reconnect element") - # ------------------------------- Forget SSID ---------------- + # ------------------------------- Forget SSID ---------------- + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/forget_button']//*[@resource-id='com.android.settings:id/icon']") + forget_ssid.click() + print("Forgetting ssid") + + # ------------------------------- Wifi Switch ---------------- + # try: + # print("clicking on wifi switch") + # get_switch_element = driver.find_element_by_xpath( + # "//*[@resource-id='com.android.settings:id/switch_widget']") + # driver.implicitly_wait(2) + # get_switch_element.click() + # except: + # print("couldn't click on wifi switch") + # #allure.attach(name= body=str("couldn't click on wifi switch")) + except: + print("Couldn't forget ssid") + # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into Additional settings") + # ------------------------------------------------------- + else: try: - check_if_no_internet_popup(driver) - forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/forget_button']//*[@resource-id='com.android.settings:id/icon']") - forget_ssid.click() - print("Forgetting ssid") + print("Into additional details") + time.sleep(2) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/wifi_details']") + additional_details_element.click() - #------------------------------- Wifi Switch ---------------- - # try: - # print("clicking on wifi switch") - # get_switch_element = driver.find_element_by_xpath( - # "//*[@resource-id='com.android.settings:id/switch_widget']") - # driver.implicitly_wait(2) - # get_switch_element.click() - # except: - # print("couldn't click on wifi switch") - # #allure.attach(name= body=str("couldn't click on wifi switch")) + try: + print("click on view more") + additional_details_element = WebDriverWait(driver, 50).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='View more']"))) + additional_details_element.click() + except: + pass + + try: + time.sleep(2) + ssid_name_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/entity_header_title']") + ssid_name_element_text = ssid_name_element.text + print("Ssid Name is :", ssid_name_element_text) + allure.attach(name="Ssid connected:", body=str(ssid_name_element_text)) + except: + print("Ssid name not available") + pass + + if (ssid_name_element_text == WifiName): + print("Wifi is connected to the expected ssid") + ip_address_element_text = "SSID Match, S20 Does Not support scrolling" + ssid_with_internet = "SSID Match, S20 Does Not support scrolling" + # return ip_address_element_text, ssid_with_internet + else: + print("Wifi is not connected to the expected ssid") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + + report.step_start("Scrolling for ip address - 1") + # if deviceModelName == "Galaxy S20": + # print("Scrolling for S20") + driver.swipe(470, 1400, 470, 1000, 400) + # else: + # scrollDown(setup_perfectoMobile) + + report.step_start("Scrolling for ip address - 2") + # if deviceModelName == "Galaxy S20": + # print("Scrolling for S20") + driver.swipe(470, 1400, 470, 1000, 400) + # else: + # scrollDown(setup_perfectoMobile) + + report.step_start("Scrolling for ip address - 3") + # if deviceModelName == "Galaxy S20": + # print("Scrolling for S20") + driver.swipe(470, 1400, 470, 1000, 400) + # else: + # scrollDown(setup_perfectoMobile) + report.step_start("looking for ip address") + + try: + ip_address_element_text = driver.find_element_by_xpath( + "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.LinearLayout[4]/android.widget.RelativeLayout[1]/android.widget.TextView[2]") + ip_address_element_text = ip_address_element_text.text + ssid_with_internet = True + except: + print("Unable to get IP address") + pass + + report.step_start("Forget SSID") + + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@text='Forget']") + forget_ssid.click() + print("Forgetting ssid") + + # ------------------------------- Wifi Switch ---------------- + # try: + # print("clicking on wifi switch") + # get_switch_element = driver.find_element_by_xpath( + # "//*[@resource-id='com.android.settings:id/switch_widget']") + # driver.implicitly_wait(2) + # get_switch_element.click() + # except: + # print("couldn't click on wifi switch") + # #allure.attach(name= body=str("couldn't click on wifi switch")) + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet except: - print("Couldn't forget ssid") - # closeApp(connData["appPackage-android"], setup_perfectoMobile) - # return ip_address_element_text, ssid_with_internet - except: - print("Couldn't get into Additional settings") - # ------------------------------------------------------- + print("Couldn't get into Additional settings") + # ------------------------------------------------------- + except: - print("No Switch element found") - # ---------------------To Turn on WIFi Switch if already OFF------------------------------- - + print("Couldn't find wifi Button") + # ------------------Open WIFI page---------------------------------- except: - print("Couldn't find wifi Button") - # ------------------Open WIFI page---------------------------------- - + print("No Switch element found") + # ---------------------To Turn on WIFi Switch if already OFF------------------------------- except: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") - # -----------------To Open Connections page--------------------------- #--------------------Pixel 4 code--------------------------- else: report.step_start("Set Wifi Network to " + WifiName) diff --git a/libs/perfecto_libs/iOS_lib.py b/libs/perfecto_libs/iOS_lib.py index 590ed9bc2..f40e8f433 100644 --- a/libs/perfecto_libs/iOS_lib.py +++ b/libs/perfecto_libs/iOS_lib.py @@ -2690,22 +2690,30 @@ def gets_ip_add_and_does_not_forget_ssid_ios(request, WifiName, WifiPass, setup_ available_ssids = get_all_available_ssids(driver) allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) try: - if WifiName not in available_ssids: + if (not ssid_Visible(driver, WifiName)) or (WifiName not in available_ssids): scrollDown(setup_perfectoMobile) time.sleep(2) else: - report.step_start("Selecting SSID To Connect") - ssid_found = True - print(WifiName + " : Found in Device") - wifiSelElement = WebDriverWait(driver, 30).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@label='" + WifiName + "']"))) - print(wifiSelElement) - wifiSelElement.click() - print("Selecting SSID") - # allure.attach(name= body=str(WifiName + " : Found in Device")) - break + try: + driver.implicitly_wait(8) + report.step_start("Selecting SSID To Connect") + ssid_found = True + print(WifiName + " : Found in Device") + wifiSelElement = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@label='" + WifiName + "']"))) + print(wifiSelElement) + wifiSelElement.click() + print("Selecting SSID") + break + except: + print("SSID unable to select") + report.step_start("Selecting Unable SSID To Connect") + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + except: print("couldn't connect to " + WifiName) - #request.config.cache.set(key="SelectingWifiFailed", value=str(e)) + # request.config.cache.set(key="SelectingWifiFailed", value=str(e)) closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) return ip_address_element_text, is_internet pass @@ -2792,6 +2800,7 @@ def gets_ip_add_and_does_not_forget_ssid_ios(request, WifiName, WifiPass, setup_ except Exception as e: print("WiFi-Address not Found") try: + time.sleep(4) report.step_start("Checking IP Address") print("Checking IP address") # (//*[@label="IP Address"]/parent::*/XCUIElementTypeStaticText)[2] @@ -2799,8 +2808,16 @@ def gets_ip_add_and_does_not_forget_ssid_ios(request, WifiName, WifiPass, setup_ "(//*[@label='IP Address']/parent::*/XCUIElementTypeStaticText)[2]").text print("ip_address_element_text: ", ip_address_element_text) except Exception as e: - print("IP Address not Found") - request.config.cache.set(key="select IP failed", value=str(e)) + try: + time.sleep(4) + print("Scrolling for checking ip address") + scrollDown(setup_perfectoMobile) + ip_address_element_text = driver.find_element_by_xpath( + "(//*[@label='IP Address']/parent::*/XCUIElementTypeStaticText)[2]").text + print("ip_address_element_text: ", ip_address_element_text) + except: + print("IP Address not Found") + request.config.cache.set(key="select IP failed", value=str(e)) except Exception as e: request.config.cache.set(key="select additional info failed", value=str(e)) @@ -2935,20 +2952,26 @@ def gets_ip_add_eap_and_does_not_forget_ssid_ios(request, WifiName, User, ttls_p available_ssids = get_all_available_ssids(driver) allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) try: - if WifiName not in available_ssids: + if (not ssid_Visible(driver, WifiName)) or (WifiName not in available_ssids): scrollDown(setup_perfectoMobile) time.sleep(2) else: - report.step_start("Selecting SSID To Connect") - ssid_found = True - print(WifiName + " : Found in Device") - wifiSelElement = WebDriverWait(driver, 30).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@label='" + WifiName + "']"))) - print(wifiSelElement) - wifiSelElement.click() - print("Selecting SSID") - # allure.attach(name= body=str(WifiName + " : Found in Device")) - break + try: + driver.implicitly_wait(8) + report.step_start("Selecting SSID To Connect") + ssid_found = True + print(WifiName + " : Found in Device") + wifiSelElement = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@label='" + WifiName + "']"))) + print(wifiSelElement) + wifiSelElement.click() + print("Selecting SSID") + break + except: + print("SSID unable to select") + report.step_start("Selecting Unable SSID To Connect") + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet except: print("couldn't connect to " + WifiName) # request.config.cache.set(key="SelectingWifiFailed", value=str(e)) @@ -3058,17 +3081,24 @@ def gets_ip_add_eap_and_does_not_forget_ssid_ios(request, WifiName, User, ttls_p print("WiFi-Address not Found") allure.attach(name="No Connected SSID WiFi-Address Found") try: - driver.implicitly_wait(5) - print("Checking IP address") - report.step_start("Checking IP address") time.sleep(4) + report.step_start("Checking IP Address") + print("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 print("ip_address_element_text: ", ip_address_element_text) except Exception as e: - print("IP Address not Found") - request.config.cache.set(key="select IP failed", value=str(e)) + try: + time.sleep(4) + print("Scrolling for checking ip address") + scrollDown(setup_perfectoMobile) + ip_address_element_text = driver.find_element_by_xpath( + "(//*[@label='IP Address']/parent::*/XCUIElementTypeStaticText)[2]").text + print("ip_address_element_text: ", ip_address_element_text) + except: + print("IP Address not Found") + request.config.cache.set(key="select IP failed", value=str(e)) except Exception as e: request.config.cache.set(key="select additional info failed", value=str(e)) @@ -3201,6 +3231,7 @@ def gets_ip_add_for_checking_and_forgets_ssid_ios(request, WifiName, WifiPass, s except Exception as e: print("WiFi-Address not Found") try: + time.sleep(4) report.step_start("Checking IP Address") print("Checking IP address") # (//*[@label="IP Address"]/parent::*/XCUIElementTypeStaticText)[2] @@ -3208,9 +3239,16 @@ def gets_ip_add_for_checking_and_forgets_ssid_ios(request, WifiName, WifiPass, s "(//*[@label='IP Address']/parent::*/XCUIElementTypeStaticText)[2]").text print("ip_address_element_text: ", ip_address_element_text) except Exception as e: - print("IP Address not Found") - request.config.cache.set(key="select IP failed", value=str(e)) - + try: + time.sleep(4) + print("Scrolling for checking ip address") + scrollDown(setup_perfectoMobile) + ip_address_element_text = driver.find_element_by_xpath( + "(//*[@label='IP Address']/parent::*/XCUIElementTypeStaticText)[2]").text + print("ip_address_element_text: ", ip_address_element_text) + except: + print("IP Address not Found") + request.config.cache.set(key="select IP failed", value=str(e)) except Exception as e: request.config.cache.set(key="select additional info failed", value=str(e)) # ---------------------Additional INFO------------------------------- diff --git a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/toggle_airplane_mode_test/iOS/test_enterprise_ttls.py b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/toggle_airplane_mode_test/iOS/test_enterprise_ttls.py index 16e51a459..fef70e28d 100644 --- a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/toggle_airplane_mode_test/iOS/test_enterprise_ttls.py +++ b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/toggle_airplane_mode_test/iOS/test_enterprise_ttls.py @@ -85,7 +85,7 @@ class TestToggleAirplaneModeBridgeModeEnterpriseTTLSSuiteA(object): connData = get_ToggleAirplaneMode_data # Set Wifi/AP Mode - ip, is_internet = gets_ip_add_for_checking_and_forgets_ssid_ios(request, ssidName, identity, ttls_passwd, setup_perfectoMobile_iOS, connData) + ip, is_internet = gets_ip_add_eap_and_does_not_forget_ssid_ios(request, ssidName, identity, ttls_passwd, setup_perfectoMobile_iOS, connData) if is_internet: if ip: