diff --git a/libs/apnos/apnos.py b/libs/apnos/apnos.py index c4b389b2660..c68f0ee15e5 100644 --- a/libs/apnos/apnos.py +++ b/libs/apnos/apnos.py @@ -445,6 +445,46 @@ def get_wifi_status(self): print(e) return json_output + def set_maverick(self): + try: + client = self.ssh_cli_connect() + cmd = "/etc/init.d/ucentral stop && /usr/libexec/ucentral/maverick.sh" + if self.mode: + cmd = f"cd ~/cicd-git/ && ./openwrt_ctl.py {self.owrt_args} -t {self.tty} --action " \ + f"cmd --value \"{cmd}\" " + stdin, stdout, stderr = client.exec_command(cmd) + output = stdout.read().replace(b":~# /etc/init.d/ucentral stop && /usr/libexec/ucentral/maverick.sh", b"").decode('utf-8') + o = output.split() + maverick_bssid_data = {} + for i in range(len(o)): + if o[i].__contains__("ESSID"): + if o[i + 9].__contains__("2.4"): + band = "2G" + else: + band = "5G" + maverick_bssid_data[o[i - 1]] = [o[i + 1].replace('"', ''), o[i + 4], band] + client.close() + except Exception as e: + maverick_bssid_data = False + print(e) + return maverick_bssid_data + + # def imav(self, get_apnos, get_configuration): + # for access_point in get_configuration['access_point']: + # ap_ssh = get_apnos(access_point, pwd="../libs/apnos/", sdk="2.x") + # maverick = ap_ssh.set_maverick() + # print("maverick:") + # print(maverick) + # iwinfo = ap_ssh.get_iwinfo() + # print("iwinfo:") + # print(iwinfo) + # return iwinfo + # for key, value in iwinfo.items(): + # # print(key, ' : ',value) + # # print(value) + + + def get_iwinfo(self): try: # [['ssid_wpa2_2g', 'wpa', 'something', '2G'], ['ssid_wpa2_2g', 'wpa', 'something', '5G']] @@ -471,6 +511,7 @@ def get_iwinfo(self): print(e) return iwinfo_bssid_data + def iwinfo(self): client = self.ssh_cli_connect() cmd = "iwinfo" @@ -483,6 +524,20 @@ def iwinfo(self): client.close() return o + + # def set_maverick(self, get_configuration, get_apnos): + # client = self.ssh_cli_connect() + # cmd = "/etc/init.d/ucentral stop && /usr/libexec/ucentral/maverick.sh" + # if self.mode: + # cmd = f"cd ~/cicd-git/ && ./openwrt_ctl.py {self.owrt_args} -t {self.tty} --action " \ + # f"cmd --value \"{cmd}\" " + # stdin, stdout, stderr = client.exec_command(cmd) + # output = stdout.read().replace(b":~# /etc/init.d/ucentral stop && /usr/libexec/ucentral/maverick.sh ", b"").decode('utf-8') + # o = output + # client.close() + # return o + + def gettxpower(self): client = self.ssh_cli_connect() cmd = "iw dev | grep txpower" diff --git a/libs/perfecto_libs/android_lib.py b/libs/perfecto_libs/android_lib.py index a0392355971..6425c9fcc7b 100644 --- a/libs/perfecto_libs/android_lib.py +++ b/libs/perfecto_libs/android_lib.py @@ -21,6 +21,11 @@ from appium.webdriver.common.mobileby import MobileBy from selenium.webdriver.support import expected_conditions as EC from appium import webdriver +from selenium import webdriver +from selenium.common.exceptions import TimeoutException +from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0 +import time + import allure @@ -99,7 +104,7 @@ def set_APconnMobileDevice_android(request, WifiName, WifiPass, setup_perfectoMo driver.switch_to.context(contexts[0]) #Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print ("Selected Device Model: " + deviceModelName) @@ -119,14 +124,14 @@ def set_APconnMobileDevice_android(request, WifiName, WifiPass, setup_perfectoMo report.step_start("Get Connected Wifi Name if any") try: driver.implicitly_wait(20) - WifiNameElement = driver.find_element_by_xpath("//*[@resource-id='android:id/summary']") + WifiNameElement = driver.find_element_by_xpath("//*[@resource-id='android & iOS:id/summary']") Wifi_AP_Name = WifiNameElement.text print("Current Wifi Status Name: " + Wifi_AP_Name) except NoSuchElementException: report.step_start("Checking Wifi Radio Button Status") try: driver.implicitly_wait(5) - WifiRadioBtnConnections = driver.find_element_by_xpath("//*[@resource-id='android:id/switch_widget' and @content-desc='Wi-Fi' and @text='Off']") + WifiRadioBtnConnections = driver.find_element_by_xpath("//*[@resource-id='android & iOS:id/switch_widget' and @content-desc='Wi-Fi' and @text='Off']") report.step_start("Wifi Radio Button Disabled, Enabling Radio Button..") print("Wifi Radio Button Disabled, Enabling Radio Button..") WifiRadioBtnConnections.click() @@ -150,7 +155,7 @@ def set_APconnMobileDevice_android(request, WifiName, WifiPass, setup_perfectoMo try: report.step_start("Verify if Wifi is Connected") - WifiInternetErrMsg = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']") + WifiInternetErrMsg = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']") print("Wifi Successfully Connected") except NoSuchElementException: @@ -161,7 +166,7 @@ def set_APconnMobileDevice_android(request, WifiName, WifiPass, setup_perfectoMo #print("Set Wifi Radio Button to enabled") #try: # report.step_start("Set Wifi Radio Button to enabled") - # wifiRadioBtn = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_widget' and @text='Wi-Fi, Off']") + # wifiRadioBtn = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget' and @text='Wi-Fi, Off']") # wifiRadioBtn.click() # except NoSuchElementException: # report.step_start("Set Wifi Radio Button Already enabled") @@ -180,7 +185,7 @@ def set_APconnMobileDevice_android(request, WifiName, WifiPass, setup_perfectoMo #Set password if Needed try: report.step_start("Set Wifi Password") - wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/edittext']") + wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/edittext']") wifiPasswordElement.send_keys(WifiPass) except NoSuchElementException: print("Password Page Not Loaded, password May be cached in the System") @@ -194,7 +199,7 @@ def set_APconnMobileDevice_android(request, WifiName, WifiPass, setup_perfectoMo 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 + "']"))) + WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) print("Wifi Successfully Connected") except NoSuchElementException: @@ -214,7 +219,7 @@ def set_APconnMobileDevice_android(request, WifiName, WifiPass, setup_perfectoMo try: print("Get Connected Wifi Name if any") report.step_start("Get Connected Wifi Name if any") - WifiNameElement = WebDriverWait(driver, 35).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='android:id/title' and @text='Wi‑Fi']/parent::*/android.widget.TextView[@resource-id='android:id/summary']"))) + WifiNameElement = WebDriverWait(driver, 35).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='android & iOS:id/title' and @text='Wi‑Fi']/parent::*/android & iOS.widget.TextView[@resource-id='android & iOS:id/summary']"))) Wifi_AP_Name = WifiNameElement.text print("Current Wifi Status Name: " + Wifi_AP_Name) WifiNameElement.click() @@ -227,7 +232,7 @@ def set_APconnMobileDevice_android(request, WifiName, WifiPass, setup_perfectoMo try: report.step_start("Verify if Wifi is Connected") - WifiInternetErrMsg = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']") + WifiInternetErrMsg = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']") print("Wifi Successfully Connected") except NoSuchElementException: @@ -238,7 +243,7 @@ def set_APconnMobileDevice_android(request, WifiName, WifiPass, setup_perfectoMo print("Set Wifi Radio Button to enabled") try: report.step_start("Set Wifi Radio Button to enabled") - wifiRadioBtn = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_widget' and @text='OFF']") + wifiRadioBtn = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget' and @text='OFF']") wifiRadioBtn.click() except NoSuchElementException: report.step_start("Set Wifi Radio Button Already enabled") @@ -255,27 +260,27 @@ def set_APconnMobileDevice_android(request, WifiName, WifiPass, setup_perfectoMo #Set password if Needed try: report.step_start("Set Wifi Password") - wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/password']") + wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/password']") wifiPasswordElement.send_keys(WifiPass) except NoSuchElementException: print("Password Page Not Loaded, password May be cached in the System") try: report.step_start("Click Connect Button") - joinBTNElement = driver.find_element_by_xpath("//*[@resource-id='android:id/button1' and @text='Connect']") + joinBTNElement = driver.find_element_by_xpath("//*[@resource-id='android & iOS:id/button1' and @text='Connect']") joinBTNElement.click() except NoSuchElementException: print("Connect Button Not Enabled...Verify if Password is set properly ") 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 + "']"))) + WifiInternetErrMsg = WebDriverWait(driver, 35).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) print("Wifi Successfully Connected") except NoSuchElementException: print("Wifi Connection Error: " + WifiName) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) def ForgetWifiConnection(request, setup_perfectoMobile, WifiName, connData): print("\n-----------------------------") @@ -291,7 +296,7 @@ def ForgetWifiConnection(request, setup_perfectoMobile, WifiName, connData): #print(contexts) #Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print ("Selected Device Model: " + deviceModelName) @@ -310,7 +315,7 @@ def ForgetWifiConnection(request, setup_perfectoMobile, WifiName, connData): try: print("Connected Wifi Name if any") report.step_start("Get Connected Wifi Name if any") - WifiNameElement = driver.find_element_by_xpath("//*[@resource-id='android:id/summary']") + WifiNameElement = driver.find_element_by_xpath("//*[@resource-id='android & iOS:id/summary']") Wifi_AP_Name = WifiNameElement.text print("Connected to Wifi: " + Wifi_AP_Name) except NoSuchElementException: @@ -328,7 +333,7 @@ def ForgetWifiConnection(request, setup_perfectoMobile, WifiName, connData): print("Load Wifi Details Page") try: report.step_start("Load Wifi Details Page") - WifiInternetDetails = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/wifi_details']") + WifiInternetDetails = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/wifi_details']") WifiInternetDetails.click() except NoSuchElementException: print("Wifi Connection Error: " + WifiName) @@ -336,7 +341,7 @@ def ForgetWifiConnection(request, setup_perfectoMobile, WifiName, connData): print("Forget Wifi Network") try: report.step_start("Forget Wifi Network") - WifiForget= driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/smallLabel' and @text='Forget']") + WifiForget= driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/smallLabel' and @text='Forget']") WifiForget.click() except NoSuchElementException: print("Wifi Connection Error: " + WifiName) @@ -344,7 +349,7 @@ def ForgetWifiConnection(request, setup_perfectoMobile, WifiName, connData): print("Verify if wifi is disconnected from: " + WifiName) try: report.step_start("Verify if wifi is disconnected from: " + WifiName) - WifiDisconnect = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']") + WifiDisconnect = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']") print("Wifi Not disconnected, check xpath for: " + WifiName) assert False except Exception as e: @@ -357,14 +362,14 @@ def ForgetWifiConnection(request, setup_perfectoMobile, WifiName, connData): report.step_start("Probably wifi auto connected to another network") try: report.step_start("Wifi Details Page") - WifiInternetDetails = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/wifi_details']") + WifiInternetDetails = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/wifi_details']") WifiInternetDetails.click() except NoSuchElementException: print("Wifi Connection Error: " + WifiName) try: report.step_start("Forget Wifi Network") - WifiForget= driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/smallLabel' and @text='Forget']") + WifiForget= driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/smallLabel' and @text='Forget']") WifiForget.click() except NoSuchElementException: print("Wifi Connection Error: " + WifiName) @@ -372,9 +377,9 @@ def ForgetWifiConnection(request, setup_perfectoMobile, WifiName, connData): print("Verify if wifi is disconnected from: " + WifiName) try: report.step_start("Verify if wifi is disconnected from: " + WifiName) - #WifiForget= driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']") + #WifiForget= driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']") print("Wifi Not disconnected, check xpath for: " + WifiName) - WifiForget = WebDriverWait(driver, 20).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + WifiForget = WebDriverWait(driver, 20).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) except Exception as e: assert True print("Wifi Disconnected Successfully: " + WifiName) @@ -393,7 +398,7 @@ def ForgetWifiConnection(request, setup_perfectoMobile, WifiName, connData): try: print("Get Connected Wifi Name if any") report.step_start("Get Connected Wifi Name if any") - WifiNameElement = WebDriverWait(driver, 35).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='android:id/title' and @text='Wi‑Fi']/parent::*/android.widget.TextView[@resource-id='android:id/summary']"))) + WifiNameElement = WebDriverWait(driver, 35).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='android & iOS:id/title' and @text='Wi‑Fi']/parent::*/android & iOS.widget.TextView[@resource-id='android & iOS:id/summary']"))) Wifi_AP_Name = WifiNameElement.text print("Current Wifi Status Name: " + Wifi_AP_Name) WifiNameElement.click() @@ -405,14 +410,14 @@ def ForgetWifiConnection(request, setup_perfectoMobile, WifiName, connData): #print("Wifi Name Matches - Already Connected To: " + Wifi_AP_Name) try: report.step_start("Wifi More information") - WifiInternetMoreSettings = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/settings_button_no_background']") + WifiInternetMoreSettings = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") WifiInternetMoreSettings.click() except NoSuchElementException: print("Wifi Not Connected to any Wifi Error: " + WifiName) try: report.step_start("Forget Wifi Network") - WifiInternetMoreSettings = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/button1' and @text='Forget']") + WifiInternetMoreSettings = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/button1' and @text='Forget']") WifiInternetMoreSettings.click() except NoSuchElementException: print("Wifi Connection Error: " + WifiName) @@ -420,12 +425,12 @@ def ForgetWifiConnection(request, setup_perfectoMobile, WifiName, connData): try: report.step_start("Verify if Wifi is Connected") - WifiInternetErrMsg = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']") + WifiInternetErrMsg = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']") print("Forgot Wifi Error, check xpath") except Exception as e: print("Wifi Disconnected Successfully: " + WifiName) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) def Toggle_AirplaneMode_android(request, setup_perfectoMobile, connData): print("\n-----------------------") @@ -441,7 +446,7 @@ def Toggle_AirplaneMode_android(request, setup_perfectoMobile, connData): #print(contexts) #Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print ("Selected Device Model: " + deviceModelName) @@ -497,7 +502,7 @@ def Toggle_WifiMode_android(request, setup_perfectoMobile, WifiName, connData): #print(contexts) #Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print ("Selected Device Model: " + deviceModelName) @@ -515,7 +520,7 @@ def Toggle_WifiMode_android(request, setup_perfectoMobile, WifiName, connData): try: print("Get Connected Wifi Name if any") report.step_start("Get Connected Wifi Name if any") - WifiNameElement = driver.find_element_by_xpath("//*[@resource-id='android:id/summary']") + WifiNameElement = driver.find_element_by_xpath("//*[@resource-id='android & iOS:id/summary']") Wifi_AP_Name = WifiNameElement.text print("Current Wifi Status Name: " + Wifi_AP_Name) except NoSuchElementException: @@ -536,7 +541,7 @@ def Toggle_WifiMode_android(request, setup_perfectoMobile, WifiName, connData): try: print("Get Connected Wifi Name if any after Wifi Radio is disabled") report.step_start("Get Connected Wifi Name if any after Wifi Radio is disabled") - WifiNameElement = driver.find_element_by_xpath("//*[@resource-id='android:id/summary']") + WifiNameElement = driver.find_element_by_xpath("//*[@resource-id='android & iOS:id/summary']") Wifi_AP_Name2 = WifiNameElement.text print("Device Connected to Wifi: " + Wifi_AP_Name2) except NoSuchElementException: @@ -554,7 +559,7 @@ def Toggle_WifiMode_android(request, setup_perfectoMobile, WifiName, connData): try: print("Get Connected Wifi Name if any after Wifi Radio is Enabled") report.step_start("Get Connected Wifi Name if any after Wifi Radio is disabled") - WifiNameElement3 = WebDriverWait(driver, 35).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='android:id/summary']"))) + WifiNameElement3 = WebDriverWait(driver, 35).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='android & iOS:id/summary']"))) Wifi_AP_Name3 = WifiNameElement3.text print("Current Wifi Status Name: " + Wifi_AP_Name3) except NoSuchElementException and TimeoutException: @@ -586,8 +591,13 @@ def verifyUploadDownloadSpeed_android(request, setup_perfectoMobile, get_APToMob report.step_start("Google Home Page") driver.get(connData["webURL"]) print("Enter Search Text") - elementFindTxt = driver.find_element_by_xpath(connData["lblSearch"]) + # elementFindTxt = driver.find_element_by_xpath(connData["lblSearch"]) + # elementFindTxt.send_keys("Internet Speed Test") + elementFindTxt = driver.find_element_by_xpath("//*[@resource-id='com.google.android & iOS.googlequicksearchbox:id/search_edit_frame']") + elementFindTxt.click() elementFindTxt.send_keys("Internet Speed Test") + + except Exception as e: print("Launching Chrome Failed") print (e) @@ -668,7 +678,7 @@ def downloadInstallOpenRoamingProfile(request, profileDownloadURL, setup_perfect print("Alert Accepted") except TimeoutException: print("no alert") - #//*[@resource-id="android:id/button1"] + #//*[@resource-id="android & iOS:id/button1"] #Open Settings Application #openApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) @@ -686,7 +696,7 @@ def deleteOpenRoamingInstalledProfile(request, profileName, setup_perfectoMobile contexts = driver.contexts #Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) @@ -696,7 +706,7 @@ def deleteOpenRoamingInstalledProfile(request, profileName, setup_perfectoMobile report.step_start("Forget Profile: " + profileName) # three dotss - #//*[@resource-id='com.android.settings:id/round_corner'] + #//*[@resource-id='com.android & iOS.settings:id/round_corner'] try: print("Click Connections") report.step_start("Click Connections") @@ -757,21 +767,21 @@ def deleteOpenRoamingInstalledProfile(request, profileName, setup_perfectoMobile print("Exception: Profile Don't Exist") #Click Forget - #//*[@resource-id="com.android.settings:id/icon"] + #//*[@resource-id="com.android & iOS.settings:id/icon"] try: print ("Click Forget") report.step_start("Click Forget") - ForgetBTN = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/icon']") + ForgetBTN = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/icon']") ForgetBTN.click() except NoSuchElementException: print("Exception: Click Forget") #Click Forget Confirm - #//*[@resource-id="android:id/button1"] + #//*[@resource-id="android & iOS:id/button1"] try: print ("Click Forget Confirm") report.step_start("Click Forget Confirm") - ForgetConfirm = driver.find_element_by_xpath("//*[@resource-id='android:id/button1']") + ForgetConfirm = driver.find_element_by_xpath("//*[@resource-id='android & iOS:id/button1']") ForgetConfirm.click() except NoSuchElementException: print("Exception: Click Forget Confirm") @@ -782,7 +792,7 @@ def deleteOpenRoamingInstalledProfile(request, profileName, setup_perfectoMobile report.step_start("Pixel Device Not supported: ") assert False - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) def verify_APconnMobileDevice_Android(request, profileNameSSID, setup_perfectoMobile, connData): print("\n-----------------------------") @@ -798,7 +808,7 @@ def verify_APconnMobileDevice_Android(request, profileNameSSID, setup_perfectoMo contexts = driver.contexts #Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) @@ -823,8 +833,8 @@ def verify_APconnMobileDevice_Android(request, profileNameSSID, setup_perfectoMo try: print("Verify if Wifi is Connected to: " + profileNameSSID) report.step_start("Verify if Wifi is Connected: " + profileNameSSID) - #WifiInternetErrMsg = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + profileNameSSID + "']") - WifiInternetErrMsg = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='Ameriband']") + #WifiInternetErrMsg = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + profileNameSSID + "']") + WifiInternetErrMsg = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='Ameriband']") print("Wifi Successfully Connected") except NoSuchElementException: @@ -838,7 +848,7 @@ def verify_APconnMobileDevice_Android(request, profileNameSSID, setup_perfectoMo report.step_start("Pixel Device Not supported: ") assert False - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # Cache_clear Function @@ -854,7 +864,7 @@ def cache_clear_android(request, setup_perfectoMobile, connData): driver.switch_to.context(contexts[0]) # Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print("Selected Device Model: " + deviceModelName) @@ -872,7 +882,7 @@ def cache_clear_android(request, setup_perfectoMobile, connData): driver.implicitly_wait(30) print("Entering Chrome in Search") report.step_start("Entering text Chrome") - search_ele = driver.find_element_by_xpath("//*[@resource-id='com.android.settings.intelligence:id/search_src_text']") + search_ele = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings.intelligence:id/search_src_text']") search_ele.send_keys("chrome") except Exception as e: print("Exception: Entering chrome failed") @@ -903,7 +913,7 @@ def cache_clear_android(request, setup_perfectoMobile, connData): driver.implicitly_wait(30) print("Clicking Clear Cache") report.step_start("Click Clear Cache") - clear_ele = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/button2']") + clear_ele = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/button2']") clear_ele.click() print("Cleared Cache") except NoSuchElementException: @@ -926,7 +936,7 @@ def cache_clear_android(request, setup_perfectoMobile, connData): try: print("Clicking Search button") report.step_start("Click Search") - conn_ele = driver.find_element_by_xpath("//*[@class='android.widget.ImageButton']") + conn_ele = driver.find_element_by_xpath("//*[@class='android & iOS.widget.ImageButton']") conn_ele.click() except NoSuchElementException: print("Exception: Verify Xpath - Update/check Xpath for Click Search") @@ -935,7 +945,7 @@ def cache_clear_android(request, setup_perfectoMobile, connData): driver.implicitly_wait(30) print("Entering Chrome in Search") report.step_start("Entering text Chrome") - search_ele = driver.find_element_by_xpath("//*[@resource-id='android:id/search_src_text']") + search_ele = driver.find_element_by_xpath("//*[@resource-id='android & iOS:id/search_src_text']") search_ele.send_keys("chrome") except Exception as e: print("Exception: Entering chrome failed") @@ -963,7 +973,7 @@ def cache_clear_android(request, setup_perfectoMobile, connData): driver.implicitly_wait(30) print("Clicking Clear Cache") report.step_start("Click Clear Cache") - clear_ele = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/button2']") + clear_ele = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/button2']") clear_ele.click() print("Cleared cache") except NoSuchElementException: @@ -995,7 +1005,7 @@ def cache_clear_android(request, setup_perfectoMobile, connData): print("Entering Chrome in Search") report.step_start("Entering text Chrome") search_ele = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings.intelligence:id/search_src_text']") + "//*[@resource-id='com.android & iOS.settings.intelligence:id/search_src_text']") search_ele.send_keys("chrome") except Exception as e: print("Exception: Entering chrome failed") @@ -1026,7 +1036,7 @@ def cache_clear_android(request, setup_perfectoMobile, connData): driver.implicitly_wait(30) print("Clicking Clear Cache") report.step_start("Click Clear Cache") - clear_ele = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/button2']") + clear_ele = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/button2']") clear_ele.click() print("Cleared Cache") except NoSuchElementException: @@ -1045,14 +1055,14 @@ def cache_clear_android(request, setup_perfectoMobile, connData): print("Exception: Verify Xpath - Update/check Xpath for Checking cache clear") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) def check_if_no_internet_popup(driver):#To check and kill if any popups related to no internet time.sleep(1) driver.implicitly_wait(1) try: - popup = driver.find_element_by_xpath("//*[@resource-id='android:id/alertTitle']") + popup = driver.find_element_by_xpath("//*[@resource-id='android & iOS:id/alertTitle']") popup_text = popup.text try: @@ -1062,7 +1072,7 @@ def check_if_no_internet_popup(driver):#To check and kill if any popups related try: driver.implicitly_wait(2) time.sleep(2) - kill_popup = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/keep_btn']") + kill_popup = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/keep_btn']") kill_popup.click() print("popup killed") except: @@ -1097,7 +1107,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa driver.switch_to.context(contexts[0]) # Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print("Selected Device Model: " + deviceModelName) @@ -1126,14 +1136,14 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) - get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_text']") + get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text print("get_switch_text: ",get_switch_text) print("Find wifi switch") try: #To Turn on Wi-Fi Switch if get_switch_text == "Off": # driver.implicitly_wait(3) - get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_widget']") + get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -1145,7 +1155,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa else: try: get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_text']") + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text except: pass @@ -1154,14 +1164,14 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa pass if get_switch_text == "Off": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet #---------------------This is to Forget current connected SSID------------------------------- @@ -1169,22 +1179,22 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa try: #To deal with already connected SSID check_if_no_internet_popup(driver) network_category = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/connected_network_category']") + "//*[@resource-id='com.android & iOS.settings:id/connected_network_category']") try: #To forget exhisting ssid print("To forget ssid") check_if_no_internet_popup(driver) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") + "//*[@resource-id='com.android & iOS.settings:id/layout_details']") additional_details_element.click() 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']") + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") forget_ssid.click() print("Forget old ssid") except: print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: print("Couldn't get into additional details") @@ -1194,23 +1204,23 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa try: #To deal with already connected SSID check_if_no_internet_popup(driver) network_category = driver.find_element_by_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]") + "//*[@resource-id='com.android & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]") try: #To forget exhisting ssid print("To forget ssid in osversion 12") check_if_no_internet_popup(driver) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/wifi_details']") + "//*[@resource-id='com.android & iOS.settings:id/wifi_details']") additional_details_element.click() try: print("To forget ssid in osversion 12-1206") 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/navigation_bar_item_icon_view']") + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/navigation_bar_item_icon_view']") forget_ssid.click() print("Forget old ssid") except: print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: print("Couldn't get into additional details") @@ -1244,10 +1254,10 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa if not ssid_found: print("could not found " + WifiName + " in device") #allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet #------------------------------------------------------- @@ -1265,7 +1275,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa except Exception as e: print("Exception on Selecting Wifi Network. Please check wifi Name or signal") request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -1277,7 +1287,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa time.sleep(3) report.step_start("Set Wifi Password") print("Set Wifi password") - wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/edittext']") + wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/edittext']") wifiPasswordElement.send_keys(WifiPass) except NoSuchElementException: print("Password Page Not Loaded, password May be cached in the System") @@ -1304,7 +1314,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) @@ -1314,7 +1324,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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='" + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) print("Wifi Successfully Connected without internet") check_if_no_internet_popup(driver) @@ -1323,12 +1333,12 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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 + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: try: @@ -1338,12 +1348,12 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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]" + "//*[@resource-id='com.android & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]/android & iOS.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']" + "//*[@resource-id='com.android & iOS.settings:id/summary']" ))) if wifi_connection_status.text == "Connected": ssid_with_internet = True @@ -1356,10 +1366,10 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # 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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -1373,31 +1383,31 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa print("Into additional details") time.sleep(2) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") + "//*[@resource-id='com.android & iOS.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='com.android.settings:id/summary']") + "//*[@text='IP address']/parent::*/android & iOS.widget.TextView[@resource-id='com.android & iOS.settings:id/summary']") ip_address_element_text = ip_address_element.text print("Device IP address is :", ip_address_element_text) except: 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 & iOS.widget.TextView[@resource-id='android & iOS: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) + closeApp(connData["appPackage-android & iOS"], 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']") + "//*[@text='Security']/parent::*/android & iOS.widget.TextView[@resource-id='com.android & iOS.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)) @@ -1407,25 +1417,25 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa try: time.sleep(2) ssid_name_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/entity_header_title']") + "//*[@resource-id='com.android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) assert False if (ssid_name_element_text == WifiName): print("Wifi is connected to the expected ssid") else: print("Wifi is not connected to the expected ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], 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 = driver.find("//*[@resource-id='android & iOS:id/switch_widget']") auto_reconnect_off_text = auto_reconnect_off.text if auto_reconnect_off_text != "Off": auto_reconnect_off.click() @@ -1439,7 +1449,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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']") + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") forget_ssid.click() print("Forgetting ssid") @@ -1447,7 +1457,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # try: # print("clicking on wifi switch") # get_switch_element = driver.find_element_by_xpath( - # "//*[@resource-id='com.android.settings:id/switch_widget']") + # "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") # driver.implicitly_wait(2) # get_switch_element.click() # except: @@ -1455,7 +1465,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # #allure.attach(name= body=str("couldn't click on wifi switch")) except: print("Couldn't forget ssid") - # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # return ip_address_element_text, ssid_with_internet except: print("Couldn't get into Additional settings") @@ -1465,7 +1475,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa print("Into additional details") time.sleep(2) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/wifi_details']") + "//*[@resource-id='com.android & iOS.settings:id/wifi_details']") additional_details_element.click() try: @@ -1479,7 +1489,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa try: time.sleep(2) ssid_name_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/entity_header_title']") + "//*[@resource-id='com.android & iOS.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)) @@ -1494,7 +1504,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # return ip_address_element_text, ssid_with_internet else: print("Wifi is not connected to the expected ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) report.step_start("Scrolling for ip address - 1") # if deviceModelName == "Galaxy S20": @@ -1520,7 +1530,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[4]/android & iOS.widget.RelativeLayout[1]/android & iOS.widget.TextView[2]") ip_address_element_text = ip_address_element_text.text ssid_with_internet = True except: @@ -1540,7 +1550,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # try: # print("clicking on wifi switch") # get_switch_element = driver.find_element_by_xpath( - # "//*[@resource-id='com.android.settings:id/switch_widget']") + # "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") # driver.implicitly_wait(2) # get_switch_element.click() # except: @@ -1548,7 +1558,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # #allure.attach(name= body=str("couldn't click on wifi switch")) except: print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: print("Couldn't get into Additional settings") @@ -1591,7 +1601,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa try: driver.implicitly_wait(1) get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") get_switch_text = get_switch_text_element.text # if get_switch_text is not None: # switch_text = "OFF" @@ -1604,7 +1614,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa if switch_text == "OFF": # driver.implicitly_wait(3) get_switch_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -1631,14 +1641,14 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa pass if switch_text == "OFF": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ---------------------This is to Forget current connected SSID------------------------------- @@ -1649,19 +1659,19 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa print("To forget ssid") check_if_no_internet_popup(driver) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") additional_details_element.click() except: print("Couldn't get into additional details") try: check_if_no_internet_popup(driver) forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/button1']") + "//*[@resource-id='com.android & iOS.settings:id/button1']") forget_ssid.click() print("Forget old ssid") except: print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: print("No Connected SSIDS") @@ -1710,10 +1720,10 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa if not ssid_not_found: print("could not found " + WifiName + " in device") # allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -1728,7 +1738,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa except Exception as e: print("Exception on Selecting Wifi Network. Please check wifi Name or signal") request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -1739,7 +1749,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa check_if_no_internet_popup(driver) report.step_start("Set Wifi Password") print("Entering password") - wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/password']") + wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/password']") wifiPasswordElement.send_keys(WifiPass) except NoSuchElementException: print("Password Page Not Loaded, password May be cached in the System") @@ -1764,7 +1774,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) @@ -1777,7 +1787,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # 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 + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='"+ WifiName + "']"))) print("Wifi Successfully Connected without internet") check_if_no_internet_popup(driver) except: @@ -1787,12 +1797,12 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa scroll_up(setup_perfectoMobile) WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( MobileBy.XPATH, - "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -1806,7 +1816,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa time.sleep(5) report.step_start("Going for ip address") additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") additional_details_element.click() print("Entered ssid") try: @@ -1822,7 +1832,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa time.sleep(5) print("clicking Advanced2") advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.FrameLayout[2]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[1]") advanced_element.click() #print("Device IP address is :", ip_address_element_text) except: @@ -1830,20 +1840,20 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa time.sleep(5) print("clicking Advanced2") advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.LinearLayout[5]/android.widget.LinearLayout[1]/android.widget.ImageView[1]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[5]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.ImageView[1]") advanced_element.click() except: print("No advanced options") # allure.attach(name= body=str("IP address element not found")) - # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # return ip_address_element_text, ssid_with_internet # Scroll Down scrollDown(setup_perfectoMobile) 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 & iOS.widget.TextView[@resource-id='android & iOS:id/summary']") ip_address_element_text = ip_address_element.text print("Device IP address is :", ip_address_element_text) except: @@ -1852,7 +1862,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa try: check_if_no_internet_popup(driver) forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") forget_ssid.click() print("Forgetting ssid") @@ -1860,7 +1870,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa try: print("clicking on wifi switch") get_switch_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(2) get_switch_element.click() except: @@ -1868,7 +1878,7 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # allure.attach(name= body=str("couldn't click on wifi switch")) except: print("Couldn't forget ssid") - # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # return ip_address_element_text, ssid_with_internet except: print("Couldn't get into Additional settings") @@ -1885,19 +1895,19 @@ def get_ip_address_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa print("Exception: Verify Xpath - Update/check Xpath for Click Connections") # -----------------To Open Connections page--------------------------- - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet -#only to connect to wifi -def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): +#mavericknew +def get_ip_address_maverick_new_and(request, WifiName, WifiPass, setup_perfectoMobile, connData): print("\n-------------------------------------") print("Select Wifi/AccessPoint Connection") print("-------------------------------------") print("Verifying Wifi Connection Details....") - #allure.attach(name= body=str("\n-------------------------------------")) report = setup_perfectoMobile[1] driver = setup_perfectoMobile[0] + ip_address_element_text = False ssid_with_internet = False report.step_start("Switching Driver Context") @@ -1906,10 +1916,10 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): driver.switch_to.context(contexts[0]) # Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print("Selected Device Model: " + deviceModelName) - #allure.attach(name= body=str("\Selected Device Model: " + deviceModelName)) + if deviceModelName != ("Pixel 4"): report.step_start("Set Wifi Network to " + WifiName) @@ -1926,21 +1936,23 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): try: report.step_start("Clicking Wi-Fi") print("Clicking WIFI") - wifiElement = driver.find_element_by_xpath("//*[@text='Wi-Fi']") + time.sleep(3) + wifiElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH,"//*[@text='Wi-Fi']"))) wifiElement.click() # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) - get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_text']") + get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text print("get_switch_text: ",get_switch_text) print("Find wifi switch") try: #To Turn on Wi-Fi Switch if get_switch_text == "Off": # driver.implicitly_wait(3) - get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_widget']") + get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -1952,7 +1964,7 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): else: try: get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_text']") + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text except: pass @@ -1961,76 +1973,102 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): pass if get_switch_text == "Off": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet #---------------------This is to Forget current connected SSID------------------------------- - try: #To deal with already connected SSID - check_if_no_internet_popup(driver) - network_category = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/connected_network_category']") - try: #To forget exhisting ssid - print("To forget ssid") + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, search_this="osVersion") != "12": + try: #To deal with already connected SSID check_if_no_internet_popup(driver) - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") - additional_details_element.click() - try: + network_category = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/connected_network_category']") + try: #To forget exhisting ssid + print("To forget ssid") 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("Forget old ssid") + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/layout_details']") + additional_details_element.click() + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") + forget_ssid.click() + print("Forget old ssid") + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet except: - print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + print("Couldn't get into additional details") except: - print("Couldn't get into additional details") - except: - print("No Connected SSIDS") + print("No Connected SSIDS") + else: + try: #To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]") + try: #To forget exhisting ssid + print("To forget ssid in osversion 12") + check_if_no_internet_popup(driver) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/wifi_details']") + additional_details_element.click() + try: + print("To forget ssid in osversion 12-1206") + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/navigation_bar_item_icon_view']") + forget_ssid.click() + print("Forget old ssid") + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into additional details") + except: + print("No Connected SSIDS") #----------------------This is to Forget current connected SSID-------------------------------- - - print("Searching for Wifi: " + WifiName) - #allure.attach(name= body=str("Searching for Wifi: " + WifiName)) - time.sleep(2) + # time.sleep(2) print("Selecting Wifi: " + WifiName) + #allure.attach(name= body=str("Selecting Wifi: " + WifiName)) ssid_found = False available_ssids = False - # This is To get all available ssids - # ------------------------------------------------------ + #This is To get all available ssids + #------------------------------------------------------ try: - for check_for_all_ssids in range(2): + for k in range(9): available_ssids = get_all_available_ssids(driver, deviceModelName) + print("active_ssid_list: ", available_ssids) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) try: if WifiName not in available_ssids: scrollDown(setup_perfectoMobile) time.sleep(2) else: ssid_found = True - print(WifiName + " : Found in Device") - #allure.attach(name= body=str(WifiName + " : Found in Device")) + print(WifiName+" : Found in Device") + #allure.attach(name= body=str(WifiName+" : Found in Device")) break except: - print("1538") - pass + print("couldn't find wifi in available ssid") if not ssid_found: - print("could not found" + WifiName + " in device") + print("could not found " + WifiName + " in device") #allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet - # ------------------------------------------------------- + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + #------------------------------------------------------- @@ -2038,17 +2076,16 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): # ------------------------------------------------------- try: report.step_start("Selecting Wifi: " + WifiName) + print(("Clicking WIFI")) wifiSelectionElement = WebDriverWait(driver, 35).until( EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) wifiSelectionElement.click() check_if_no_internet_popup(driver) - #allure.attach(name= body=str("Selecting Wifi: " + WifiName)) except Exception as e: print("Exception on Selecting Wifi Network. Please check wifi Name or signal") - #allure.attach(name= body=str("Exception on Selecting Wifi Network. Please check wifi Name or signal")) request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -2056,9 +2093,10 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): # ------------------------------------------------------- try: check_if_no_internet_popup(driver) + time.sleep(3) report.step_start("Set Wifi Password") - wifiPasswordElement = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/edittext']") + print("Set Wifi password") + wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/edittext']") wifiPasswordElement.send_keys(WifiPass) except NoSuchElementException: print("Password Page Not Loaded, password May be cached in the System") @@ -2068,72 +2106,265 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): #Click on connect button # ------------------------------------------------------- try: + time.sleep(5) report.step_start("Click Connect Button") + print("Click Connect") joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") joinBTNElement.click() except NoSuchElementException: print("Connect Button Not Enabled...Verify if Password is set properly ") check_if_no_internet_popup(driver) # ------------------------------------------------------- - # //*[@resource-id='com.android.settings:id/summary' and @text="Sign in to the network."]/parent::*/android.widget.TextView[@text='XWF-OWF_DSx'] + #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") - #allure.attach(name= body=str("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") - #allure.attach(name= body=str("Wifi Successfully Connected without internet")) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.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") - #allure.attach(name=body=str("Wifi Successfully Connected")) + check_if_no_internet_popup(driver) + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='" + + WifiName + "']"))) + print("Wifi Successfully Connected without internet") + check_if_no_internet_popup(driver) except: try: - report.step_start("Unknown WIFI status found") - ssid_with_internet = False - print("Unknown WIFI status found") + 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 & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") except NoSuchElementException: print("Wifi Connection Error: " + WifiName) - #allure.attach(name=body=str("Wifi Connection Error: " + WifiName)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], 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 & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]/android & iOS.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 & iOS.settings:id/summary']" + ))) + if wifi_connection_status.text == "Connected": + ssid_with_internet = True + print("Connected with internet") - except NoSuchElementException: - print("No Switch element found") - #allure.attach(name= body=str("No Switch element found")) - # ---------------------To Turn on WIFi Switch if already OFF------------------------------- + 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 & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + # ------------------------------------------------------- - except NoSuchElementException: - print("Couldn't find wifi Button") - #allure.attach(name= body=str("Couldn't find wifi Button")) - # ------------------Open WIFI page---------------------------------- + #Get into Additional Details + #To Get an IP Address + #To Forget connection + #To turn off auto. connect + # ------------------------------------------------------- + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, search_this="osVersion") != "12": + try: + print("Into additional details") + time.sleep(2) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.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 & iOS.widget.TextView[@resource-id='com.android & iOS.settings:id/summary']") + ip_address_element_text = ip_address_element.text + print("Device IP address is :", ip_address_element_text) + except: + try: + time.sleep(2) + ip_address_element = driver.find_element_by_xpath( + "//*[@text='IP address']/parent::*/android & iOS.widget.TextView[@resource-id='android & iOS: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 & iOS"], 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 & iOS.widget.TextView[@resource-id='com.android & iOS.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 & iOS.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 & iOS"], setup_perfectoMobile) + assert False + if (ssid_name_element_text == WifiName): + print("Wifi is connected to the expected ssid") + else: + print("Wifi is not connected to the expected ssid") + closeApp(connData["appPackage-android & iOS"], 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 & iOS: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") - except NoSuchElementException: - print("Exception: Verify Xpath - Update/check Xpath for Click Connections") - #allure.attach(name= body=str("Exception: Verify Xpath - Update/check Xpath for Click Connections")) - # -----------------To Open Connections page--------------------------- - else: #--------------Pixel 4 code-------------------------- + # ------------------------------- Forget SSID ---------------- + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.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 & iOS.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 & iOS"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet + except: + 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 & iOS.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 & iOS.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 & iOS"], 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 & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[4]/android & iOS.widget.RelativeLayout[1]/android & iOS.widget.TextView[2]") + ip_address_element_text = ip_address_element_text.text + ssid_with_internet = True + except: + print("Unable to get IP address") + pass + + except: + print("Couldn't get into Additional settings") + # ------------------------------------------------------- + + + # ------------------------------------------------------- + except: + print("No Switch element found") + # ---------------------To Turn on WIFi Switch if already OFF------------------------------- + + except: + print("Couldn't find wifi Button") + # ------------------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) # -----------------To Open Connections page----------------------- @@ -2156,25 +2387,26 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): try: driver.implicitly_wait(1) get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='android:id/icon']") - get_switch_text = get_switch_text_element.click() - if get_switch_text is not None: - switch_text = "Off" - else: - switch_text = "On" + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") + get_switch_text = get_switch_text_element.text + # if get_switch_text is not None: + # switch_text = "OFF" + # else: + # switch_text = "ON" + switch_text = get_switch_text print("get_switch_text: ", switch_text) print("Find wifi switch") try: # To Turn on Wi-Fi Switch - if switch_text == "Off": + if switch_text == "OFF": # driver.implicitly_wait(3) get_switch_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) i = 0 for i in range(5): - if switch_text == "On": + if switch_text == "ON": print("WIFI Switch is ON") break else: @@ -2183,9 +2415,9 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): "//*[@text='Add network']") get_switch_text = get_switch_text_element.text if get_switch_text == "Add network": - switch_text = "On" + switch_text = "ON" else: - switch_text = "Off" + switch_text = "OFF" except NoSuchElementException: print("Exception: Verify Xpath") # Scroll Down @@ -2193,17 +2425,18 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): print("Sleeping for: ", i) time.sleep(i) pass - if switch_text == "Off": + if switch_text == "OFF": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + # ---------------------This is to Forget current connected SSID------------------------------- try: # To deal with already connected SSID check_if_no_internet_popup(driver) @@ -2212,20 +2445,20 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): print("To forget ssid") check_if_no_internet_popup(driver) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") additional_details_element.click() except: print("Couldn't get into additional details") try: check_if_no_internet_popup(driver) forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/button1']") + "//*[@resource-id='com.android & iOS.settings:id/button1']") forget_ssid.click() print("Forget old ssid") except: print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet except: print("No Connected SSIDS") # ----------------------This is to Forget current connected SSID-------------------------------- @@ -2241,7 +2474,7 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): for k in range(5): available_ssids = get_all_available_ssids(driver, deviceModelName) print("active_ssid_list: ", available_ssids) - #allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) try: if WifiName not in available_ssids: scrollDown(setup_perfectoMobile) @@ -2273,11 +2506,11 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): if not ssid_not_found: print("could not found " + WifiName + " in device") # allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- # Selecting WIFI @@ -2291,17 +2524,18 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): except Exception as e: print("Exception on Selecting Wifi Network. Please check wifi Name or signal") request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- # Set password if Needed # ------------------------------------------------------- try: + time.sleep(3) check_if_no_internet_popup(driver) report.step_start("Set Wifi Password") - wifiPasswordElement = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/password']") + print("Entering password") + wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/password']") wifiPasswordElement.send_keys(WifiPass) except NoSuchElementException: print("Password Page Not Loaded, password May be cached in the System") @@ -2312,6 +2546,7 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): # ------------------------------------------------------- try: report.step_start("Click Connect Button") + time.sleep(5) joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") joinBTNElement.click() except NoSuchElementException: @@ -2325,7 +2560,7 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) @@ -2338,7 +2573,7 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): # 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 + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='"+ WifiName + "']"))) print("Wifi Successfully Connected without internet") check_if_no_internet_popup(driver) except: @@ -2348,53 +2583,122 @@ def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): scroll_up(setup_perfectoMobile) WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( MobileBy.XPATH, - "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.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 ssid_with_internet + closeApp(connData["appPackage-android & iOS"], 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 + # ------------------------------------------------------- + try: + print("Into additional details") + time.sleep(5) + report.step_start("Going for ip address") + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") + additional_details_element.click() + print("Entered ssid") + try: + time.sleep(10) + print("clicking Advanced") + report.step_start("clicking Advanced") + advanced_element = driver.find_element_by_xpath("//*[@text='Advanced']") + advanced_element.click() + print("clicked Advanced") + #print("Device IP address is :", ip_address_element_text) + except: + try: + time.sleep(5) + print("clicking Advanced2") + advanced_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.FrameLayout[2]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[1]") + advanced_element.click() + #print("Device IP address is :", ip_address_element_text) + except: + try: + time.sleep(5) + print("clicking Advanced2") + advanced_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[5]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.ImageView[1]") + advanced_element.click() + except: + print("No advanced options") + # allure.attach(name= body=str("IP address element not found")) - except NoSuchElementException: + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet + # Scroll Down + scrollDown(setup_perfectoMobile) + try: + time.sleep(2) + ip_address_element = driver.find_element_by_xpath( + "//*[@text='IP address']/parent::*/android & iOS.widget.TextView[@resource-id='android & iOS: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") + #------------------------------- Forget SSID ---------------- + print("Forgetting ssid") + + # ------------------------------- Wifi Switch ---------------- + try: + print("clicking on wifi switch") + get_switch_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.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 get into Additional settings") + # ------------------------------------------------------- + except: print("No Switch element found") - # allure.attach(name= body=str("No Switch element found")) # ---------------------To Turn on WIFi Switch if already OFF------------------------------- - except NoSuchElementException: + except: print("Couldn't find wifi Button") - # allure.attach(name= body=str("Couldn't find wifi Button")) # ------------------Open WIFI page---------------------------------- - except NoSuchElementException: + except: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") - # allure.attach(name= body=str("Exception: Verify Xpath - Update/check Xpath for Click Connections")) # -----------------To Open Connections page--------------------------- - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet -#To disconnect and forget network -def wifi_disconnect_and_forget(request, WifiName, WifiPass, setup_perfectoMobile, connData): + + +#only to connect to wifi +def wifi_connect(request, WifiName, WifiPass, setup_perfectoMobile, connData): print("\n-------------------------------------") - print("WIFI Disconnect") + print("Select Wifi/AccessPoint Connection") print("-------------------------------------") - #allure.attach(name= body=str("------------------- WIFI Disconnect ------------------")) - + print("Verifying Wifi Connection Details....") + #allure.attach(name= body=str("\n-------------------------------------")) report = setup_perfectoMobile[1] driver = setup_perfectoMobile[0] + ssid_with_internet = False + report.step_start("Switching Driver Context") print("Switching Context to Native") contexts = driver.contexts driver.switch_to.context(contexts[0]) # Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print("Selected Device Model: " + deviceModelName) - + #allure.attach(name= body=str("\Selected Device Model: " + deviceModelName)) if deviceModelName != ("Pixel 4"): report.step_start("Set Wifi Network to " + WifiName) @@ -2418,14 +2722,14 @@ def wifi_disconnect_and_forget(request, WifiName, WifiPass, setup_perfectoMobile # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) - get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_text']") + get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text print("get_switch_text: ",get_switch_text) print("Find wifi switch") try: #To Turn on Wi-Fi Switch if get_switch_text == "Off": # driver.implicitly_wait(3) - get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_widget']") + get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -2437,7 +2741,7 @@ def wifi_disconnect_and_forget(request, WifiName, WifiPass, setup_perfectoMobile else: try: get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_text']") + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text except: pass @@ -2446,72 +2750,185 @@ def wifi_disconnect_and_forget(request, WifiName, WifiPass, setup_perfectoMobile pass if get_switch_text == "Off": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet #---------------------This is to Forget current connected SSID------------------------------- try: #To deal with already connected SSID check_if_no_internet_popup(driver) network_category = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/connected_network_category']") + "//*[@resource-id='com.android & iOS.settings:id/connected_network_category']") try: #To forget exhisting ssid print("To forget ssid") check_if_no_internet_popup(driver) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") + "//*[@resource-id='com.android & iOS.settings:id/layout_details']") additional_details_element.click() 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']") + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") forget_ssid.click() print("Forget old ssid") - #allure.attach(name=body=str("Forget old ssid")) except: print("Couldn't forget ssid") - #allure.attach(name=body=str("Couldn't forget ssid")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet except: - #allure.attach(name=body=str("Couldn't get into additional details")) print("Couldn't get into additional details") except: - #allure.attach(name=body=str("No Connected SSIDS")) print("No Connected SSIDS") #----------------------This is to Forget current connected SSID-------------------------------- - 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") - - - except NoSuchElementException: - print("No Switch element found") - # ---------------------To Turn on WIFi Switch if already OFF------------------------------- - - except NoSuchElementException: - print("Couldn't find wifi Button") - # ------------------Open WIFI page---------------------------------- - except NoSuchElementException: + print("Searching for Wifi: " + WifiName) + #allure.attach(name= body=str("Searching for Wifi: " + WifiName)) + time.sleep(2) + print("Selecting Wifi: " + WifiName) + ssid_found = False + available_ssids = False + # This is To get all available ssids + # ------------------------------------------------------ + try: + for check_for_all_ssids in range(2): + available_ssids = get_all_available_ssids(driver, deviceModelName) + try: + if WifiName not in available_ssids: + scrollDown(setup_perfectoMobile) + time.sleep(2) + else: + ssid_found = True + print(WifiName + " : Found in Device") + #allure.attach(name= body=str(WifiName + " : Found in Device")) + break + except: + print("1538") + pass + if not ssid_found: + print("could not found" + WifiName + " in device") + #allure.attach(name= body=str("could not found" + WifiName + " in device")) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + except: + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + # ------------------------------------------------------- + + + + #Selecting WIFI + # ------------------------------------------------------- + try: + report.step_start("Selecting Wifi: " + WifiName) + wifiSelectionElement = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) + wifiSelectionElement.click() + check_if_no_internet_popup(driver) + #allure.attach(name= body=str("Selecting Wifi: " + WifiName)) + except Exception as e: + print("Exception on Selecting Wifi Network. Please check wifi Name or signal") + #allure.attach(name= body=str("Exception on Selecting Wifi Network. Please check wifi Name or signal")) + request.config.cache.set(key="SelectingWifiFailed", value=str(e)) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + # ------------------------------------------------------- + + + #Set password if Needed + # ------------------------------------------------------- + try: + check_if_no_internet_popup(driver) + report.step_start("Set Wifi Password") + wifiPasswordElement = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/edittext']") + wifiPasswordElement.send_keys(WifiPass) + except NoSuchElementException: + print("Password Page Not Loaded, password May be cached in the System") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + + #Click on connect button + # ------------------------------------------------------- + try: + report.step_start("Click Connect Button") + joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") + joinBTNElement.click() + except NoSuchElementException: + print("Connect Button Not Enabled...Verify if Password is set properly ") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + # //*[@resource-id='com.android & iOS.settings:id/summary' and @text="Sign in to the network."]/parent::*/android & iOS.widget.TextView[@text='XWF-OWF_DSx'] + #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 & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + #allure.attach(name= body=str("Wifi Successfully Connected")) + # time.sleep(5) + check_if_no_internet_popup(driver) + except: + try: + check_if_no_internet_popup(driver) + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='" + + WifiName + "']"))) + print("Wifi Successfully Connected without internet") + #allure.attach(name= body=str("Wifi Successfully Connected without internet")) + 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 & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + #allure.attach(name=body=str("Wifi Successfully Connected")) + except: + try: + report.step_start("Unknown WIFI status found") + ssid_with_internet = False + print("Unknown WIFI status found") + except NoSuchElementException: + print("Wifi Connection Error: " + WifiName) + #allure.attach(name=body=str("Wifi Connection Error: " + WifiName)) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + + + except NoSuchElementException: + print("No Switch element found") + #allure.attach(name= body=str("No Switch element found")) + # ---------------------To Turn on WIFi Switch if already OFF------------------------------- + + except NoSuchElementException: + print("Couldn't find wifi Button") + #allure.attach(name= body=str("Couldn't find wifi Button")) + # ------------------Open WIFI page---------------------------------- + + except NoSuchElementException: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") + #allure.attach(name= body=str("Exception: Verify Xpath - Update/check Xpath for Click Connections")) # -----------------To Open Connections page--------------------------- - else:#-----------------------Pixel4 code------------------------- + else: #--------------Pixel 4 code-------------------------- report.step_start("Set Wifi Network to " + WifiName) # -----------------To Open Connections page----------------------- try: print("Verifying Connected Wifi Connection") - report.step_start("Click Network & internet") + report.step_start("Click Network & internet in pixel4") connElement = driver.find_element_by_xpath("//*[@text='Network & internet']") connElement.click() @@ -2528,20 +2945,19 @@ def wifi_disconnect_and_forget(request, WifiName, WifiPass, setup_perfectoMobile try: driver.implicitly_wait(1) get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='android:id/icon']") + "//*[@resource-id='android & iOS:id/icon']") get_switch_text = get_switch_text_element.click() if get_switch_text is not None: switch_text = "Off" else: switch_text = "On" - print("get_switch_text: ", switch_text) print("Find wifi switch") try: # To Turn on Wi-Fi Switch if switch_text == "Off": # driver.implicitly_wait(3) get_switch_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -2568,181 +2984,554 @@ def wifi_disconnect_and_forget(request, WifiName, WifiPass, setup_perfectoMobile pass if switch_text == "Off": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - # ---------------------This is to Forget current connected SSID------------------------------- - try: # To deal with already connected SSID + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + # ---------------------This is to Forget current connected SSID------------------------------- + try: # To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath("//*[@text='Connected']") + try: # To forget existing ssid + print("To forget ssid") check_if_no_internet_popup(driver) - network_category = driver.find_element_by_xpath("//*[@text='Connected']") - try: # To forget existing ssid - print("To forget ssid") - check_if_no_internet_popup(driver) - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") - additional_details_element.click() - try: - check_if_no_internet_popup(driver) - forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/button1']") - forget_ssid.click() - print("Forget old ssid") - except: - print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - except: - #allure.attach(name=body=str("Couldn't get into additional details")) - print("Couldn't get into additional details") + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") + additional_details_element.click() except: - #allure.attach(name=body=str("No Connected SSIDS")) - print("No Connected SSIDS") - #----------------------This is to Forget current connected SSID-------------------------------- + print("Couldn't get into additional details") + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/button1']") + forget_ssid.click() + print("Forget old ssid") + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + except: + print("No Connected SSIDS") + # ----------------------This is to Forget current connected SSID-------------------------------- + time.sleep(2) + print("Selecting Wifi: " + WifiName) + # allure.attach(name= body=str("Selecting Wifi: " + WifiName)) + ssid_found = False + available_ssids = False + # This is To get all available ssids + # ------------------------------------------------------ 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() + for k in range(5): + available_ssids = get_all_available_ssids(driver, deviceModelName) + print("active_ssid_list: ", available_ssids) + #allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + try: + if WifiName not in available_ssids: + scrollDown(setup_perfectoMobile) + time.sleep(2) + else: + ssid_found = True + print(WifiName + " : Found in Device") + # allure.attach(name= body=str(WifiName+" : Found in Device")) + break + except: + print("couldn't find wifi in available ssid") + if not ssid_found: + ssid_not_found = False + for k in range(5): + available_ssids = get_all_available_ssids(driver, deviceModelName) + print("active_ssid_list: ", available_ssids) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + try: + if WifiName not in available_ssids: + scroll_up(setup_perfectoMobile) + time.sleep(2) + else: + ssid_not_found = True + print(WifiName + " : Found in Device") + # allure.attach(name= body=str(WifiName+" : Found in Device")) + break + except: + print("couldn't find wifi in available ssid") + if not ssid_not_found: + print("could not found " + WifiName + " in device") + # allure.attach(name= body=str("could not found" + WifiName + " in device")) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet except: - print("couldn't click on wifi switch") - - - except NoSuchElementException: - print("No Switch element found") - # ---------------------To Turn on WIFi Switch if already OFF------------------------------- - - except NoSuchElementException: - print("Couldn't find wifi Button") - # ------------------Open WIFI page---------------------------------- + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + # ------------------------------------------------------- - except NoSuchElementException: - print("Exception: Verify Xpath - Update/check Xpath for Click Connections") + # Selecting WIFI + # ------------------------------------------------------- + try: + report.step_start("Selecting Wifi: " + WifiName) + wifiSelectionElement = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) + wifiSelectionElement.click() + check_if_no_internet_popup(driver) + except Exception as e: + print("Exception on Selecting Wifi Network. Please check wifi Name or signal") + request.config.cache.set(key="SelectingWifiFailed", value=str(e)) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + # ------------------------------------------------------- - closeApp(connData["appPackage-android"], setup_perfectoMobile) + # Set password if Needed + # ------------------------------------------------------- + try: + check_if_no_internet_popup(driver) + report.step_start("Set Wifi Password") + wifiPasswordElement = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/password']") + wifiPasswordElement.send_keys(WifiPass) + except NoSuchElementException: + print("Password Page Not Loaded, password May be cached in the System") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + # Click on connect button + # ------------------------------------------------------- + try: + report.step_start("Click Connect Button") + joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") + joinBTNElement.click() + except NoSuchElementException: + print("Connect Button Not Enabled...Verify if Password is set properly ") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + + # 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 & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + # time.sleep(5) + check_if_no_internet_popup(driver) + except: + try: + print("Not able to verify the connected WiFi. Scrolling up.") + scroll_up(setup_perfectoMobile) + scroll_up(setup_perfectoMobile) + # check_if_no_internet_popup(driver) + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.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") + print("Verifying after scrolling") + scroll_up(setup_perfectoMobile) + WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + except NoSuchElementException: + print("Wifi Connection Error: " + WifiName) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet -# try: -# elements = driver.find_elements_by_xpath("//*[@resource-id='com.android.settings:id/title']") -# print("elements: ", elements) -# print(len(elements)) -# for i in range(len(elements)): -# print("elements[i]", elements[i]) -# print("elements[i].text", elements[i].text) -# except: -# print("No SSIDS available") -def get_all_available_ssids(driver, deviceModelName): - active_ssid_list = [] + except NoSuchElementException: + print("No Switch element found") + # allure.attach(name= body=str("No Switch element found")) + # ---------------------To Turn on WIFi Switch if already OFF------------------------------- + + except NoSuchElementException: + print("Couldn't find wifi Button") + # allure.attach(name= body=str("Couldn't find wifi Button")) + # ------------------Open WIFI page---------------------------------- + + except NoSuchElementException: + print("Exception: Verify Xpath - Update/check Xpath for Click Connections") + # allure.attach(name= body=str("Exception: Verify Xpath - Update/check Xpath for Click Connections")) + # -----------------To Open Connections page--------------------------- + + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + +#To disconnect and forget network +def wifi_disconnect_and_forget(request, WifiName, WifiPass, setup_perfectoMobile, connData): + print("\n-------------------------------------") + print("WIFI Disconnect") + print("-------------------------------------") + #allure.attach(name= body=str("------------------- WIFI Disconnect ------------------")) + + report = setup_perfectoMobile[1] + driver = setup_perfectoMobile[0] + + report.step_start("Switching Driver Context") + print("Switching Context to Native") + contexts = driver.contexts + driver.switch_to.context(contexts[0]) + + # Open Settings Application + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + deviceModelName = getDeviceModelName(setup_perfectoMobile) print("Selected Device Model: " + deviceModelName) + if deviceModelName != ("Pixel 4"): + report.step_start("Set Wifi Network to " + WifiName) + + + # -----------------To Open Connections page----------------------- try: - time.sleep(8) - driver.implicitly_wait(10) - elements = driver.find_elements_by_xpath("//*[@resource-id='com.android.settings:id/title']") - # print("elements: ", elements) - print(len(elements)) - for i in range(len(elements)): - # print("elements[i]", elements[i]) - # print("elements[i].text", elements[i].text) - active_ssid_list.append(elements[i].text) - except: - print("No SSIDS available") - else: - try: - time.sleep(8) - driver.implicitly_wait(10) - elements = driver.find_elements_by_xpath("//*[@resource-id='android:id/title']") - # print("elements: ", elements) - print(len(elements)) - for i in range(len(elements)): - # print("elements[i]", elements[i]) - # print("elements[i].text", elements[i].text) + print("Verifying Connected Wifi Connection") + report.step_start("Click Connections") + connElement = driver.find_element_by_xpath("//*[@text='Connections']") + connElement.click() + + + # ---------------------Open WIFI page------------------------------- + try: + report.step_start("Clicking Wi-Fi") + print("Clicking WIFI") + wifiElement = driver.find_element_by_xpath("//*[@text='Wi-Fi']") + wifiElement.click() + + + # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: - active_ssid_list.append(elements[i].text) - except: - print("Encountered a cache SSID which is no longer in the DOM.Moving to next SSID.") - except: - print("No SSIDS available") - return active_ssid_list + driver.implicitly_wait(1) + get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_text']") + get_switch_text = get_switch_text_element.text + print("get_switch_text: ",get_switch_text) + print("Find wifi switch") + try: #To Turn on Wi-Fi Switch + if get_switch_text == "Off": + # driver.implicitly_wait(3) + get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget']") + driver.implicitly_wait(1) + get_switch_element.click() + driver.implicitly_wait(1) + i = 0 + for i in range(5): + if get_switch_text == "On": + print("WIFI Switch is ON") + break + else: + try: + get_switch_text_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") + get_switch_text = get_switch_text_element.text + except: + pass + print("Sleeping for: ", i) + time.sleep(i) + pass + if get_switch_text == "Off": + print("Switch is Still OFF") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + else: + print("Switch is already On") + check_if_no_internet_popup(driver) + except: + print("Couldn't turn on WIFI switch") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) -def reportClient(value): - global reporting_client # declare a to be a global - reporting_client = value # this sets the global value of a + #---------------------This is to Forget current connected SSID------------------------------- + try: #To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/connected_network_category']") + try: #To forget exhisting ssid + print("To forget ssid") + check_if_no_internet_popup(driver) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/layout_details']") + additional_details_element.click() + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") + forget_ssid.click() + print("Forget old ssid") + #allure.attach(name=body=str("Forget old ssid")) + except: + print("Couldn't forget ssid") + #allure.attach(name=body=str("Couldn't forget ssid")) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + except: + #allure.attach(name=body=str("Couldn't get into additional details")) + print("Couldn't get into additional details") + except: + #allure.attach(name=body=str("No Connected SSIDS")) + print("No Connected SSIDS") + #----------------------This is to Forget current connected SSID-------------------------------- -# This is a functon to get all of the ssid details -# This function needs to be called from a standalone script and not throuh testcase -# def get_all_available_ssids(): -# from appium import webdriver -# driver = None -# reporting_client = None -# -# warnings.simplefilter("ignore", ResourceWarning) -# urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) -# -# capabilities = { -# 'platformName': 'Android', -# 'model': 'Galaxy S9', -# 'browserName': 'mobileOS', -# # 'automationName' : 'Appium', -# 'securityToken': 'eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI3NzkzZGM0Ni1jZmU4LTQ4ODMtYjhiOS02ZWFlZGU2OTc2MDkifQ.eyJpYXQiOjE2MjE4NjgyOTksImp0aSI6IjIzNGFiOTM1LWIxYjQtNGZiOC1hZmJiLTM0OTQwNzU5MjIwMyIsImlzcyI6Imh0dHBzOi8vYXV0aDIucGVyZmVjdG9tb2JpbGUuY29tL2F1dGgvcmVhbG1zL3RpcC1wZXJmZWN0b21vYmlsZS1jb20iLCJhdWQiOiJodHRwczovL2F1dGgyLnBlcmZlY3RvbW9iaWxlLmNvbS9hdXRoL3JlYWxtcy90aXAtcGVyZmVjdG9tb2JpbGUtY29tIiwic3ViIjoiN2I1MzBhZTAtODgxOC00N2I5LTgzZjMtN2ZhMGZiMGRkYjRlIiwidHlwIjoiT2ZmbGluZSIsImF6cCI6Im9mZmxpbmUtdG9rZW4tZ2VuZXJhdG9yIiwibm9uY2UiOiI1MzI2NDQxNS0xYTQwLTQ1ZTctOGVkMi1hOTNiYWZmZWNjYjIiLCJzZXNzaW9uX3N0YXRlIjoiY2YzY2JlOGMtY2Y5OC00NzRlLWJmODctYTIxNzU0NzVhM2EzIiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSBvZmZsaW5lX2FjY2VzcyBlbWFpbCJ9.4a4v6AKxmY95Zb-l84K_Od49WPikwOHP7ryctfmnn-w', -# 'useAppiumForWeb': 'false', -# 'useAppiumForHybrid': 'false', -# # 'bundleId' : request.config.getini("appPackage-android"), -# } -# -# app_data = { -# "webURL": "https://www.google.com", -# "lblSearch": "//*[@class='gLFyf']", -# "elelSearch": "(//*[@class='sbic sb43'])[1]", -# "BtnRunSpeedTest": "//*[text()='RUN SPEED TEST']", -# "bundleId-iOS-Settings": 'com.apple.Preferences', -# "bundleId-iOS-Safari": 'com.apple.mobilesafari', -# "downloadMbps": "//*[@id='knowledge-verticals-internetspeedtest__download']/P[@class='spiqle']", -# "UploadMbps": "//*[@id='knowledge-verticals-internetspeedtest__upload']/P[@class='spiqle']", -# # Android -# "platformName-android": 'Android', -# "appPackage-android": 'com.android.settings' -# } -# -# driver = webdriver.Remote( -# "https://tip.perfectomobile.com/nexperience/perfectomobile/wd/hub", -# capabilities -# ) -# -# try: -# print(driver) -# driver.implicitly_wait(35) -# #Driver Ends here -# -# projectname = "TIP-PyTest-Execution" -# projectversion = 1.0 -# jobname = "tip-sushant-android" -# jobnumber = 2 -# tags = "TestTag" -# testCaseName = "getting_ssids" -# -# # print("\nSetting Perfecto ReportClient....") -# perfecto_execution_context = PerfectoExecutionContext(driver, tags, Job(jobname, jobnumber), -# Project(projectname, projectversion)) -# reporting_client = PerfectoReportiumClient(perfecto_execution_context) -# reporting_client.test_start(testCaseName, TestContext([], "Perforce")) -# reportClient(reporting_client) -# -# -# setup_perfectoMobile = (driver, reporting_client) -# print("setup_perfectoMobile_android: ", setup_perfectoMobile) -# print(type(setup_perfectoMobile)) -# -# print("\n-------------------------------------") -# print("Select Wifi/AccessPoint Connection") -# print("-------------------------------------") -# print("Verifying Wifi Connection Details....") -# report = setup_perfectoMobile[1] + try: + print("clicking on wifi switch") + get_switch_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") + driver.implicitly_wait(2) + get_switch_element.click() + except: + print("couldn't click on wifi switch") + + + except NoSuchElementException: + print("No Switch element found") + # ---------------------To Turn on WIFi Switch if already OFF------------------------------- + + except NoSuchElementException: + print("Couldn't find wifi Button") + # ------------------Open WIFI page---------------------------------- + + except NoSuchElementException: + print("Exception: Verify Xpath - Update/check Xpath for Click Connections") + # -----------------To Open Connections page--------------------------- + else:#-----------------------Pixel4 code------------------------- + report.step_start("Set Wifi Network to " + WifiName) + + # -----------------To Open Connections page----------------------- + try: + print("Verifying Connected Wifi Connection") + report.step_start("Click Network & internet") + connElement = driver.find_element_by_xpath("//*[@text='Network & internet']") + connElement.click() + + # ---------------------Open WIFI page------------------------------- + try: + report.step_start("Clicking Wi-Fi") + print("Clicking WIFI") + time.sleep(3) + wifiElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Wi‑Fi']"))) + wifiElement.click() + + # --------------------To Turn on WIFi Switch if already OFF-------------------------------- + try: + driver.implicitly_wait(1) + get_switch_text_element = driver.find_element_by_xpath( + "//*[@resource-id='android & iOS:id/icon']") + get_switch_text = get_switch_text_element.click() + if get_switch_text is not None: + switch_text = "Off" + else: + switch_text = "On" + + print("get_switch_text: ", switch_text) + print("Find wifi switch") + try: # To Turn on Wi-Fi Switch + if switch_text == "Off": + # driver.implicitly_wait(3) + get_switch_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") + driver.implicitly_wait(1) + get_switch_element.click() + driver.implicitly_wait(1) + i = 0 + for i in range(5): + if switch_text == "On": + print("WIFI Switch is ON") + break + else: + try: + get_switch_text_element = driver.find_element_by_xpath( + "//*[@text='Add network']") + get_switch_text = get_switch_text_element.text + if get_switch_text == "Add network": + switch_text = "On" + else: + switch_text = "Off" + except NoSuchElementException: + print("Exception: Verify Xpath") + # Scroll Down + scrollDown(setup_perfectoMobile) + print("Sleeping for: ", i) + time.sleep(i) + pass + if switch_text == "Off": + print("Switch is Still OFF") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + else: + print("Switch is already On") + check_if_no_internet_popup(driver) + except: + print("Couldn't turn on WIFI switch") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + # ---------------------This is to Forget current connected SSID------------------------------- + try: # To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath("//*[@text='Connected']") + try: # To forget existing ssid + print("To forget ssid") + check_if_no_internet_popup(driver) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") + additional_details_element.click() + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/button1']") + forget_ssid.click() + print("Forget old ssid") + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + except: + #allure.attach(name=body=str("Couldn't get into additional details")) + print("Couldn't get into additional details") + except: + #allure.attach(name=body=str("No Connected SSIDS")) + print("No Connected SSIDS") + #----------------------This is to Forget current connected SSID-------------------------------- + + try: + print("clicking on wifi switch") + get_switch_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") + driver.implicitly_wait(2) + get_switch_element.click() + except: + print("couldn't click on wifi switch") + + + except NoSuchElementException: + print("No Switch element found") + # ---------------------To Turn on WIFi Switch if already OFF------------------------------- + + except NoSuchElementException: + print("Couldn't find wifi Button") + # ------------------Open WIFI page---------------------------------- + + except NoSuchElementException: + print("Exception: Verify Xpath - Update/check Xpath for Click Connections") + + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + + + +# try: +# elements = driver.find_elements_by_xpath("//*[@resource-id='com.android & iOS.settings:id/title']") +# print("elements: ", elements) +# print(len(elements)) +# for i in range(len(elements)): +# print("elements[i]", elements[i]) +# print("elements[i].text", elements[i].text) +# except: +# print("No SSIDS available") +def get_all_available_ssids(driver, deviceModelName): + active_ssid_list = [] + print("Selected Device Model: " + deviceModelName) + if deviceModelName != ("Pixel 4"): + try: + time.sleep(8) + driver.implicitly_wait(10) + elements = driver.find_elements_by_xpath("//*[@resource-id='com.android & iOS.settings:id/title']") + # print("elements: ", elements) + print(len(elements)) + for i in range(len(elements)): + # print("elements[i]", elements[i]) + # print("elements[i].text", elements[i].text) + active_ssid_list.append(elements[i].text) + except: + print("No SSIDS available") + else: + try: + time.sleep(8) + driver.implicitly_wait(10) + elements = driver.find_elements_by_xpath("//*[@resource-id='android & iOS:id/title']") + # print("elements: ", elements) + print(len(elements)) + for i in range(len(elements)): + # print("elements[i]", elements[i]) + # print("elements[i].text", elements[i].text) + try: + active_ssid_list.append(elements[i].text) + except: + print("Encountered a cache SSID which is no longer in the DOM.Moving to next SSID.") + except: + print("No SSIDS available") + return active_ssid_list + +def reportClient(value): + global reporting_client # declare a to be a global + reporting_client = value # this sets the global value of a + +# This is a functon to get all of the ssid details +# This function needs to be called from a standalone script and not throuh testcase +# def get_all_available_ssids(): +# from appium import webdriver +# driver = None +# reporting_client = None +# +# warnings.simplefilter("ignore", ResourceWarning) +# urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) +# +# capabilities = { +# 'platformName': 'Android', +# 'model': 'Galaxy S9', +# 'browserName': 'mobileOS', +# # 'automationName' : 'Appium', +# 'securityToken': 'eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI3NzkzZGM0Ni1jZmU4LTQ4ODMtYjhiOS02ZWFlZGU2OTc2MDkifQ.eyJpYXQiOjE2MjE4NjgyOTksImp0aSI6IjIzNGFiOTM1LWIxYjQtNGZiOC1hZmJiLTM0OTQwNzU5MjIwMyIsImlzcyI6Imh0dHBzOi8vYXV0aDIucGVyZmVjdG9tb2JpbGUuY29tL2F1dGgvcmVhbG1zL3RpcC1wZXJmZWN0b21vYmlsZS1jb20iLCJhdWQiOiJodHRwczovL2F1dGgyLnBlcmZlY3RvbW9iaWxlLmNvbS9hdXRoL3JlYWxtcy90aXAtcGVyZmVjdG9tb2JpbGUtY29tIiwic3ViIjoiN2I1MzBhZTAtODgxOC00N2I5LTgzZjMtN2ZhMGZiMGRkYjRlIiwidHlwIjoiT2ZmbGluZSIsImF6cCI6Im9mZmxpbmUtdG9rZW4tZ2VuZXJhdG9yIiwibm9uY2UiOiI1MzI2NDQxNS0xYTQwLTQ1ZTctOGVkMi1hOTNiYWZmZWNjYjIiLCJzZXNzaW9uX3N0YXRlIjoiY2YzY2JlOGMtY2Y5OC00NzRlLWJmODctYTIxNzU0NzVhM2EzIiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSBvZmZsaW5lX2FjY2VzcyBlbWFpbCJ9.4a4v6AKxmY95Zb-l84K_Od49WPikwOHP7ryctfmnn-w', +# 'useAppiumForWeb': 'false', +# 'useAppiumForHybrid': 'false', +# # 'bundleId' : request.config.getini("appPackage-android & iOS"), +# } +# +# app_data = { +# "webURL": "https://www.google.com", +# "lblSearch": "//*[@class='gLFyf']", +# "elelSearch": "(//*[@class='sbic sb43'])[1]", +# "BtnRunSpeedTest": "//*[text()='RUN SPEED TEST']", +# "bundleId-iOS-Settings": 'com.apple.Preferences', +# "bundleId-iOS-Safari": 'com.apple.mobilesafari', +# "downloadMbps": "//*[@id='knowledge-verticals-internetspeedtest__download']/P[@class='spiqle']", +# "UploadMbps": "//*[@id='knowledge-verticals-internetspeedtest__upload']/P[@class='spiqle']", +# # Android +# "platformName-android & iOS": 'Android', +# "appPackage-android & iOS": 'com.android & iOS.settings' +# } +# +# driver = webdriver.Remote( +# "https://tip.perfectomobile.com/nexperience/perfectomobile/wd/hub", +# capabilities +# ) +# +# try: +# print(driver) +# driver.implicitly_wait(35) +# #Driver Ends here +# +# projectname = "TIP-PyTest-Execution" +# projectversion = 1.0 +# jobname = "tip-sushant-android & iOS" +# jobnumber = 2 +# tags = "TestTag" +# testCaseName = "getting_ssids" +# +# # print("\nSetting Perfecto ReportClient....") +# perfecto_execution_context = PerfectoExecutionContext(driver, tags, Job(jobname, jobnumber), +# Project(projectname, projectversion)) +# reporting_client = PerfectoReportiumClient(perfecto_execution_context) +# reporting_client.test_start(testCaseName, TestContext([], "Perforce")) +# reportClient(reporting_client) +# +# +# setup_perfectoMobile = (driver, reporting_client) +# print("setup_perfectoMobile_android: ", setup_perfectoMobile) +# print(type(setup_perfectoMobile)) +# +# print("\n-------------------------------------") +# print("Select Wifi/AccessPoint Connection") +# print("-------------------------------------") +# print("Verifying Wifi Connection Details....") +# report = setup_perfectoMobile[1] # driver = setup_perfectoMobile[0] # # @@ -2759,7 +3548,7 @@ def reportClient(value): # print("1508") # # # Open Settings Application -# openApp(app_data["appPackage-android"], setup_perfectoMobile) +# openApp(app_data["appPackage-android & iOS"], setup_perfectoMobile) # # deviceModelName = driver.execute_script('mobile:handset:info', {'property': 'model'}) # @@ -2785,7 +3574,7 @@ def reportClient(value): # try: # driver.implicitly_wait(1) # get_switch_text_element = driver.find_element_by_xpath( -# "//*[@resource-id='com.android.settings:id/switch_text']") +# "//*[@resource-id='com.android & iOS.settings:id/switch_text']") # get_switch_text = get_switch_text_element.text # print("get_switch_text: ", get_switch_text) # # print("Find wifi switch") @@ -2793,7 +3582,7 @@ def reportClient(value): # if get_switch_text == "Off": # # driver.implicitly_wait(3) # get_switch_element = driver.find_element_by_xpath( -# "//*[@resource-id='com.android.settings:id/switch_widget']") +# "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") # # driver.implicitly_wait(1) # get_switch_element.click() # driver.implicitly_wait(1) @@ -2805,7 +3594,7 @@ def reportClient(value): # else: # try: # get_switch_text_element = driver.find_element_by_xpath( -# "//*[@resource-id='com.android.settings:id/switch_text']") +# "//*[@resource-id='com.android & iOS.settings:id/switch_text']") # get_switch_text = get_switch_text_element.text # except: # pass @@ -2814,7 +3603,7 @@ def reportClient(value): # pass # if get_switch_text == "Off": # print("Switch is Still OFF") -# closeApp(app_data["appPackage-android"], setup_perfectoMobile) +# closeApp(app_data["appPackage-android & iOS"], setup_perfectoMobile) # close_driver(driver) # return ip_address_element_text # else: @@ -2822,7 +3611,7 @@ def reportClient(value): # check_if_no_internet_popup(driver) # except: # print("Couldn't turn on WIFI sewitch") -# closeApp(app_data["appPackage-android"], setup_perfectoMobile) +# closeApp(app_data["appPackage-android & iOS"], setup_perfectoMobile) # close_driver(driver) # return ip_address_element_text # @@ -2830,22 +3619,22 @@ def reportClient(value): # try: # To deal with already connected SSID # check_if_no_internet_popup(driver) # network_category = driver.find_element_by_xpath( -# "//*[@resource-id='com.android.settings:id/connected_network_category']") +# "//*[@resource-id='com.android & iOS.settings:id/connected_network_category']") # try: # To forget exhisting ssid # print("To forget exhisting ssid") # check_if_no_internet_popup(driver) # additional_details_element = driver.find_element_by_xpath( -# "//*[@resource-id='com.android.settings:id/layout_details']") +# "//*[@resource-id='com.android & iOS.settings:id/layout_details']") # additional_details_element.click() # 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']") +# "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") # forget_ssid.click() # print("Forget old ssid") # except: # print("Couldn't forget ssid") -# closeApp(app_data["appPackage-android"], setup_perfectoMobile) +# closeApp(app_data["appPackage-android & iOS"], setup_perfectoMobile) # close_driver(driver) # return ip_address_element_text # except: @@ -2869,7 +3658,7 @@ def reportClient(value): # try: # try: # elements = driver.find_elements_by_xpath( -# "//*[@resource-id='com.android.settings:id/title']") +# "//*[@resource-id='com.android & iOS.settings:id/title']") # print("elements: ", elements) # print(len(elements)) # curent_ssid_list = [] @@ -2919,7 +3708,7 @@ def reportClient(value): # # except: # try: -# closeApp(app_data["appPackage-android"], setup_perfectoMobile) +# closeApp(app_data["appPackage-android & iOS"], setup_perfectoMobile) # except: # pass # try: @@ -2951,7 +3740,856 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM report = setup_perfectoMobile[1] driver = setup_perfectoMobile[0] - ip_address_element_text = False + ip_address_element_text = False + ssid_with_internet = False + + report.step_start("Switching Driver Context") + print("Switching Context to Native") + contexts = driver.contexts + driver.switch_to.context(contexts[0]) + + # Open Settings Application + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + deviceModelName = getDeviceModelName(setup_perfectoMobile) + print("Selected Device Model: " + deviceModelName) + + if deviceModelName != ("Pixel 4"): + report.step_start("Set Wifi Network to " + WifiName) + + + # -----------------To Open Connections page----------------------- + try: + print("Verifying Connected Wifi Connection") + report.step_start("Click Connections") + connElement = driver.find_element_by_xpath("//*[@text='Connections']") + connElement.click() + + + # ---------------------Open WIFI page------------------------------- + try: + report.step_start("Clicking Wi-Fi") + print("Clicking WIFI") + time.sleep(3) + wifiElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH,"//*[@text='Wi-Fi']"))) + wifiElement.click() + + + # --------------------To Turn on WIFi Switch if already OFF-------------------------------- + try: + driver.implicitly_wait(1) + get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_text']") + get_switch_text = get_switch_text_element.text + print("get_switch_text: ",get_switch_text) + print("Find wifi switch") + try: #To Turn on Wi-Fi Switch + if get_switch_text == "Off": + # driver.implicitly_wait(3) + get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget']") + driver.implicitly_wait(1) + get_switch_element.click() + driver.implicitly_wait(1) + i = 0 + for i in range(5): + if get_switch_text == "On": + print("WIFI Switch is ON") + break + else: + try: + get_switch_text_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") + get_switch_text = get_switch_text_element.text + except: + pass + print("Sleeping for: ", i) + time.sleep(i) + pass + if get_switch_text == "Off": + print("Switch is Still OFF") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + else: + print("Switch is already On") + check_if_no_internet_popup(driver) + except: + print("Couldn't turn on WIFI switch") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + + #---------------------This is to Forget current connected SSID------------------------------- + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, search_this="osVersion") != "12": + try: #To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/connected_network_category']") + try: #To forget exhisting ssid + print("To forget ssid") + check_if_no_internet_popup(driver) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/layout_details']") + additional_details_element.click() + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") + forget_ssid.click() + print("Forget old ssid") + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into additional details") + except: + print("No Connected SSIDS") + else: + try: #To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]") + try: #To forget exhisting ssid + print("To forget ssid in osversion 12") + check_if_no_internet_popup(driver) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/wifi_details']") + additional_details_element.click() + try: + print("To forget ssid in os version 12") + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/navigation_bar_item_icon_view']") + forget_ssid.click() + print("Forget old ssid") + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into additional details") + except: + print("No Connected SSIDS") + #----------------------This is to Forget current connected SSID-------------------------------- + + time.sleep(2) + print("Selecting Wifi: " + WifiName) + #allure.attach(name= body=str("Selecting Wifi: " + WifiName)) + ssid_found = False + available_ssids = False + #This is To get all available ssids + #------------------------------------------------------ + try: + for k in range(10): + available_ssids = get_all_available_ssids(driver, deviceModelName) + print("active_ssid_list: ", available_ssids) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + try: + if WifiName not in available_ssids: + scrollDown(setup_perfectoMobile) + time.sleep(2) + else: + ssid_found = True + print(WifiName+" : Found in Device") + #allure.attach(name= body=str(WifiName+" : Found in Device")) + break + except: + print("couldn't find wifi in available ssid") + if not ssid_found: + print("could not found " + WifiName + " in device") + #allure.attach(name= body=str("could not found" + WifiName + " in device")) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + #------------------------------------------------------- + + # Selecting WIFI + # ------------------------------------------------------- + try: + report.step_start("Selecting Wifi: " + WifiName) + print("Selecting Wifi") + wifiSelectionElement = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) + wifiSelectionElement.click() + check_if_no_internet_popup(driver) + except Exception as e: + print("Exception on Selecting Wifi Network. Please check wifi Name or signal") + request.config.cache.set(key="SelectingWifiFailed", value=str(e)) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + # ------------------------------------------------------- + + # Set username + # ------------------------------------------------------- + try: + # driver.implicitly_wait(3) + report.step_start("Set User name") + print("Set User name") + wifiUserElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='com.android & iOS.settings:id/edittext' and @password='false']"))) + wifiUserElement.send_keys(User) + except NoSuchElementException: + print("User name not Loaded") + # ------------------------------------------------------- + + # Set Password + # ------------------------------------------------------- + try: + # driver.implicitly_wait(6) + report.step_start("Set Password") + print("Set Password") + wifiPasswordElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Enter password']"))) + wifiPasswordElement.send_keys(ttls_passwd) + print("Entered Password") + except NoSuchElementException: + print("Password Page Not Loaded, password May be cached in the System") + # ------------------------------------------------------- + # Selecting certificate + # ------------------------------------------------------- + try: + # driver.implicitly_wait(3) + report.step_start("Selecting CA Cert") + print("Selecting CA Cert") + certElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Select certificate']"))) + certElement.click() + except NoSuchElementException: + print("Selecting certificate failed") + # ------------------------------------------------------- + # Validating certificate + # ------------------------------------------------------- + try: + # driver.implicitly_wait(3) + report.step_start("Validting CA Cert") + print("Validting CA Cert") + certElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text=\"Don't validate\"]"))) + certElement.click() + except NoSuchElementException: + print("validation failed") + # ------------------------------------------------------- + if (deviceModelName == "Galaxy S9"): + driver.hide_keyboard() + print("Hide keyboard") + # Click on connect button + # ------------------------------------------------------- + try: + # driver.implicitly_wait(3) + report.step_start("Click Connect Button") + print("Click Connect Button") + joinBTNElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Connect']"))) + joinBTNElement.click() + except NoSuchElementException: + print("Connect Button Not Enabled...Verify if Password is set properly ") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + + #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 & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + # time.sleep(5) + check_if_no_internet_popup(driver) + except: + try: + check_if_no_internet_popup(driver) + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.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") + WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + except NoSuchElementException: + print("Wifi Connection Error: " + WifiName) + closeApp(connData["appPackage-android & iOS"], 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 + # ------------------------------------------------------- + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, + search_this="osVersion") != "12": + try: + print("Into additional details") + time.sleep(2) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.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 & iOS.widget.TextView[@resource-id='com.android & iOS.settings:id/summary']") + ip_address_element_text = ip_address_element.text + print("Device IP address is :", ip_address_element_text) + except: + try: + time.sleep(2) + ip_address_element = driver.find_element_by_xpath( + "//*[@text='IP address']/parent::*/android & iOS.widget.TextView[@resource-id='android & iOS: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 & iOS"], 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 & iOS.widget.TextView[@resource-id='com.android & iOS.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 & iOS.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 & iOS"], setup_perfectoMobile) + assert False + if (ssid_name_element_text == WifiName): + print("Wifi is connected to the expected ssid") + else: + print("Wifi is not connected to the expected ssid") + closeApp(connData["appPackage-android & iOS"], 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 & iOS: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 & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.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 & iOS.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 & iOS"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet + except: + 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 & iOS.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 & iOS.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 & iOS"], 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 & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[4]/android & iOS.widget.RelativeLayout[1]/android & iOS.widget.TextView[2]") + ip_address_element_text = ip_address_element_text.text + ssid_with_internet = True + except: + 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 & iOS.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 & iOS"], 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------------------------------- + + except: + print("Couldn't find wifi Button") + # ------------------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) + + # -----------------To Open Connections page----------------------- + try: + print("Verifying Connected Wifi Connection in Pixel") + report.step_start("Click Network & internet in pixel4") + conn_element = driver.find_element_by_xpath("//*[@text='Network & internet']") + conn_element.click() + + # ---------------------Open WIFI page------------------------------- + try: + report.step_start("Clicking Wi-Fi") + print("Clicking WIFI") + time.sleep(3) + wifi_element = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Wi‑Fi']"))) + wifi_element.click() + + # --------------------To Turn on WIFi Switch if already OFF-------------------------------- + try: + driver.implicitly_wait(1) + get_switch_text_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") + get_switch_text = get_switch_text_element.text + # if get_switch_text is not None: + # switch_text = "OFF" + # else: + # switch_text = "ON" + switch_text = get_switch_text + print("get_switch_text: ", switch_text) + print("Find wifi switch") + try: # To Turn on Wi-Fi Switch + if switch_text == "OFF": + # driver.implicitly_wait(3) + get_switch_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") + driver.implicitly_wait(1) + get_switch_element.click() + driver.implicitly_wait(1) + i = 0 + for i in range(5): + if switch_text == "ON": + print("WIFI Switch is ON") + break + else: + try: + get_switch_text_element = driver.find_element_by_xpath( + "//*[@text='Add network']") + get_switch_text = get_switch_text_element.text + if get_switch_text == "Add network": + switch_text = "ON" + else: + switch_text = "OFF" + except NoSuchElementException: + print("Exception: Verify Xpath") + # Scroll Down + scrollDown(setup_perfectoMobile) + print("Sleeping for: ", i) + time.sleep(i) + pass + if switch_text == "OFF": + print("Switch is Still OFF") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + else: + print("Switch is already On") + check_if_no_internet_popup(driver) + except: + print("Couldn't turn on WIFI switch") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + + # ---------------------This is to Forget current connected SSID------------------------------- + try: # To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath("//*[@text='Connected']") + try: # To forget existing ssid + print("To forget ssid") + check_if_no_internet_popup(driver) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") + additional_details_element.click() + except: + print("Couldn't get into additional details") + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/button1']") + forget_ssid.click() + print("Forget old ssid") + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + print("No Connected SSIDS") + # ----------------------This is to Forget current connected SSID-------------------------------- + + time.sleep(2) + print("Selecting Wifi: " + WifiName) + # allure.attach(name= body=str("Selecting Wifi: " + WifiName)) + ssid_found = False + available_ssids = False + # This is To get all available ssids + # ------------------------------------------------------ + try: + for k in range(5): + available_ssids = get_all_available_ssids(driver, deviceModelName) + print("active_ssid_list: ", available_ssids) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + try: + if WifiName not in available_ssids: + scrollDown(setup_perfectoMobile) + time.sleep(2) + else: + ssid_found = True + print(WifiName + " : Found in Device") + # allure.attach(name= body=str(WifiName+" : Found in Device")) + break + except: + print("couldn't find wifi in available ssid") + if not ssid_found: + ssid_not_found = False + for k in range(5): + available_ssids = get_all_available_ssids(driver, deviceModelName) + print("active_ssid_list: ", available_ssids) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + try: + if WifiName not in available_ssids: + scroll_up(setup_perfectoMobile) + time.sleep(2) + else: + ssid_not_found = True + print(WifiName + " : Found in Device") + # allure.attach(name= body=str(WifiName+" : Found in Device")) + break + except: + print("couldn't find wifi in available ssid") + if not ssid_not_found: + print("could not found " + WifiName + " in device") + # allure.attach(name= body=str("could not found" + WifiName + " in device")) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + # ------------------------------------------------------- + # ------------------------------------------------------- + + # Selecting WIFI + # ------------------------------------------------------- + try: + report.step_start("Selecting Wifi: " + WifiName) + wifi_selection_element = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) + wifi_selection_element.click() + check_if_no_internet_popup(driver) + except Exception as e: + print("Exception on Selecting Wifi Network. Please check wifi Name or signal") + request.config.cache.set(key="SelectingWifiFailed", value=str(e)) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + # ------------------------------------------------------- + # ------------------------------------------------------- + # Selecting certificate + # ------------------------------------------------------- + try: + driver.implicitly_wait(3) + report.step_start("Selecting CA Cert") + print("Selecting certificate") + cert_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/ca_cert']") + cert_element.click() + except NoSuchElementException: + print("Selecting certificate failed") + # ------------------------------------------------------- + # Validating certificate + # ------------------------------------------------------- + try: + driver.implicitly_wait(3) + report.step_start("Validting CA Cert") + print("validation") + cert_element = driver.find_element_by_xpath( + "//*[@text='Do not validate']") + cert_element.click() + except NoSuchElementException: + print("validation failed") + # Set username + # ------------------------------------------------------- + try: + driver.implicitly_wait(3) + report.step_start("Set User name") + print("Set User name") + wifi_user_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/identity']") + wifi_user_element.send_keys(User) + except NoSuchElementException: + print("User name not Loaded") + # ------------------------------------------------------- + # Scroll Down + scroll_down_pixel(setup_perfectoMobile) + time.sleep(2) + # Set Password + # ------------------------------------------------------- + try: + check_if_no_internet_popup(driver) + report.step_start("Set Wifi Password") + print("Entering password") + wifiPasswordElement = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/password']") + wifiPasswordElement.send_keys(ttls_passwd) + except NoSuchElementException: + print("Password Page Not Loaded, password May be cached in the System") + check_if_no_internet_popup(driver) + + # ------------------------------------------------------- + + # Click on connect button + # ------------------------------------------------------- + try: + driver.implicitly_wait(3) + report.step_start("Click Connect Button") + print("Click Connect Button") + join_element = driver.find_element_by_xpath("//*[@text='Connect']") + join_element.click() + except NoSuchElementException: + print("Connect Button Not Enabled...Verify if Password is set properly ") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + + # 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 & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + # time.sleep(5) + check_if_no_internet_popup(driver) + except: + try: + print("Not able to verify the connected WiFi. Scrolling up.") + scroll_up(setup_perfectoMobile) + scroll_up(setup_perfectoMobile) + check_if_no_internet_popup(driver) + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.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") + scroll_up(setup_perfectoMobile) + WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + except NoSuchElementException: + print("Wifi Connection Error: " + WifiName) + closeApp(connData["appPackage-android & iOS"], 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 + # ------------------------------------------------------- + try: + print("Into additional details") + time.sleep(5) + report.step_start("Going for ip address") + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") + additional_details_element.click() + print("Entered ssid") + try: + time.sleep(10) + print("clicking Advanced") + report.step_start("clicking Advanced") + advanced_element = driver.find_element_by_xpath("//*[@text='Advanced']") + advanced_element.click() + print("clicked Advanced") + #print("Device IP address is :", ip_address_element_text) + except: + try: + time.sleep(5) + print("clicking Advanced2") + advanced_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.FrameLayout[2]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[1]") + advanced_element.click() + #print("Device IP address is :", ip_address_element_text) + except: + try: + time.sleep(5) + print("clicking Advanced2") + advanced_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[5]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.ImageView[1]") + advanced_element.click() + except: + print("No advanced options") + # allure.attach(name= body=str("IP address element not found")) + + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet + # Scroll Down + scrollDown(setup_perfectoMobile) + try: + time.sleep(2) + ip_address_element = driver.find_element_by_xpath( + "//*[@text='IP address']/parent::*/android & iOS.widget.TextView[@resource-id='android & iOS: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") + #------------------------------- Forget SSID ---------------- + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") + 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 & iOS.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")) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet + except: + print("Couldn't forget ssid") + except: + print("Couldn't get into Additional settings") + # ------------------------------------------------------- + except: + print("No Switch element found") + # ---------------------To Turn on WIFi Switch if already OFF------------------------------- + + except: + print("Couldn't find wifi Button") + # ------------------Open WIFI page---------------------------------- + + except: + print("Exception: Verify Xpath - Update/check Xpath for Click Connections") + # -----------------To Open Connections page--------------------------- + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet +#only to connect to wifi +def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, connData): + print("\n-------------------------------------") + print("Select Wifi/AccessPoint Connection") + print("-------------------------------------") + print("Verifying Wifi Connection Details....") + #allure.attach(name= body=str("\n-------------------------------------")) + report = setup_perfectoMobile[1] + driver = setup_perfectoMobile[0] + ssid_with_internet = False report.step_start("Switching Driver Context") @@ -2960,10 +4598,10 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM driver.switch_to.context(contexts[0]) # Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print("Selected Device Model: " + deviceModelName) - + #allure.attach(name= body=str("\Selected Device Model: " + deviceModelName)) if deviceModelName != ("Pixel 4"): report.step_start("Set Wifi Network to " + WifiName) @@ -2980,23 +4618,21 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM try: report.step_start("Clicking Wi-Fi") print("Clicking WIFI") - time.sleep(3) - wifiElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH,"//*[@text='Wi-Fi']"))) + wifiElement = driver.find_element_by_xpath("//*[@text='Wi-Fi']") wifiElement.click() # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) - get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_text']") + get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text print("get_switch_text: ",get_switch_text) print("Find wifi switch") try: #To Turn on Wi-Fi Switch if get_switch_text == "Off": # driver.implicitly_wait(3) - get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_widget']") + get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -3008,7 +4644,7 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM else: try: get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_text']") + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text except: pass @@ -3017,102 +4653,76 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM pass if get_switch_text == "Off": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet #---------------------This is to Forget current connected SSID------------------------------- - if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, search_this="osVersion") != "12": - try: #To deal with already connected SSID - check_if_no_internet_popup(driver) - network_category = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/connected_network_category']") - try: #To forget exhisting ssid - print("To forget ssid") - check_if_no_internet_popup(driver) - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") - additional_details_element.click() - 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("Forget old ssid") - 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 details") - except: - print("No Connected SSIDS") - else: - try: #To deal with already connected SSID + try: #To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/connected_network_category']") + try: #To forget exhisting ssid + print("To forget ssid") check_if_no_internet_popup(driver) - network_category = driver.find_element_by_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]") - try: #To forget exhisting ssid - print("To forget ssid in osversion 12") - check_if_no_internet_popup(driver) - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/wifi_details']") - additional_details_element.click() - try: - print("To forget ssid in os version 12") - 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/navigation_bar_item_icon_view']") - forget_ssid.click() - print("Forget old ssid") - except: - print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/layout_details']") + additional_details_element.click() + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") + forget_ssid.click() + print("Forget old ssid") except: - print("Couldn't get into additional details") + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet except: - print("No Connected SSIDS") + print("Couldn't get into additional details") + except: + print("No Connected SSIDS") #----------------------This is to Forget current connected SSID-------------------------------- + + print("Searching for Wifi: " + WifiName) + #allure.attach(name= body=str("Searching for Wifi: " + WifiName)) time.sleep(2) print("Selecting Wifi: " + WifiName) - #allure.attach(name= body=str("Selecting Wifi: " + WifiName)) ssid_found = False available_ssids = False - #This is To get all available ssids - #------------------------------------------------------ + # This is To get all available ssids + # ------------------------------------------------------ try: - for k in range(10): + for check_for_all_ssids in range(2): available_ssids = get_all_available_ssids(driver, deviceModelName) - print("active_ssid_list: ", available_ssids) - allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) try: if WifiName not in available_ssids: scrollDown(setup_perfectoMobile) time.sleep(2) else: ssid_found = True - print(WifiName+" : Found in Device") - #allure.attach(name= body=str(WifiName+" : Found in Device")) + print(WifiName + " : Found in Device") + #allure.attach(name= body=str(WifiName + " : Found in Device")) break except: - print("couldn't find wifi in available ssid") + print("1538") + pass if not ssid_found: - print("could not found " + WifiName + " in device") + print("could not found" + WifiName + " in device") #allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet - #------------------------------------------------------- + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + # ------------------------------------------------------- # Selecting WIFI # ------------------------------------------------------- @@ -3126,320 +4736,129 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM except Exception as e: print("Exception on Selecting Wifi Network. Please check wifi Name or signal") request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet - # ------------------------------------------------------- - - # Set username - # ------------------------------------------------------- - try: - # driver.implicitly_wait(3) - report.step_start("Set User name") - print("Set User name") - wifiUserElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='com.android.settings:id/edittext' and @password='false']"))) - wifiUserElement.send_keys(User) - except NoSuchElementException: - print("User name not Loaded") - # ------------------------------------------------------- - - # Set Password - # ------------------------------------------------------- - try: - # driver.implicitly_wait(6) - report.step_start("Set Password") - print("Set Password") - wifiPasswordElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Enter password']"))) - wifiPasswordElement.send_keys(ttls_passwd) - print("Entered Password") - except NoSuchElementException: - print("Password Page Not Loaded, password May be cached in the System") - # ------------------------------------------------------- - # Selecting certificate - # ------------------------------------------------------- - try: - # driver.implicitly_wait(3) - report.step_start("Selecting CA Cert") - print("Selecting CA Cert") - certElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Select certificate']"))) - certElement.click() - except NoSuchElementException: - print("Selecting certificate failed") - # ------------------------------------------------------- - # Validating certificate - # ------------------------------------------------------- - try: - # driver.implicitly_wait(3) - report.step_start("Validting CA Cert") - print("Validting CA Cert") - certElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text=\"Don't validate\"]"))) - certElement.click() - except NoSuchElementException: - print("validation failed") - # ------------------------------------------------------- - if (deviceModelName == "Galaxy S9"): - driver.hide_keyboard() - print("Hide keyboard") - # Click on connect button - # ------------------------------------------------------- - try: - # driver.implicitly_wait(3) - report.step_start("Click Connect Button") - print("Click Connect Button") - joinBTNElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Connect']"))) - joinBTNElement.click() - except NoSuchElementException: - print("Connect Button Not Enabled...Verify if Password is set properly ") - check_if_no_internet_popup(driver) - # ------------------------------------------------------- - - #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: - try: - 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") - 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 - # ------------------------------------------------------- - - # Get into Additional Details - # To Get an IP Address - # To Forget connection - # To turn off auto. connect - # ------------------------------------------------------- - if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, - search_this="osVersion") != "12": - 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() - try: - 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: - 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("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 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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + # ------------------------------------------------------- - 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) + # Set username + # ------------------------------------------------------- + try: + driver.implicitly_wait(3) + report.step_start("Set User name") + print("Set User name") + wifiUserElement = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/edittext' and @password='false']") + wifiUserElement.send_keys(User) + except NoSuchElementException: + print("User name not Loaded") + # ------------------------------------------------------- - 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) + # Set Password + # ------------------------------------------------------- + try: + driver.implicitly_wait(6) + report.step_start("Set Password") + print("Set Password") + wifiPasswordElement = driver.find_element_by_xpath( + "//*[@text='Enter password']") + wifiPasswordElement.send_keys(ttls_passwd) + print("Entered Password") + except NoSuchElementException: + print("Password Page Not Loaded, password May be cached in the System") + # ------------------------------------------------------- + # Selecting certificate + # ------------------------------------------------------- + try: + driver.implicitly_wait(3) + report.step_start("Selecting CA Cert") + certElement = driver.find_element_by_xpath( + "//*[@text='Select certificate']") + certElement.click() + except NoSuchElementException: + print("Selecting certificate failed") + # ------------------------------------------------------- + # Validating certificate + # ------------------------------------------------------- + try: + driver.implicitly_wait(3) + report.step_start("Validting CA Cert") + certElement = driver.find_element_by_xpath( + "//*[@text=\"Don't validate\"]") + certElement.click() + except NoSuchElementException: + print("validation failed") + # ------------------------------------------------------- - 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") + # Click on connect button + # ------------------------------------------------------- + try: + driver.implicitly_wait(3) + report.step_start("Click Connect Button") + joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") + joinBTNElement.click() + except NoSuchElementException: + print("Connect Button Not Enabled...Verify if Password is set properly ") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + #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 & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + #allure.attach(name= body=str("Wifi Successfully Connected")) + # time.sleep(5) + check_if_no_internet_popup(driver) + except: + try: + check_if_no_internet_popup(driver) + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='" + + WifiName + "']"))) + print("Wifi Successfully Connected without internet") + #allure.attach(name= body=str("Wifi Successfully Connected without internet")) + check_if_no_internet_popup(driver) + except: 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 + report.step_start("Verify if Wifi is Connected") + WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True - except: - 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") + print("Wifi Successfully Connected") + #allure.attach(name=body=str("Wifi Successfully Connected")) + except NoSuchElementException: + print("Wifi Connection Error: " + WifiName) + #allure.attach(name=body=str("Wifi Connection Error: " + WifiName)) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet - # ------------------------------- 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: + except NoSuchElementException: print("No Switch element found") + #allure.attach(name= body=str("No Switch element found")) # ---------------------To Turn on WIFi Switch if already OFF------------------------------- - except: + except NoSuchElementException: print("Couldn't find wifi Button") + #allure.attach(name= body=str("Couldn't find wifi Button")) # ------------------Open WIFI page---------------------------------- - except: + except NoSuchElementException: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") + #allure.attach(name= body=str("Exception: Verify Xpath - Update/check Xpath for Click Connections")) # -----------------To Open Connections page--------------------------- - else: #--------------------Pixel code----------------------------------- + else: #--------------Pixel 4 code-------------------------- report.step_start("Set Wifi Network to " + WifiName) # -----------------To Open Connections page----------------------- try: - print("Verifying Connected Wifi Connection in Pixel") + print("Verifying Connected Wifi Connection") report.step_start("Click Network & internet in pixel4") conn_element = driver.find_element_by_xpath("//*[@text='Network & internet']") conn_element.click() @@ -3457,7 +4876,7 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM try: driver.implicitly_wait(1) get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") get_switch_text = get_switch_text_element.text # if get_switch_text is not None: # switch_text = "OFF" @@ -3470,7 +4889,7 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM if switch_text == "OFF": # driver.implicitly_wait(3) get_switch_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -3497,15 +4916,15 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM pass if switch_text == "OFF": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet # ---------------------This is to Forget current connected SSID------------------------------- try: # To deal with already connected SSID @@ -3515,20 +4934,20 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM print("To forget ssid") check_if_no_internet_popup(driver) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") additional_details_element.click() except: print("Couldn't get into additional details") try: check_if_no_internet_popup(driver) forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/button1']") + "//*[@resource-id='com.android & iOS.settings:id/button1']") forget_ssid.click() print("Forget old ssid") except: print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet except: print("No Connected SSIDS") # ----------------------This is to Forget current connected SSID-------------------------------- @@ -3576,12 +4995,11 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM if not ssid_not_found: print("could not found " + WifiName + " in device") # allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet - # ------------------------------------------------------- + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet # ------------------------------------------------------- # Selecting WIFI @@ -3595,18 +5013,16 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM except Exception as e: print("Exception on Selecting Wifi Network. Please check wifi Name or signal") request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet - # ------------------------------------------------------- + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet # ------------------------------------------------------- # Selecting certificate # ------------------------------------------------------- try: driver.implicitly_wait(3) report.step_start("Selecting CA Cert") - print("Selecting certificate") cert_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/ca_cert']") + "//*[@resource-id='com.android & iOS.settings:id/ca_cert']") cert_element.click() except NoSuchElementException: print("Selecting certificate failed") @@ -3616,7 +5032,6 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM try: driver.implicitly_wait(3) report.step_start("Validting CA Cert") - print("validation") cert_element = driver.find_element_by_xpath( "//*[@text='Do not validate']") cert_element.click() @@ -3629,7 +5044,7 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM report.step_start("Set User name") print("Set User name") wifi_user_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/identity']") + "//*[@resource-id='com.android & iOS.settings:id/identity']") wifi_user_element.send_keys(User) except NoSuchElementException: print("User name not Loaded") @@ -3640,15 +5055,15 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM # Set Password # ------------------------------------------------------- try: - check_if_no_internet_popup(driver) - report.step_start("Set Wifi Password") - print("Entering password") - wifiPasswordElement = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/password']") - wifiPasswordElement.send_keys(ttls_passwd) + driver.implicitly_wait(6) + report.step_start("Set Password") + print("Set Password") + wifi_password_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/password']") + wifi_password_element.send_keys(ttls_passwd) + print("Entered Password") except NoSuchElementException: print("Password Page Not Loaded, password May be cached in the System") - check_if_no_internet_popup(driver) # ------------------------------------------------------- @@ -3657,7 +5072,6 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM try: driver.implicitly_wait(3) report.step_start("Click Connect Button") - print("Click Connect Button") join_element = driver.find_element_by_xpath("//*[@text='Connect']") join_element.click() except NoSuchElementException: @@ -3669,130 +5083,59 @@ def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoM # ------------------------------------------------------- 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: - try: - print("Not able to verify the connected WiFi. Scrolling up.") - scroll_up(setup_perfectoMobile) - scroll_up(setup_perfectoMobile) - 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") - scroll_up(setup_perfectoMobile) - WifiInternetErrMsg = WebDriverWait(driver, 60).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") - except NoSuchElementException: - print("Wifi Connection Error: " + WifiName) - 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 - # ------------------------------------------------------- - try: - print("Into additional details") - time.sleep(5) - report.step_start("Going for ip address") - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") - additional_details_element.click() - print("Entered ssid") - try: - time.sleep(10) - print("clicking Advanced") - report.step_start("clicking Advanced") - advanced_element = driver.find_element_by_xpath("//*[@text='Advanced']") - advanced_element.click() - print("clicked Advanced") - #print("Device IP address is :", ip_address_element_text) - except: - try: - time.sleep(5) - print("clicking Advanced2") - advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]") - advanced_element.click() - #print("Device IP address is :", ip_address_element_text) - except: - try: - time.sleep(5) - print("clicking Advanced2") - advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.LinearLayout[5]/android.widget.LinearLayout[1]/android.widget.ImageView[1]") - advanced_element.click() - except: - print("No advanced options") - # allure.attach(name= body=str("IP address element not found")) - - # closeApp(connData["appPackage-android"], setup_perfectoMobile) - # return ip_address_element_text, ssid_with_internet - # Scroll Down - scrollDown(setup_perfectoMobile) - 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") - #------------------------------- Forget SSID ---------------- + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + # time.sleep(5) + check_if_no_internet_popup(driver) + except: try: + print("Not able to verify the connected WiFi. Scrolling up.") + scroll_up(setup_perfectoMobile) + scroll_up(setup_perfectoMobile) + # check_if_no_internet_popup(driver) + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + print("Wifi Successfully Connected without internet") check_if_no_internet_popup(driver) - forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") - 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")) - # closeApp(connData["appPackage-android"], setup_perfectoMobile) - # return ip_address_element_text, ssid_with_internet except: - print("Couldn't forget ssid") - except: - print("Couldn't get into Additional settings") - # ------------------------------------------------------- - except: + try: + report.step_start("Verify if Wifi is Connected") + print("Verifying after scrolling") + scroll_up(setup_perfectoMobile) + WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + except NoSuchElementException: + print("Wifi Connection Error: " + WifiName) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet + + + except NoSuchElementException: print("No Switch element found") + # allure.attach(name= body=str("No Switch element found")) # ---------------------To Turn on WIFi Switch if already OFF------------------------------- - except: + except NoSuchElementException: print("Couldn't find wifi Button") + # allure.attach(name= body=str("Couldn't find wifi Button")) # ------------------Open WIFI page---------------------------------- - except: + except NoSuchElementException: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") + # allure.attach(name= body=str("Exception: Verify Xpath - Update/check Xpath for Click Connections")) # -----------------To Open Connections page--------------------------- - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet -#only to connect to wifi -def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, connData): + + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ssid_with_internet +#--------------------CAPTIVE PORTAL Android----------------------------------------- +def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connData): print("\n-------------------------------------") print("Select Wifi/AccessPoint Connection") print("-------------------------------------") @@ -3801,6 +5144,7 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, report = setup_perfectoMobile[1] driver = setup_perfectoMobile[0] + ip_address_element_text = False ssid_with_internet = False report.step_start("Switching Driver Context") @@ -3809,14 +5153,14 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, driver.switch_to.context(contexts[0]) # Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print("Selected Device Model: " + deviceModelName) #allure.attach(name= body=str("\Selected Device Model: " + deviceModelName)) + if deviceModelName != ("Pixel 4"): report.step_start("Set Wifi Network to " + WifiName) - # -----------------To Open Connections page----------------------- try: print("Verifying Connected Wifi Connection") @@ -3824,26 +5168,28 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, connElement = driver.find_element_by_xpath("//*[@text='Connections']") connElement.click() - # ---------------------Open WIFI page------------------------------- try: report.step_start("Clicking Wi-Fi") print("Clicking WIFI") - wifiElement = driver.find_element_by_xpath("//*[@text='Wi-Fi']") + time.sleep(3) + wifiElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Wi-Fi']"))) wifiElement.click() - # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) - get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_text']") + get_switch_text_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text - print("get_switch_text: ",get_switch_text) + print("get_switch_text: ", get_switch_text) print("Find wifi switch") - try: #To Turn on Wi-Fi Switch + try: # To Turn on Wi-Fi Switch if get_switch_text == "Off": # driver.implicitly_wait(3) - get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_widget']") + get_switch_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -3855,7 +5201,7 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, else: try: get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_text']") + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text except: pass @@ -3864,230 +5210,481 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, pass if get_switch_text == "Off": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) - except: - print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet - - #---------------------This is to Forget current connected SSID------------------------------- - try: #To deal with already connected SSID - check_if_no_internet_popup(driver) - network_category = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/connected_network_category']") - try: #To forget exhisting ssid - print("To forget ssid") + except: + print("Couldn't turn on WIFI switch") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + + # ---------------------This is to Forget current connected SSID------------------------------- + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, + search_this="osVersion") != "12": + try: # To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/connected_network_category']") + try: # To forget exhisting ssid + print("To forget ssid") + check_if_no_internet_popup(driver) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/layout_details']") + additional_details_element.click() + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") + forget_ssid.click() + print("Forget old ssid") + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into additional details") + except: + print("No Connected SSIDS") + else: + try: # To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]") + try: # To forget exhisting ssid + print("To forget ssid in osversion 12") + check_if_no_internet_popup(driver) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/wifi_details']") + additional_details_element.click() + try: + print("To forget ssid in osversion 12-1206") + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/navigation_bar_item_icon_view']") + forget_ssid.click() + print("Forget old ssid") + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into additional details") + except: + print("No Connected SSIDS") + # ----------------------This is to Forget current connected SSID-------------------------------- + + # time.sleep(2) + print("Selecting Wifi: " + WifiName) + # allure.attach(name= body=str("Selecting Wifi: " + WifiName)) + ssid_found = False + available_ssids = False + # This is To get all available ssids + # ------------------------------------------------------ + try: + for k in range(9): + available_ssids = get_all_available_ssids(driver, deviceModelName) + print("active_ssid_list: ", available_ssids) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + try: + if WifiName not in available_ssids: + scrollDown(setup_perfectoMobile) + time.sleep(2) + else: + ssid_found = True + print(WifiName + " : Found in Device") + # allure.attach(name= body=str(WifiName+" : Found in Device")) + break + except: + print("couldn't find wifi in available ssid") + if not ssid_found: + print("could not found " + WifiName + " in device") + # allure.attach(name= body=str("could not found" + WifiName + " in device")) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + # ------------------------------------------------------- + + # Selecting WIFI + # ------------------------------------------------------- + try: + report.step_start("Selecting Wifi: " + WifiName) + print(("Clicking WIFI")) + wifiSelectionElement = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) + wifiSelectionElement.click() + check_if_no_internet_popup(driver) + except Exception as e: + print("Exception on Selecting Wifi Network. Please check wifi Name or signal") + request.config.cache.set(key="SelectingWifiFailed", value=str(e)) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + # ------------------------------------------------------- + + # Set password if Needed + # ------------------------------------------------------- + try: + check_if_no_internet_popup(driver) + time.sleep(3) + report.step_start("Set Wifi Password") + print("Set Wifi password") + wifiPasswordElement = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/edittext']") + wifiPasswordElement.send_keys(WifiPass) + except NoSuchElementException: + print("Password Page Not Loaded, password May be cached in the System") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + + # Click on connect button + # ------------------------------------------------------- + try: + time.sleep(5) + report.step_start("Click Connect Button") + print("Click Connect") + joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") + joinBTNElement.click() + except NoSuchElementException: + print("Connect Button Not Enabled...Verify if Password is set properly ") + check_if_no_internet_popup(driver) + #---------------------Clicking on ssid for captive portal login-------- + try: + time.sleep(2) + report.step_start("Selecting Wifi: " + WifiName) + wifi_selection_element = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) + wifi_selection_element.click() + except NoSuchElementException: + print("Not connected to Captive portal Ssid.. ") + try: + time.sleep(2) + report.step_start("Click Accept Terms Button") + print("Click Accept Terms Button") + join_btn_element = driver.find_element_by_xpath("//*[@text='Accept Terms of Service']") + join_btn_element.click() + except NoSuchElementException: + print(" Couldn't press Accept terms button") + try: + time.sleep(2) + report.step_start("Click Continue Button") + print("Click Continue Button") + join_btn_element = driver.find_element_by_xpath("//*[@text='Continue']") + join_btn_element.click() + except NoSuchElementException: + print(" Couldn't press Continue button") + try: + time.sleep(2) + report.step_start("Click Last Terms if needed") + print("Click Last Terms if needed") + join_btn_element = driver.find_element_by_xpath("//*[@text='Done']") + join_btn_element.click() + except NoSuchElementException: + print(" Couldn't find the last terms page") + + + # Verify if WiFi is connected + # ------------------------------------------------------- + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, + search_this="osVersion") != "12": + try: + report.step_start("Verify if Wifi is Connected") + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + # time.sleep(5) + check_if_no_internet_popup(driver) + except: + try: + check_if_no_internet_popup(driver) + WifiInternetErrMsg = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.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 & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + ssid_with_internet = True + print("Wifi Successfully Connected") + except NoSuchElementException: + print("Wifi Connection Error: " + WifiName) + closeApp(connData["appPackage-android & iOS"], 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 & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]/android & iOS.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 & iOS.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 & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + closeApp(connData["appPackage-android & iOS"], 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 + # ------------------------------------------------------- + # ------------------------------------------------------- + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, + search_this="osVersion") != "12": + try: + print("Into additional details") + time.sleep(2) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") + "//*[@resource-id='com.android & iOS.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 & iOS.widget.TextView[@resource-id='com.android & iOS.settings:id/summary']") + ip_address_element_text = ip_address_element.text + print("Device IP address is :", ip_address_element_text) + except: + try: + time.sleep(2) + ip_address_element = driver.find_element_by_xpath( + "//*[@text='IP address']/parent::*/android & iOS.widget.TextView[@resource-id='android & iOS: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 & iOS"], 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 & iOS.widget.TextView[@resource-id='com.android & iOS.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 & iOS.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 & iOS"], setup_perfectoMobile) + assert False + if (ssid_name_element_text == WifiName): + print("Wifi is connected to the expected ssid") + else: + print("Wifi is not connected to the expected ssid") + closeApp(connData["appPackage-android & iOS"], 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 & iOS: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']") + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") forget_ssid.click() - print("Forget old ssid") + print("Forgetting ssid") + + # ------------------------------- Wifi Switch ---------------- + # try: + # print("clicking on wifi switch") + # get_switch_element = driver.find_element_by_xpath( + # "//*[@resource-id='com.android & iOS.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 ssid_with_internet + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet except: - print("Couldn't get into additional details") - except: - print("No Connected SSIDS") - #----------------------This is to Forget current connected SSID-------------------------------- + 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 & iOS.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 - print("Searching for Wifi: " + WifiName) - #allure.attach(name= body=str("Searching for Wifi: " + WifiName)) - time.sleep(2) - print("Selecting Wifi: " + WifiName) - ssid_found = False - available_ssids = False - # This is To get all available ssids - # ------------------------------------------------------ - try: - for check_for_all_ssids in range(2): - available_ssids = get_all_available_ssids(driver, deviceModelName) try: - if WifiName not in available_ssids: - scrollDown(setup_perfectoMobile) - time.sleep(2) - else: - ssid_found = True - print(WifiName + " : Found in Device") - #allure.attach(name= body=str(WifiName + " : Found in Device")) - break + time.sleep(2) + ssid_name_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.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("1538") + print("Ssid name not available") pass - if not ssid_found: - print("could not found" + WifiName + " in device") - #allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet - except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet - # ------------------------------------------------------- - # Selecting WIFI - # ------------------------------------------------------- - try: - report.step_start("Selecting Wifi: " + WifiName) - print("Selecting Wifi") - wifiSelectionElement = WebDriverWait(driver, 35).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) - wifiSelectionElement.click() - check_if_no_internet_popup(driver) - except Exception as e: - print("Exception on Selecting Wifi Network. Please check wifi Name or signal") - request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet - # ------------------------------------------------------- + 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 & iOS"], setup_perfectoMobile) - # Set username - # ------------------------------------------------------- - try: - driver.implicitly_wait(3) - report.step_start("Set User name") - print("Set User name") - wifiUserElement = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/edittext' and @password='false']") - wifiUserElement.send_keys(User) - except NoSuchElementException: - print("User name not Loaded") - # ------------------------------------------------------- + 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) - # Set Password - # ------------------------------------------------------- - try: - driver.implicitly_wait(6) - report.step_start("Set Password") - print("Set Password") - wifiPasswordElement = driver.find_element_by_xpath( - "//*[@text='Enter password']") - wifiPasswordElement.send_keys(ttls_passwd) - print("Entered Password") - except NoSuchElementException: - print("Password Page Not Loaded, password May be cached in the System") - # ------------------------------------------------------- - # Selecting certificate - # ------------------------------------------------------- - try: - driver.implicitly_wait(3) - report.step_start("Selecting CA Cert") - certElement = driver.find_element_by_xpath( - "//*[@text='Select certificate']") - certElement.click() - except NoSuchElementException: - print("Selecting certificate failed") - # ------------------------------------------------------- - # Validating certificate - # ------------------------------------------------------- - try: - driver.implicitly_wait(3) - report.step_start("Validting CA Cert") - certElement = driver.find_element_by_xpath( - "//*[@text=\"Don't validate\"]") - certElement.click() - except NoSuchElementException: - print("validation failed") - # ------------------------------------------------------- + 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) - # Click on connect button - # ------------------------------------------------------- - try: - driver.implicitly_wait(3) - report.step_start("Click Connect Button") - joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") - joinBTNElement.click() - except NoSuchElementException: - print("Connect Button Not Enabled...Verify if Password is set properly ") - check_if_no_internet_popup(driver) - # ------------------------------------------------------- + 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") - #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") - #allure.attach(name= body=str("Wifi Successfully Connected")) - # time.sleep(5) - check_if_no_internet_popup(driver) - except: - try: - 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") - #allure.attach(name= body=str("Wifi Successfully Connected without internet")) - 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 + "']"))) + ip_address_element_text = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[4]/android & iOS.widget.RelativeLayout[1]/android & iOS.widget.TextView[2]") + ip_address_element_text = ip_address_element_text.text ssid_with_internet = True - print("Wifi Successfully Connected") - #allure.attach(name=body=str("Wifi Successfully Connected")) - except NoSuchElementException: - print("Wifi Connection Error: " + WifiName) - #allure.attach(name=body=str("Wifi Connection Error: " + WifiName)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + 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") - except NoSuchElementException: + # ------------------------------- Wifi Switch ---------------- + # try: + # print("clicking on wifi switch") + # get_switch_element = driver.find_element_by_xpath( + # "//*[@resource-id='com.android & iOS.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 & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into Additional settings") + # ------------------------------------------------------- + + # ------------------------------------------------------- + except: print("No Switch element found") - #allure.attach(name= body=str("No Switch element found")) # ---------------------To Turn on WIFi Switch if already OFF------------------------------- - except NoSuchElementException: + except: print("Couldn't find wifi Button") - #allure.attach(name= body=str("Couldn't find wifi Button")) # ------------------Open WIFI page---------------------------------- - except NoSuchElementException: + except: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") - #allure.attach(name= body=str("Exception: Verify Xpath - Update/check Xpath for Click Connections")) # -----------------To Open Connections page--------------------------- - else: #--------------Pixel 4 code-------------------------- + # --------------------Pixel 4 code--------------------------- + else: report.step_start("Set Wifi Network to " + WifiName) # -----------------To Open Connections page----------------------- try: print("Verifying Connected Wifi Connection") report.step_start("Click Network & internet in pixel4") - conn_element = driver.find_element_by_xpath("//*[@text='Network & internet']") - conn_element.click() + connElement = driver.find_element_by_xpath("//*[@text='Network & internet']") + connElement.click() # ---------------------Open WIFI page------------------------------- try: report.step_start("Clicking Wi-Fi") print("Clicking WIFI") time.sleep(3) - wifi_element = WebDriverWait(driver, 10).until( + wifiElement = WebDriverWait(driver, 10).until( EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Wi‑Fi']"))) - wifi_element.click() + wifiElement.click() # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") get_switch_text = get_switch_text_element.text # if get_switch_text is not None: # switch_text = "OFF" @@ -4100,7 +5697,7 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, if switch_text == "OFF": # driver.implicitly_wait(3) get_switch_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -4127,15 +5724,15 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, pass if switch_text == "OFF": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet # ---------------------This is to Forget current connected SSID------------------------------- try: # To deal with already connected SSID @@ -4145,20 +5742,20 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, print("To forget ssid") check_if_no_internet_popup(driver) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") additional_details_element.click() except: print("Couldn't get into additional details") try: check_if_no_internet_popup(driver) forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/button1']") + "//*[@resource-id='com.android & iOS.settings:id/button1']") forget_ssid.click() print("Forget old ssid") except: print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet except: print("No Connected SSIDS") # ----------------------This is to Forget current connected SSID-------------------------------- @@ -4206,89 +5803,86 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, if not ssid_not_found: print("could not found " + WifiName + " in device") # allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- # Selecting WIFI # ------------------------------------------------------- try: report.step_start("Selecting Wifi: " + WifiName) - wifi_selection_element = WebDriverWait(driver, 35).until( + wifiSelectionElement = WebDriverWait(driver, 35).until( EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) - wifi_selection_element.click() + wifiSelectionElement.click() check_if_no_internet_popup(driver) except Exception as e: print("Exception on Selecting Wifi Network. Please check wifi Name or signal") request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet - # ------------------------------------------------------- - # Selecting certificate - # ------------------------------------------------------- - try: - driver.implicitly_wait(3) - report.step_start("Selecting CA Cert") - cert_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/ca_cert']") - cert_element.click() - except NoSuchElementException: - print("Selecting certificate failed") - # ------------------------------------------------------- - # Validating certificate - # ------------------------------------------------------- - try: - driver.implicitly_wait(3) - report.step_start("Validting CA Cert") - cert_element = driver.find_element_by_xpath( - "//*[@text='Do not validate']") - cert_element.click() - except NoSuchElementException: - print("validation failed") - # Set username - # ------------------------------------------------------- - try: - driver.implicitly_wait(3) - report.step_start("Set User name") - print("Set User name") - wifi_user_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/identity']") - wifi_user_element.send_keys(User) - except NoSuchElementException: - print("User name not Loaded") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- - # Scroll Down - scroll_down_pixel(setup_perfectoMobile) - time.sleep(2) - # Set Password + + # Set password if Needed # ------------------------------------------------------- try: - driver.implicitly_wait(6) - report.step_start("Set Password") - print("Set Password") - wifi_password_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/password']") - wifi_password_element.send_keys(ttls_passwd) - print("Entered Password") + time.sleep(3) + check_if_no_internet_popup(driver) + report.step_start("Set Wifi Password") + print("Entering password") + wifiPasswordElement = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/password']") + wifiPasswordElement.send_keys(WifiPass) except NoSuchElementException: print("Password Page Not Loaded, password May be cached in the System") - + check_if_no_internet_popup(driver) # ------------------------------------------------------- # Click on connect button # ------------------------------------------------------- try: - driver.implicitly_wait(3) report.step_start("Click Connect Button") - join_element = driver.find_element_by_xpath("//*[@text='Connect']") - join_element.click() + time.sleep(5) + joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") + joinBTNElement.click() except NoSuchElementException: print("Connect Button Not Enabled...Verify if Password is set properly ") check_if_no_internet_popup(driver) # ------------------------------------------------------- + try: + report.step_start("Selecting Wifi: " + WifiName) + wifiSelectionElement = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) + wifiSelectionElement.click() + check_if_no_internet_popup(driver) + except Exception as e: + print("Exception on Selecting Wifi Network. Please check wifi Name or signal") + try: + time.sleep(2) + report.step_start("Click Accept Terms Button") + print("Click Accept Terms Button") + join_btn_element = driver.find_element_by_xpath("//*[@text='Accept Terms of Service']") + join_btn_element.click() + except NoSuchElementException: + print(" Couldn't press Accept terms button") + try: + time.sleep(2) + report.step_start("Click Continue Button") + print("Click Continue Button") + join_btn_element = driver.find_element_by_xpath("//*[@text='Continue']") + join_btn_element.click() + except NoSuchElementException: + print(" Couldn't press Continue button") + try: + time.sleep(2) + report.step_start("Click Last Terms if needed") + print("Click Last Terms if needed") + join_btn_element = driver.find_element_by_xpath("//*[@text='Done']") + join_btn_element.click() + except NoSuchElementException: + print(" Couldn't find the last terms page") # Verify if WiFi is connected # ------------------------------------------------------- @@ -4296,7 +5890,7 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) @@ -4309,7 +5903,7 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, # 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 + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) print("Wifi Successfully Connected without internet") check_if_no_internet_popup(driver) except: @@ -4317,41 +5911,203 @@ def wifi_connect_eap(request, WifiName, User, ttls_passwd, setup_perfectoMobile, report.step_start("Verify if Wifi is Connected") print("Verifying after scrolling") scroll_up(setup_perfectoMobile) - WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( - MobileBy.XPATH, - "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + WifiInternetErrMsg = WebDriverWait(driver, 60).until( + EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.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 ssid_with_internet + closeApp(connData["appPackage-android & iOS"], 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 + # ------------------------------------------------------- + try: + print("Into additional details") + time.sleep(5) + report.step_start("Going for ip address") + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") + additional_details_element.click() + print("Entered ssid") + try: + time.sleep(10) + print("clicking Advanced") + report.step_start("clicking Advanced") + advanced_element = driver.find_element_by_xpath("//*[@text='Advanced']") + advanced_element.click() + print("clicked Advanced") + # print("Device IP address is :", ip_address_element_text) + except: + try: + time.sleep(5) + print("clicking Advanced2") + advanced_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.FrameLayout[2]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[1]") + advanced_element.click() + # print("Device IP address is :", ip_address_element_text) + except: + try: + time.sleep(5) + print("clicking Advanced2") + advanced_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[5]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.ImageView[1]") + advanced_element.click() + except: + print("No advanced options") + # allure.attach(name= body=str("IP address element not found")) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet + # Scroll Down + scrollDown(setup_perfectoMobile) + try: + time.sleep(2) + ip_address_element = driver.find_element_by_xpath( + "//*[@text='IP address']/parent::*/android & iOS.widget.TextView[@resource-id='android & iOS: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") + # ------------------------------- Forget SSID ---------------- + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") + forget_ssid.click() + print("Forgetting ssid") - except NoSuchElementException: + # ------------------------------- Wifi Switch ---------------- + try: + print("clicking on wifi switch") + get_switch_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.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 & iOS"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into Additional settings") + # ------------------------------------------------------- + except: print("No Switch element found") - # allure.attach(name= body=str("No Switch element found")) # ---------------------To Turn on WIFi Switch if already OFF------------------------------- - except NoSuchElementException: + except: print("Couldn't find wifi Button") - # allure.attach(name= body=str("Couldn't find wifi Button")) # ------------------Open WIFI page---------------------------------- - except NoSuchElementException: + except: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") - # allure.attach(name= body=str("Exception: Verify Xpath - Update/check Xpath for Click Connections")) # -----------------To Open Connections page--------------------------- - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ssid_with_internet -#--------------------CAPTIVE PORTAL Android----------------------------------------- -def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connData): + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + + +def close_driver(driver): + driver.close() + driver.quit() + + +def expressWifi(request, WifiName, setup_perfectoMobile, connData): + print("\n-------------------------------------") + print("Express Wifi Verification") + print("-------------------------------------") + report = setup_perfectoMobile[1] + driver = setup_perfectoMobile[0] + + try: + click_on_ssid = WebDriverWait(driver, 10).until(EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Sign in to the network.']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) + click_on_ssid.click() + print("click on expresswifi SSID to open login page") + except: + print("Could not found expresswifi SSID") + + try: + print("Express Wifi Home Page Verification") + report.step_start("Express Wifi Home Page Verification") + driver.implicitly_wait(2) + ExpressWifiBytesLeft = driver.find_element_by_xpath("//*[@label='0KB left']") + except NoSuchElementException: + # driver.implicitly_wait(25) + #Add function to Toggle Wifi if Express Wifi Home Page not Triggerd + print("Express Wifi Page Not Logged In - ") + + try: + print("ExpressWifi Click on Menu Circle") + report.step_start("ExpressWifi Click on Menu Circle") + ExpressWifiMenu = driver.find_element_by_xpath("//*[@resource-id='dogfood-menu']") + ExpressWifiMenu.click() + except NoSuchElementException: + print("---- Exception ExpressWifi Click on Menu Circle") + + try: + print("ExpressWifi Click Run Tests!") + report.step_start("ExpressWifi Click Run Tests!") + ExpressWifiRunTests = driver.find_element_by_xpath("//*[@resource-id='run_tests']") + ExpressWifiRunTests.click() + time.sleep(20) + except NoSuchElementException: + print("Exception ExceptionExpressWifi Click Run Tests!") + + try: + print("Verify Results: ") + report.step_start("Verify Results") + + expressWifiOutputMsg = "//*[@resource-id='test_result']" + LogOut = driver.find_element_by_xpath(expressWifiOutputMsg) + print("----" + LogOut.text + "\n") + if 'test completed successfully' in LogOut.text: + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return True + else: + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return False + except NoSuchElementException: + print("Exception Verify Results") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + +def scroll_down_pixel(setup_perfectoMobile): + print("Scroll Down") + setup_perfectoMobile[1].step_start("Scroll Down") + params2 = {} + params2["start"] = "50%,50%" + params2["end"] = "50%,20%" + params2["duration"] = "4" + time.sleep(2) + setup_perfectoMobile[0].execute_script('mobile:touch:swipe', params2) + time.sleep(1) +def scroll_up(setup_perfectoMobile): + print("Scroll up") + setup_perfectoMobile[1].step_start("Scroll up") + params2 = {} + params2["start"] = "50%,20%" + params2["end"] = "50%,80%" + params2["duration"] = "2" + time.sleep(1) + setup_perfectoMobile[0].execute_script('mobile:touch:swipe', params2) + time.sleep(1) + + +def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perfectoMobile, connData): print("\n-------------------------------------") print("Select Wifi/AccessPoint Connection") print("-------------------------------------") print("Verifying Wifi Connection Details....") - #allure.attach(name= body=str("\n-------------------------------------")) report = setup_perfectoMobile[1] driver = setup_perfectoMobile[0] @@ -4364,14 +6120,14 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa driver.switch_to.context(contexts[0]) # Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print("Selected Device Model: " + deviceModelName) - #allure.attach(name= body=str("\Selected Device Model: " + deviceModelName)) if deviceModelName != ("Pixel 4"): report.step_start("Set Wifi Network to " + WifiName) + # -----------------To Open Connections page----------------------- try: print("Verifying Connected Wifi Connection") @@ -4379,28 +6135,28 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa connElement = driver.find_element_by_xpath("//*[@text='Connections']") connElement.click() + # ---------------------Open WIFI page------------------------------- try: report.step_start("Clicking Wi-Fi") print("Clicking WIFI") time.sleep(3) wifiElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Wi-Fi']"))) + EC.presence_of_element_located((MobileBy.XPATH,"//*[@text='Wi-Fi']"))) wifiElement.click() + # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) - get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_text']") + get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text - print("get_switch_text: ", get_switch_text) + print("get_switch_text: ",get_switch_text) print("Find wifi switch") - try: # To Turn on Wi-Fi Switch + try: #To Turn on Wi-Fi Switch if get_switch_text == "Off": # driver.implicitly_wait(3) - get_switch_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -4412,7 +6168,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa else: try: get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_text']") + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text except: pass @@ -4421,78 +6177,50 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa pass if get_switch_text == "Off": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet - # ---------------------This is to Forget current connected SSID------------------------------- - if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, - search_this="osVersion") != "12": - try: # To deal with already connected SSID - check_if_no_internet_popup(driver) - network_category = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/connected_network_category']") - try: # To forget exhisting ssid - print("To forget ssid") - check_if_no_internet_popup(driver) - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") - additional_details_element.click() - 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("Forget old ssid") - 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 details") - except: - print("No Connected SSIDS") - else: - try: # To deal with already connected SSID + #---------------------This is to Forget current connected SSID------------------------------- + try: #To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/connected_network_category']") + try: #To forget exhisting ssid + print("To forget ssid") check_if_no_internet_popup(driver) - network_category = driver.find_element_by_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]") - try: # To forget exhisting ssid - print("To forget ssid in osversion 12") + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/layout_details']") + additional_details_element.click() + try: check_if_no_internet_popup(driver) - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/wifi_details']") - additional_details_element.click() - try: - print("To forget ssid in osversion 12-1206") - 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/navigation_bar_item_icon_view']") - forget_ssid.click() - print("Forget old ssid") - except: - print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") + forget_ssid.click() + print("Forget old ssid") except: - print("Couldn't get into additional details") + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet except: - print("No Connected SSIDS") - # ----------------------This is to Forget current connected SSID-------------------------------- + print("Couldn't get into additional details") + except: + print("No Connected SSIDS") + #----------------------This is to Forget current connected SSID-------------------------------- # time.sleep(2) print("Selecting Wifi: " + WifiName) - # allure.attach(name= body=str("Selecting Wifi: " + WifiName)) + #allure.attach(name= body=str("Selecting Wifi: " + WifiName)) ssid_found = False available_ssids = False - # This is To get all available ssids - # ------------------------------------------------------ + #This is To get all available ssids + #------------------------------------------------------ try: for k in range(9): available_ssids = get_all_available_ssids(driver, deviceModelName) @@ -4504,22 +6232,24 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa time.sleep(2) else: ssid_found = True - print(WifiName + " : Found in Device") - # allure.attach(name= body=str(WifiName+" : Found in Device")) + print(WifiName+" : Found in Device") + #allure.attach(name= body=str(WifiName+" : Found in Device")) break except: print("couldn't find wifi in available ssid") if not ssid_found: print("could not found " + WifiName + " in device") - # allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + #allure.attach(name= body=str("could not found" + WifiName + " in device")) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet - # ------------------------------------------------------- + #------------------------------------------------------- - # Selecting WIFI + + + #Selecting WIFI # ------------------------------------------------------- try: report.step_start("Selecting Wifi: " + WifiName) @@ -4531,26 +6261,26 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa except Exception as e: print("Exception on Selecting Wifi Network. Please check wifi Name or signal") request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- - # Set password if Needed + + #Set password if Needed # ------------------------------------------------------- try: check_if_no_internet_popup(driver) time.sleep(3) report.step_start("Set Wifi Password") print("Set Wifi password") - wifiPasswordElement = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/edittext']") + wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/edittext']") wifiPasswordElement.send_keys(WifiPass) except NoSuchElementException: print("Password Page Not Loaded, password May be cached in the System") check_if_no_internet_popup(driver) # ------------------------------------------------------- - # Click on connect button + #Click on connect button # ------------------------------------------------------- try: time.sleep(5) @@ -4560,41 +6290,8 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa joinBTNElement.click() except NoSuchElementException: print("Connect Button Not Enabled...Verify if Password is set properly ") - check_if_no_internet_popup(driver) - #---------------------Clicking on ssid for captive portal login-------- - try: - time.sleep(2) - report.step_start("Selecting Wifi: " + WifiName) - wifi_selection_element = WebDriverWait(driver, 35).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) - wifi_selection_element.click() - except NoSuchElementException: - print("Not connected to Captive portal Ssid.. ") - try: - time.sleep(2) - report.step_start("Click Accept Terms Button") - print("Click Accept Terms Button") - join_btn_element = driver.find_element_by_xpath("//*[@text='Accept Terms of Service']") - join_btn_element.click() - except NoSuchElementException: - print(" Couldn't press Accept terms button") - try: - time.sleep(2) - report.step_start("Click Continue Button") - print("Click Continue Button") - join_btn_element = driver.find_element_by_xpath("//*[@text='Continue']") - join_btn_element.click() - except NoSuchElementException: - print(" Couldn't press Continue button") - try: - time.sleep(2) - report.step_start("Click Last Terms if needed") - print("Click Last Terms if needed") - join_btn_element = driver.find_element_by_xpath("//*[@text='Done']") - join_btn_element.click() - except NoSuchElementException: - print(" Couldn't find the last terms page") - + check_if_no_internet_popup(driver) + # ------------------------------------------------------- # Verify if WiFi is connected # ------------------------------------------------------- @@ -4604,7 +6301,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) @@ -4614,7 +6311,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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='" + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) print("Wifi Successfully Connected without internet") check_if_no_internet_popup(driver) @@ -4624,28 +6321,27 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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 + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: try: - report.step_start( - "Verifying wifi connection status connected/connected without internet") + 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]" + "//*[@resource-id='com.android & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]/android & iOS.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']" + "//*[@resource-id='com.android & iOS.settings:id/summary']" ))) if wifi_connection_status.text == "Connected": ssid_with_internet = True @@ -4658,49 +6354,49 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # 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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], 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 # ------------------------------------------------------- - # ------------------------------------------------------- if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, search_this="osVersion") != "12": try: print("Into additional details") time.sleep(2) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") + "//*[@resource-id='com.android & iOS.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='com.android.settings:id/summary']") + "//*[@text='IP address']/parent::*/android & iOS.widget.TextView[@resource-id='com.android & iOS.settings:id/summary']") ip_address_element_text = ip_address_element.text print("Device IP address is :", ip_address_element_text) except: 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 & iOS.widget.TextView[@resource-id='android & iOS: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) + closeApp(connData["appPackage-android & iOS"], 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']") + "//*[@text='Security']/parent::*/android & iOS.widget.TextView[@resource-id='com.android & iOS.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)) @@ -4710,26 +6406,25 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa try: time.sleep(2) ssid_name_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/entity_header_title']") + "//*[@resource-id='com.android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) assert False if (ssid_name_element_text == WifiName): print("Wifi is connected to the expected ssid") else: print("Wifi is not connected to the expected ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], 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 = driver.find("//*[@resource-id='android & iOS:id/switch_widget']") auto_reconnect_off_text = auto_reconnect_off.text if auto_reconnect_off_text != "Off": auto_reconnect_off.click() @@ -4743,7 +6438,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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']") + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") forget_ssid.click() print("Forgetting ssid") @@ -4751,7 +6446,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # try: # print("clicking on wifi switch") # get_switch_element = driver.find_element_by_xpath( - # "//*[@resource-id='com.android.settings:id/switch_widget']") + # "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") # driver.implicitly_wait(2) # get_switch_element.click() # except: @@ -4759,7 +6454,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # #allure.attach(name= body=str("couldn't click on wifi switch")) except: print("Couldn't forget ssid") - # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # return ip_address_element_text, ssid_with_internet except: print("Couldn't get into Additional settings") @@ -4769,14 +6464,13 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa print("Into additional details") time.sleep(2) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/wifi_details']") + "//*[@resource-id='com.android & iOS.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']"))) + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='View more']"))) additional_details_element.click() except: pass @@ -4784,7 +6478,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa try: time.sleep(2) ssid_name_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/entity_header_title']") + "//*[@resource-id='com.android & iOS.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)) @@ -4799,7 +6493,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # return ip_address_element_text, ssid_with_internet else: print("Wifi is not connected to the expected ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) report.step_start("Scrolling for ip address - 1") # if deviceModelName == "Galaxy S20": @@ -4825,36 +6519,36 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[4]/android & iOS.widget.RelativeLayout[1]/android & iOS.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 + # 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 & iOS.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 & iOS"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet except: print("Couldn't get into Additional settings") # ------------------------------------------------------- @@ -4862,16 +6556,15 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # ------------------------------------------------------- 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--------------------------- + #--------------------Pixel 4 code--------------------------- else: report.step_start("Set Wifi Network to " + WifiName) @@ -4895,7 +6588,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa try: driver.implicitly_wait(1) get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") get_switch_text = get_switch_text_element.text # if get_switch_text is not None: # switch_text = "OFF" @@ -4908,7 +6601,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa if switch_text == "OFF": # driver.implicitly_wait(3) get_switch_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -4935,14 +6628,14 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa pass if switch_text == "OFF": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ---------------------This is to Forget current connected SSID------------------------------- @@ -4953,19 +6646,19 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa print("To forget ssid") check_if_no_internet_popup(driver) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") additional_details_element.click() except: print("Couldn't get into additional details") try: check_if_no_internet_popup(driver) forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/button1']") + "//*[@resource-id='com.android & iOS.settings:id/button1']") forget_ssid.click() print("Forget old ssid") except: print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: print("No Connected SSIDS") @@ -5014,10 +6707,10 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa if not ssid_not_found: print("could not found " + WifiName + " in device") # allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -5032,7 +6725,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa except Exception as e: print("Exception on Selecting Wifi Network. Please check wifi Name or signal") request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -5043,8 +6736,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa check_if_no_internet_popup(driver) report.step_start("Set Wifi Password") print("Entering password") - wifiPasswordElement = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/password']") + wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/password']") wifiPasswordElement.send_keys(WifiPass) except NoSuchElementException: print("Password Page Not Loaded, password May be cached in the System") @@ -5062,38 +6754,6 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa print("Connect Button Not Enabled...Verify if Password is set properly ") check_if_no_internet_popup(driver) # ------------------------------------------------------- - try: - report.step_start("Selecting Wifi: " + WifiName) - wifiSelectionElement = WebDriverWait(driver, 35).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) - wifiSelectionElement.click() - check_if_no_internet_popup(driver) - except Exception as e: - print("Exception on Selecting Wifi Network. Please check wifi Name or signal") - try: - time.sleep(2) - report.step_start("Click Accept Terms Button") - print("Click Accept Terms Button") - join_btn_element = driver.find_element_by_xpath("//*[@text='Accept Terms of Service']") - join_btn_element.click() - except NoSuchElementException: - print(" Couldn't press Accept terms button") - try: - time.sleep(2) - report.step_start("Click Continue Button") - print("Click Continue Button") - join_btn_element = driver.find_element_by_xpath("//*[@text='Continue']") - join_btn_element.click() - except NoSuchElementException: - print(" Couldn't press Continue button") - try: - time.sleep(2) - report.step_start("Click Last Terms if needed") - print("Click Last Terms if needed") - join_btn_element = driver.find_element_by_xpath("//*[@text='Done']") - join_btn_element.click() - except NoSuchElementException: - print(" Couldn't find the last terms page") # Verify if WiFi is connected # ------------------------------------------------------- @@ -5101,7 +6761,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) @@ -5114,7 +6774,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa # 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 + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) print("Wifi Successfully Connected without internet") check_if_no_internet_popup(driver) except: @@ -5122,15 +6782,14 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa report.step_start("Verify if Wifi is Connected") print("Verifying after scrolling") scroll_up(setup_perfectoMobile) - WifiInternetErrMsg = WebDriverWait(driver, 60).until( - EC.presence_of_element_located(( - MobileBy.XPATH, - "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -5144,7 +6803,7 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa time.sleep(5) report.step_start("Going for ip address") additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") additional_details_element.click() print("Entered ssid") try: @@ -5154,60 +6813,38 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa advanced_element = driver.find_element_by_xpath("//*[@text='Advanced']") advanced_element.click() print("clicked Advanced") - # print("Device IP address is :", ip_address_element_text) + #print("Device IP address is :", ip_address_element_text) except: try: time.sleep(5) print("clicking Advanced2") advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.FrameLayout[2]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[1]") advanced_element.click() - # print("Device IP address is :", ip_address_element_text) + #print("Device IP address is :", ip_address_element_text) except: try: time.sleep(5) print("clicking Advanced2") advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.LinearLayout[5]/android.widget.LinearLayout[1]/android.widget.ImageView[1]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[5]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.ImageView[1]") advanced_element.click() except: print("No advanced options") # allure.attach(name= body=str("IP address element not found")) - # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # return ip_address_element_text, ssid_with_internet # Scroll Down scrollDown(setup_perfectoMobile) 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 & iOS.widget.TextView[@resource-id='android & iOS: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") - # ------------------------------- Forget SSID ---------------- - try: - check_if_no_internet_popup(driver) - forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") - 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") # ------------------------------------------------------- @@ -5223,98 +6860,10 @@ def captive_portal_and(request, WifiName, WifiPass, setup_perfectoMobile, connDa print("Exception: Verify Xpath - Update/check Xpath for Click Connections") # -----------------To Open Connections page--------------------------- - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet - - -def close_driver(driver): - driver.close() - driver.quit() - - -def expressWifi(request, WifiName, setup_perfectoMobile, connData): - print("\n-------------------------------------") - print("Express Wifi Verification") - print("-------------------------------------") - report = setup_perfectoMobile[1] - driver = setup_perfectoMobile[0] - - try: - click_on_ssid = WebDriverWait(driver, 10).until(EC.presence_of_element_located(( - MobileBy.XPATH, - "//*[@resource-id='com.android.settings:id/summary' and @text='Sign in to the network.']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) - click_on_ssid.click() - print("click on expresswifi SSID to open login page") - except: - print("Could not found expresswifi SSID") - - try: - print("Express Wifi Home Page Verification") - report.step_start("Express Wifi Home Page Verification") - driver.implicitly_wait(2) - ExpressWifiBytesLeft = driver.find_element_by_xpath("//*[@label='0KB left']") - except NoSuchElementException: - # driver.implicitly_wait(25) - #Add function to Toggle Wifi if Express Wifi Home Page not Triggerd - print("Express Wifi Page Not Logged In - ") - - try: - print("ExpressWifi Click on Menu Circle") - report.step_start("ExpressWifi Click on Menu Circle") - ExpressWifiMenu = driver.find_element_by_xpath("//*[@resource-id='dogfood-menu']") - ExpressWifiMenu.click() - except NoSuchElementException: - print("---- Exception ExpressWifi Click on Menu Circle") - - try: - print("ExpressWifi Click Run Tests!") - report.step_start("ExpressWifi Click Run Tests!") - ExpressWifiRunTests = driver.find_element_by_xpath("//*[@resource-id='run_tests']") - ExpressWifiRunTests.click() - time.sleep(20) - except NoSuchElementException: - print("Exception ExceptionExpressWifi Click Run Tests!") - - try: - print("Verify Results: ") - report.step_start("Verify Results") - - expressWifiOutputMsg = "//*[@resource-id='test_result']" - LogOut = driver.find_element_by_xpath(expressWifiOutputMsg) - print("----" + LogOut.text + "\n") - if 'test completed successfully' in LogOut.text: - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return True - else: - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return False - except NoSuchElementException: - print("Exception Verify Results") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - -def scroll_down_pixel(setup_perfectoMobile): - print("Scroll Down") - setup_perfectoMobile[1].step_start("Scroll Down") - params2 = {} - params2["start"] = "50%,50%" - params2["end"] = "50%,20%" - params2["duration"] = "4" - time.sleep(2) - setup_perfectoMobile[0].execute_script('mobile:touch:swipe', params2) - time.sleep(1) -def scroll_up(setup_perfectoMobile): - print("Scroll up") - setup_perfectoMobile[1].step_start("Scroll up") - params2 = {} - params2["start"] = "50%,20%" - params2["end"] = "50%,80%" - params2["duration"] = "2" - time.sleep(1) - setup_perfectoMobile[0].execute_script('mobile:touch:swipe', params2) - time.sleep(1) - - -def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perfectoMobile, connData): +#----------------------------------Gets ip address of the enterprise ssid and does not forget it------------------ +def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passwd, setup_perfectoMobile, connData): print("\n-------------------------------------") print("Select Wifi/AccessPoint Connection") print("-------------------------------------") @@ -5331,7 +6880,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf driver.switch_to.context(contexts[0]) # Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print("Selected Device Model: " + deviceModelName) @@ -5360,14 +6909,14 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) - get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_text']") + get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text print("get_switch_text: ",get_switch_text) print("Find wifi switch") try: #To Turn on Wi-Fi Switch if get_switch_text == "Off": # driver.implicitly_wait(3) - get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_widget']") + get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -5379,7 +6928,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf else: try: get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_text']") + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text except: pass @@ -5388,36 +6937,36 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf pass if get_switch_text == "Off": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet #---------------------This is to Forget current connected SSID------------------------------- try: #To deal with already connected SSID check_if_no_internet_popup(driver) network_category = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/connected_network_category']") + "//*[@resource-id='com.android & iOS.settings:id/connected_network_category']") try: #To forget exhisting ssid print("To forget ssid") check_if_no_internet_popup(driver) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") + "//*[@resource-id='com.android & iOS.settings:id/layout_details']") additional_details_element.click() 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']") + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") forget_ssid.click() print("Forget old ssid") except: print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: print("Couldn't get into additional details") @@ -5425,7 +6974,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf print("No Connected SSIDS") #----------------------This is to Forget current connected SSID-------------------------------- - # time.sleep(2) + time.sleep(2) print("Selecting Wifi: " + WifiName) #allure.attach(name= body=str("Selecting Wifi: " + WifiName)) ssid_found = False @@ -5433,7 +6982,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf #This is To get all available ssids #------------------------------------------------------ try: - for k in range(9): + for k in range(10): available_ssids = get_all_available_ssids(driver, deviceModelName) print("active_ssid_list: ", available_ssids) allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) @@ -5451,20 +7000,18 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf if not ssid_found: print("could not found " + WifiName + " in device") #allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet #------------------------------------------------------- - - - #Selecting WIFI + # Selecting WIFI # ------------------------------------------------------- try: report.step_start("Selecting Wifi: " + WifiName) - print(("Clicking WIFI")) + print("Selecting Wifi") wifiSelectionElement = WebDriverWait(driver, 35).until( EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) wifiSelectionElement.click() @@ -5472,32 +7019,71 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf except Exception as e: print("Exception on Selecting Wifi Network. Please check wifi Name or signal") request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- - - - #Set password if Needed + + # Set username + # ------------------------------------------------------- + try: + # driver.implicitly_wait(3) + report.step_start("Set User name") + print("Set User name") + wifiUserElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='com.android & iOS.settings:id/edittext' and @password='false']"))) + wifiUserElement.send_keys(User) + except NoSuchElementException: + print("User name not Loaded") + # ------------------------------------------------------- + + # Set Password + # ------------------------------------------------------- + try: + # driver.implicitly_wait(6) + report.step_start("Set Password") + print("Set Password") + wifiPasswordElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Enter password']"))) + wifiPasswordElement.send_keys(ttls_passwd) + print("Entered Password") + except NoSuchElementException: + print("Password Page Not Loaded, password May be cached in the System") + # ------------------------------------------------------- + # Selecting certificate + # ------------------------------------------------------- + try: + # driver.implicitly_wait(3) + report.step_start("Selecting CA Cert") + print("Selecting CA Cert") + certElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Select certificate']"))) + certElement.click() + except NoSuchElementException: + print("Selecting certificate failed") + # ------------------------------------------------------- + # Validating certificate # ------------------------------------------------------- try: - check_if_no_internet_popup(driver) - time.sleep(3) - report.step_start("Set Wifi Password") - print("Set Wifi password") - wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/edittext']") - wifiPasswordElement.send_keys(WifiPass) + # driver.implicitly_wait(3) + report.step_start("Validting CA Cert") + print("Validting CA Cert") + certElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text=\"Don't validate\"]"))) + certElement.click() except NoSuchElementException: - print("Password Page Not Loaded, password May be cached in the System") - check_if_no_internet_popup(driver) + print("validation failed") # ------------------------------------------------------- - - #Click on connect button + if (deviceModelName == "Galaxy S9"): + driver.hide_keyboard() + print("Hide keyboard") + # Click on connect button # ------------------------------------------------------- try: - time.sleep(5) + # driver.implicitly_wait(3) report.step_start("Click Connect Button") - print("Click Connect") - joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") + print("Click Connect Button") + joinBTNElement = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Connect']"))) joinBTNElement.click() except NoSuchElementException: print("Connect Button Not Enabled...Verify if Password is set properly ") @@ -5512,7 +7098,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) @@ -5522,7 +7108,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf 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='" + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) print("Wifi Successfully Connected without internet") check_if_no_internet_popup(driver) @@ -5532,12 +7118,12 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf 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 + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: try: @@ -5547,12 +7133,12 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf 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]" + "//*[@resource-id='com.android & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]/android & iOS.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']" + "//*[@resource-id='com.android & iOS.settings:id/summary']" ))) if wifi_connection_status.text == "Connected": ssid_with_internet = True @@ -5565,10 +7151,10 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf # 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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -5583,31 +7169,31 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf print("Into additional details") time.sleep(2) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") + "//*[@resource-id='com.android & iOS.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='com.android.settings:id/summary']") + "//*[@text='IP address']/parent::*/android & iOS.widget.TextView[@resource-id='com.android & iOS.settings:id/summary']") ip_address_element_text = ip_address_element.text print("Device IP address is :", ip_address_element_text) except: 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 & iOS.widget.TextView[@resource-id='android & iOS: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) + closeApp(connData["appPackage-android & iOS"], 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']") + "//*[@text='Security']/parent::*/android & iOS.widget.TextView[@resource-id='com.android & iOS.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)) @@ -5617,25 +7203,25 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf try: time.sleep(2) ssid_name_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/entity_header_title']") + "//*[@resource-id='com.android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) assert False if (ssid_name_element_text == WifiName): print("Wifi is connected to the expected ssid") else: print("Wifi is not connected to the expected ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], 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 = driver.find("//*[@resource-id='android & iOS:id/switch_widget']") auto_reconnect_off_text = auto_reconnect_off.text if auto_reconnect_off_text != "Off": auto_reconnect_off.click() @@ -5649,7 +7235,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf 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']") + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") forget_ssid.click() print("Forgetting ssid") @@ -5657,7 +7243,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf # try: # print("clicking on wifi switch") # get_switch_element = driver.find_element_by_xpath( - # "//*[@resource-id='com.android.settings:id/switch_widget']") + # "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") # driver.implicitly_wait(2) # get_switch_element.click() # except: @@ -5665,7 +7251,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf # #allure.attach(name= body=str("couldn't click on wifi switch")) except: print("Couldn't forget ssid") - # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # return ip_address_element_text, ssid_with_internet except: print("Couldn't get into Additional settings") @@ -5675,7 +7261,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf print("Into additional details") time.sleep(2) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/wifi_details']") + "//*[@resource-id='com.android & iOS.settings:id/wifi_details']") additional_details_element.click() try: @@ -5689,7 +7275,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf try: time.sleep(2) ssid_name_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/entity_header_title']") + "//*[@resource-id='com.android & iOS.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)) @@ -5704,7 +7290,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf # return ip_address_element_text, ssid_with_internet else: print("Wifi is not connected to the expected ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) report.step_start("Scrolling for ip address - 1") # if deviceModelName == "Galaxy S20": @@ -5730,7 +7316,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf 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]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[4]/android & iOS.widget.RelativeLayout[1]/android & iOS.widget.TextView[2]") ip_address_element_text = ip_address_element_text.text ssid_with_internet = True except: @@ -5750,7 +7336,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf # # try: # # print("clicking on wifi switch") # # get_switch_element = driver.find_element_by_xpath( - # # "//*[@resource-id='com.android.settings:id/switch_widget']") + # # "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") # # driver.implicitly_wait(2) # # get_switch_element.click() # # except: @@ -5758,7 +7344,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf # # #allure.attach(name= body=str("couldn't click on wifi switch")) # except: # print("Couldn't forget ssid") - # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # return ip_address_element_text, ssid_with_internet except: print("Couldn't get into Additional settings") @@ -5775,31 +7361,30 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf except: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") - #--------------------Pixel 4 code--------------------------- - else: + else: #--------------------Pixel code----------------------------------- report.step_start("Set Wifi Network to " + WifiName) # -----------------To Open Connections page----------------------- try: - print("Verifying Connected Wifi Connection") + print("Verifying Connected Wifi Connection in Pixel") report.step_start("Click Network & internet in pixel4") - connElement = driver.find_element_by_xpath("//*[@text='Network & internet']") - connElement.click() + conn_element = driver.find_element_by_xpath("//*[@text='Network & internet']") + conn_element.click() # ---------------------Open WIFI page------------------------------- try: report.step_start("Clicking Wi-Fi") print("Clicking WIFI") time.sleep(3) - wifiElement = WebDriverWait(driver, 10).until( + wifi_element = WebDriverWait(driver, 10).until( EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Wi‑Fi']"))) - wifiElement.click() + wifi_element.click() # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") get_switch_text = get_switch_text_element.text # if get_switch_text is not None: # switch_text = "OFF" @@ -5812,7 +7397,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf if switch_text == "OFF": # driver.implicitly_wait(3) get_switch_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -5839,14 +7424,14 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf pass if switch_text == "OFF": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ---------------------This is to Forget current connected SSID------------------------------- @@ -5857,19 +7442,19 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf print("To forget ssid") check_if_no_internet_popup(driver) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") additional_details_element.click() except: print("Couldn't get into additional details") try: check_if_no_internet_popup(driver) forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/button1']") + "//*[@resource-id='com.android & iOS.settings:id/button1']") forget_ssid.click() print("Forget old ssid") except: print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: print("No Connected SSIDS") @@ -5918,49 +7503,89 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf if not ssid_not_found: print("could not found " + WifiName + " in device") # allure.attach(name= body=str("could not found" + WifiName + " in device")) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet + # ------------------------------------------------------- # ------------------------------------------------------- # Selecting WIFI # ------------------------------------------------------- try: report.step_start("Selecting Wifi: " + WifiName) - wifiSelectionElement = WebDriverWait(driver, 35).until( + wifi_selection_element = WebDriverWait(driver, 35).until( EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) - wifiSelectionElement.click() + wifi_selection_element.click() check_if_no_internet_popup(driver) except Exception as e: print("Exception on Selecting Wifi Network. Please check wifi Name or signal") request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- - - # Set password if Needed + # ------------------------------------------------------- + # Selecting certificate + # ------------------------------------------------------- + try: + driver.implicitly_wait(3) + report.step_start("Selecting CA Cert") + print("Selecting certificate") + cert_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/ca_cert']") + cert_element.click() + except NoSuchElementException: + print("Selecting certificate failed") + # ------------------------------------------------------- + # Validating certificate + # ------------------------------------------------------- + try: + driver.implicitly_wait(3) + report.step_start("Validting CA Cert") + print("validation") + cert_element = driver.find_element_by_xpath( + "//*[@text='Do not validate']") + cert_element.click() + except NoSuchElementException: + print("validation failed") + # Set username + # ------------------------------------------------------- + try: + driver.implicitly_wait(3) + report.step_start("Set User name") + print("Set User name") + wifi_user_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/identity']") + wifi_user_element.send_keys(User) + except NoSuchElementException: + print("User name not Loaded") + # ------------------------------------------------------- + # Scroll Down + scroll_down_pixel(setup_perfectoMobile) + time.sleep(2) + # Set Password # ------------------------------------------------------- try: - time.sleep(3) check_if_no_internet_popup(driver) report.step_start("Set Wifi Password") print("Entering password") - wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/password']") - wifiPasswordElement.send_keys(WifiPass) + wifiPasswordElement = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/password']") + wifiPasswordElement.send_keys(ttls_passwd) except NoSuchElementException: print("Password Page Not Loaded, password May be cached in the System") check_if_no_internet_popup(driver) + # ------------------------------------------------------- # Click on connect button # ------------------------------------------------------- try: + driver.implicitly_wait(3) report.step_start("Click Connect Button") - time.sleep(5) - joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") - joinBTNElement.click() + join_element = driver.find_element_by_xpath("//*[@text='Connect']") + join_element.click() except NoSuchElementException: print("Connect Button Not Enabled...Verify if Password is set properly ") check_if_no_internet_popup(driver) @@ -5972,7 +7597,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) @@ -5985,7 +7610,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf # 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 + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) print("Wifi Successfully Connected without internet") check_if_no_internet_popup(driver) except: @@ -5995,12 +7620,12 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf scroll_up(setup_perfectoMobile) WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( MobileBy.XPATH, - "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -6014,7 +7639,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf time.sleep(5) report.step_start("Going for ip address") additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") additional_details_element.click() print("Entered ssid") try: @@ -6030,7 +7655,7 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf time.sleep(5) print("clicking Advanced2") advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.FrameLayout[2]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[1]") advanced_element.click() #print("Device IP address is :", ip_address_element_text) except: @@ -6038,20 +7663,20 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf time.sleep(5) print("clicking Advanced2") advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.LinearLayout[5]/android.widget.LinearLayout[1]/android.widget.ImageView[1]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[5]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.ImageView[1]") advanced_element.click() except: print("No advanced options") # allure.attach(name= body=str("IP address element not found")) - # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # return ip_address_element_text, ssid_with_internet # Scroll Down scrollDown(setup_perfectoMobile) 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 & iOS.widget.TextView[@resource-id='android & iOS:id/summary']") ip_address_element_text = ip_address_element.text print("Device IP address is :", ip_address_element_text) except: @@ -6070,11 +7695,12 @@ def gets_ip_add_and_does_not_forget_ssid(request, WifiName, WifiPass, setup_perf except: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") # -----------------To Open Connections page--------------------------- - - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet -#----------------------------------Gets ip address of the enterprise ssid and does not forget it------------------ -def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passwd, setup_perfectoMobile, connData): + + +#-----------------------------ip address check------------------------------------------------ +def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup_perfectoMobile, connData): print("\n-------------------------------------") print("Select Wifi/AccessPoint Connection") print("-------------------------------------") @@ -6091,7 +7717,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw driver.switch_to.context(contexts[0]) # Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print("Selected Device Model: " + deviceModelName) @@ -6120,14 +7746,14 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) - get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_text']") + get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text print("get_switch_text: ",get_switch_text) print("Find wifi switch") try: #To Turn on Wi-Fi Switch if get_switch_text == "Off": # driver.implicitly_wait(3) - get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_widget']") + get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -6139,168 +7765,25 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw else: try: get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_text']") + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text - except: - pass - print("Sleeping for: ", i) - time.sleep(i) - pass - if get_switch_text == "Off": - print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet - else: - print("Switch is already On") - check_if_no_internet_popup(driver) - except: - print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet - - #---------------------This is to Forget current connected SSID------------------------------- - try: #To deal with already connected SSID - check_if_no_internet_popup(driver) - network_category = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/connected_network_category']") - try: #To forget exhisting ssid - print("To forget ssid") - check_if_no_internet_popup(driver) - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") - additional_details_element.click() - 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("Forget old ssid") - 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 details") - except: - print("No Connected SSIDS") - #----------------------This is to Forget current connected SSID-------------------------------- - - time.sleep(2) - print("Selecting Wifi: " + WifiName) - #allure.attach(name= body=str("Selecting Wifi: " + WifiName)) - ssid_found = False - available_ssids = False - #This is To get all available ssids - #------------------------------------------------------ - try: - for k in range(10): - available_ssids = get_all_available_ssids(driver, deviceModelName) - print("active_ssid_list: ", available_ssids) - allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) - try: - if WifiName not in available_ssids: - scrollDown(setup_perfectoMobile) - time.sleep(2) - else: - ssid_found = True - print(WifiName+" : Found in Device") - #allure.attach(name= body=str(WifiName+" : Found in Device")) - break - except: - print("couldn't find wifi in available ssid") - if not ssid_found: - print("could not found " + WifiName + " in device") - #allure.attach(name= body=str("could not found" + WifiName + " in device")) - 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 - #------------------------------------------------------- - - # Selecting WIFI - # ------------------------------------------------------- - try: - report.step_start("Selecting Wifi: " + WifiName) - print("Selecting Wifi") - wifiSelectionElement = WebDriverWait(driver, 35).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) - wifiSelectionElement.click() - check_if_no_internet_popup(driver) - except Exception as e: - print("Exception on Selecting Wifi Network. Please check wifi Name or signal") - request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet - # ------------------------------------------------------- - - # Set username - # ------------------------------------------------------- - try: - # driver.implicitly_wait(3) - report.step_start("Set User name") - print("Set User name") - wifiUserElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@resource-id='com.android.settings:id/edittext' and @password='false']"))) - wifiUserElement.send_keys(User) - except NoSuchElementException: - print("User name not Loaded") - # ------------------------------------------------------- - - # Set Password - # ------------------------------------------------------- - try: - # driver.implicitly_wait(6) - report.step_start("Set Password") - print("Set Password") - wifiPasswordElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Enter password']"))) - wifiPasswordElement.send_keys(ttls_passwd) - print("Entered Password") - except NoSuchElementException: - print("Password Page Not Loaded, password May be cached in the System") - # ------------------------------------------------------- - # Selecting certificate - # ------------------------------------------------------- - try: - # driver.implicitly_wait(3) - report.step_start("Selecting CA Cert") - print("Selecting CA Cert") - certElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Select certificate']"))) - certElement.click() - except NoSuchElementException: - print("Selecting certificate failed") - # ------------------------------------------------------- - # Validating certificate - # ------------------------------------------------------- - try: - # driver.implicitly_wait(3) - report.step_start("Validting CA Cert") - print("Validting CA Cert") - certElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text=\"Don't validate\"]"))) - certElement.click() - except NoSuchElementException: - print("validation failed") - # ------------------------------------------------------- - if (deviceModelName == "Galaxy S9"): - driver.hide_keyboard() - print("Hide keyboard") - # Click on connect button - # ------------------------------------------------------- - try: - # driver.implicitly_wait(3) - report.step_start("Click Connect Button") - print("Click Connect Button") - joinBTNElement = WebDriverWait(driver, 10).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Connect']"))) - joinBTNElement.click() - except NoSuchElementException: - print("Connect Button Not Enabled...Verify if Password is set properly ") - check_if_no_internet_popup(driver) + except: + pass + print("Sleeping for: ", i) + time.sleep(i) + pass + if get_switch_text == "Off": + print("Switch is Still OFF") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + else: + print("Switch is already On") + check_if_no_internet_popup(driver) + except: + print("Couldn't turn on WIFI switch") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- - # Verify if WiFi is connected # ------------------------------------------------------- if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, @@ -6309,7 +7792,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) @@ -6319,7 +7802,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw 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='" + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) print("Wifi Successfully Connected without internet") check_if_no_internet_popup(driver) @@ -6329,27 +7812,28 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw 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 + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: try: - report.step_start("Verifying wifi connection status connected/connected without internet") + 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]" + "//*[@resource-id='com.android & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]/android & iOS.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']" + "//*[@resource-id='com.android & iOS.settings:id/summary']" ))) if wifi_connection_status.text == "Connected": ssid_with_internet = True @@ -6362,10 +7846,10 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw # 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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -6380,31 +7864,31 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw print("Into additional details") time.sleep(2) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") + "//*[@resource-id='com.android & iOS.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='com.android.settings:id/summary']") + "//*[@text='IP address']/parent::*/android & iOS.widget.TextView[@resource-id='com.android & iOS.settings:id/summary']") ip_address_element_text = ip_address_element.text print("Device IP address is :", ip_address_element_text) except: 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 & iOS.widget.TextView[@resource-id='android & iOS: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) + closeApp(connData["appPackage-android & iOS"], 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']") + "//*[@text='Security']/parent::*/android & iOS.widget.TextView[@resource-id='com.android & iOS.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)) @@ -6414,25 +7898,25 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw try: time.sleep(2) ssid_name_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/entity_header_title']") + "//*[@resource-id='com.android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) assert False if (ssid_name_element_text == WifiName): print("Wifi is connected to the expected ssid") else: print("Wifi is not connected to the expected ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], 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 = driver.find("//*[@resource-id='android & iOS:id/switch_widget']") auto_reconnect_off_text = auto_reconnect_off.text if auto_reconnect_off_text != "Off": auto_reconnect_off.click() @@ -6446,7 +7930,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw 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']") + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") forget_ssid.click() print("Forgetting ssid") @@ -6454,7 +7938,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw # try: # print("clicking on wifi switch") # get_switch_element = driver.find_element_by_xpath( - # "//*[@resource-id='com.android.settings:id/switch_widget']") + # "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") # driver.implicitly_wait(2) # get_switch_element.click() # except: @@ -6462,7 +7946,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw # #allure.attach(name= body=str("couldn't click on wifi switch")) except: print("Couldn't forget ssid") - # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # return ip_address_element_text, ssid_with_internet except: print("Couldn't get into Additional settings") @@ -6472,7 +7956,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw print("Into additional details") time.sleep(2) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/wifi_details']") + "//*[@resource-id='com.android & iOS.settings:id/wifi_details']") additional_details_element.click() try: @@ -6486,7 +7970,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw try: time.sleep(2) ssid_name_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/entity_header_title']") + "//*[@resource-id='com.android & iOS.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)) @@ -6501,7 +7985,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw # return ip_address_element_text, ssid_with_internet else: print("Wifi is not connected to the expected ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) report.step_start("Scrolling for ip address - 1") # if deviceModelName == "Galaxy S20": @@ -6527,75 +8011,73 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw 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]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[4]/android & iOS.widget.RelativeLayout[1]/android & iOS.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 + 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 & iOS.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 & iOS"], 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------------------------------- - + 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") - else: #--------------------Pixel code----------------------------------- + #--------------------Pixel 4 code--------------------------- + else: report.step_start("Set Wifi Network to " + WifiName) # -----------------To Open Connections page----------------------- try: - print("Verifying Connected Wifi Connection in Pixel") + print("Verifying Connected Wifi Connection") report.step_start("Click Network & internet in pixel4") - conn_element = driver.find_element_by_xpath("//*[@text='Network & internet']") - conn_element.click() + connElement = driver.find_element_by_xpath("//*[@text='Network & internet']") + connElement.click() # ---------------------Open WIFI page------------------------------- try: report.step_start("Clicking Wi-Fi") print("Clicking WIFI") time.sleep(3) - wifi_element = WebDriverWait(driver, 10).until( + wifiElement = WebDriverWait(driver, 10).until( EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='Wi‑Fi']"))) - wifi_element.click() + wifiElement.click() # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") get_switch_text = get_switch_text_element.text # if get_switch_text is not None: # switch_text = "OFF" @@ -6608,7 +8090,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw if switch_text == "OFF": # driver.implicitly_wait(3) get_switch_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -6635,208 +8117,45 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw pass if switch_text == "OFF": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet - - # ---------------------This is to Forget current connected SSID------------------------------- - try: # To deal with already connected SSID - check_if_no_internet_popup(driver) - network_category = driver.find_element_by_xpath("//*[@text='Connected']") - try: # To forget existing ssid - print("To forget ssid") - check_if_no_internet_popup(driver) - additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") - additional_details_element.click() - except: - print("Couldn't get into additional details") - try: - check_if_no_internet_popup(driver) - forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/button1']") - forget_ssid.click() - print("Forget old ssid") - except: - print("Couldn't forget ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) - return ip_address_element_text, ssid_with_internet - except: - print("No Connected SSIDS") - # ----------------------This is to Forget current connected SSID-------------------------------- - - time.sleep(2) - print("Selecting Wifi: " + WifiName) - # allure.attach(name= body=str("Selecting Wifi: " + WifiName)) - ssid_found = False - available_ssids = False - # This is To get all available ssids - # ------------------------------------------------------ - try: - for k in range(5): - available_ssids = get_all_available_ssids(driver, deviceModelName) - print("active_ssid_list: ", available_ssids) - allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) - try: - if WifiName not in available_ssids: - scrollDown(setup_perfectoMobile) - time.sleep(2) - else: - ssid_found = True - print(WifiName + " : Found in Device") - # allure.attach(name= body=str(WifiName+" : Found in Device")) - break - except: - print("couldn't find wifi in available ssid") - if not ssid_found: - ssid_not_found = False - for k in range(5): - available_ssids = get_all_available_ssids(driver, deviceModelName) - print("active_ssid_list: ", available_ssids) - allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) - try: - if WifiName not in available_ssids: - scroll_up(setup_perfectoMobile) - time.sleep(2) - else: - ssid_not_found = True - print(WifiName + " : Found in Device") - # allure.attach(name= body=str(WifiName+" : Found in Device")) - break - except: - print("couldn't find wifi in available ssid") - if not ssid_not_found: - print("could not found " + WifiName + " in device") - # allure.attach(name= body=str("could not found" + WifiName + " in device")) - 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 - # ------------------------------------------------------- - # ------------------------------------------------------- - - # Selecting WIFI - # ------------------------------------------------------- - try: - report.step_start("Selecting Wifi: " + WifiName) - wifi_selection_element = WebDriverWait(driver, 35).until( - EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) - wifi_selection_element.click() - check_if_no_internet_popup(driver) - except Exception as e: - print("Exception on Selecting Wifi Network. Please check wifi Name or signal") - request.config.cache.set(key="SelectingWifiFailed", value=str(e)) - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet - # ------------------------------------------------------- - # ------------------------------------------------------- - # Selecting certificate - # ------------------------------------------------------- - try: - driver.implicitly_wait(3) - report.step_start("Selecting CA Cert") - print("Selecting certificate") - cert_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/ca_cert']") - cert_element.click() - except NoSuchElementException: - print("Selecting certificate failed") - # ------------------------------------------------------- - # Validating certificate - # ------------------------------------------------------- - try: - driver.implicitly_wait(3) - report.step_start("Validting CA Cert") - print("validation") - cert_element = driver.find_element_by_xpath( - "//*[@text='Do not validate']") - cert_element.click() - except NoSuchElementException: - print("validation failed") - # Set username - # ------------------------------------------------------- - try: - driver.implicitly_wait(3) - report.step_start("Set User name") - print("Set User name") - wifi_user_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/identity']") - wifi_user_element.send_keys(User) - except NoSuchElementException: - print("User name not Loaded") - # ------------------------------------------------------- - # Scroll Down - scroll_down_pixel(setup_perfectoMobile) - time.sleep(2) - # Set Password - # ------------------------------------------------------- - try: - check_if_no_internet_popup(driver) - report.step_start("Set Wifi Password") - print("Entering password") - wifiPasswordElement = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/password']") - wifiPasswordElement.send_keys(ttls_passwd) - except NoSuchElementException: - print("Password Page Not Loaded, password May be cached in the System") - check_if_no_internet_popup(driver) - - # ------------------------------------------------------- - - # Click on connect button - # ------------------------------------------------------- - try: - driver.implicitly_wait(3) - report.step_start("Click Connect Button") - join_element = driver.find_element_by_xpath("//*[@text='Connect']") - join_element.click() - except NoSuchElementException: - print("Connect Button Not Enabled...Verify if Password is set properly ") - check_if_no_internet_popup(driver) - # ------------------------------------------------------- - # 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) check_if_no_internet_popup(driver) except: try: - print("Not able to verify the connected WiFi. Scrolling up.") - scroll_up(setup_perfectoMobile) - scroll_up(setup_perfectoMobile) - # check_if_no_internet_popup(driver) + 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 + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.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") - print("Verifying after scrolling") - scroll_up(setup_perfectoMobile) WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( MobileBy.XPATH, - "//*[@resource-id='android:id/summary' and @text='Connected']/parent::*/android.widget.TextView[@text='" + WifiName + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -6850,7 +8169,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw time.sleep(5) report.step_start("Going for ip address") additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") additional_details_element.click() print("Entered ssid") try: @@ -6866,7 +8185,7 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw time.sleep(5) print("clicking Advanced2") advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.FrameLayout[2]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[1]") advanced_element.click() #print("Device IP address is :", ip_address_element_text) except: @@ -6874,24 +8193,46 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw time.sleep(5) print("clicking Advanced2") advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.LinearLayout[5]/android.widget.LinearLayout[1]/android.widget.ImageView[1]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[5]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.ImageView[1]") advanced_element.click() except: print("No advanced options") # allure.attach(name= body=str("IP address element not found")) - # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # return ip_address_element_text, ssid_with_internet # Scroll Down scrollDown(setup_perfectoMobile) 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 & iOS.widget.TextView[@resource-id='android & iOS: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") + print("IP address element not found") + #------------------------------- Forget SSID ---------------- + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") + 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 & iOS.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 & iOS"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet except: print("Couldn't get into Additional settings") # ------------------------------------------------------- @@ -6906,19 +8247,101 @@ def gets_ip_add_eap_and_does_not_forget_ssid(request, WifiName, User, ttls_passw except: print("Exception: Verify Xpath - Update/check Xpath for Click Connections") # -----------------To Open Connections page--------------------------- - closeApp(connData["appPackage-android"], setup_perfectoMobile) + + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet +def get_phone_information(setup_perfectoMobile, search_this): + report = setup_perfectoMobile[1] + driver = setup_perfectoMobile[0] -#-----------------------------ip address check------------------------------------------------ -def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup_perfectoMobile, connData): + report.step_start("Get DeviceID") + params = {'property': search_this} + device_information = driver.execute_script('mobile:handset:info', params) + print("device information for "+search_this+" is: ", device_information) + return device_information + +#------------Return upload download rate------------------------------ +def return_upload_download_speed_android(request, setup_perfectoMobile_android, get_APToMobileDevice_data): + print("\n-------------------------------------") + print("Verify Upload & Download Speed") + print("-------------------------------------") + + report = setup_perfectoMobile_android[1] + driver = setup_perfectoMobile_android[0] + connData = get_APToMobileDevice_data + + driver.switch_to.context('WEBVIEW_1') + + try: + print("Launching Chrome") + report.step_start("Google Home Page") + driver.get(connData["webURL"]) + print("Enter Search Text") + elementFindTxt = driver.find_element_by_xpath(connData["lblSearch"]) + elementFindTxt.send_keys("Internet Speed Test") + except Exception as e: + print("Launching Chrome Failed") + print (e) + # allure.attach(name="Speed Test logs: ", body=str("Launching Safari Failed")) + # allure.attach(name="Speed Test logs: ", body=str("Error log: " + e)) + + try: + print("Click Search Button") + report.step_start("Click Search Button") + time.sleep(2) + driver.implicitly_wait(2) + elelSearch = driver.find_element_by_xpath("//*[@class='aajZCb']//*[@class='nz2CCf']/li[1]/div[2]") + elelSearch.click() + except: + try: + time.sleep(2) + driver.implicitly_wait(2) + elelSearch = driver.find_element_by_xpath("//*[@class='aajZCb']//*[@class='nz2CCf']/li[1]/div[2]") + elelSearch.click() + except: + print("Search Drop Down not active...") + return False + + try: + print("Click Run Speed Test Button...") + report.step_start("Click Run Speed Test Button") + driver.find_element_by_xpath(connData["BtnRunSpeedTest"]).click() + except NoSuchElementException: + print("Error in speed test element ", NoSuchElementException) + # allure.attach(name="Speed Test logs: ", body=str("Search Run Speed Test not active..." + NoSuchElementException)) + return False + + #Get upload/Download Speed + try: + print("Get Download Speed") + report.step_start("Get upload/Download Speed") + time.sleep(60) + downloadMbps = driver.find_element_by_xpath(connData["downloadMbps"]) + downloadSpeed = downloadMbps.text + print("Download: " + downloadSpeed + " Mbps") + + print("Get Upload Speed") + report.step_start("Get Upload Speed") + UploadMbps = driver.find_element_by_xpath(connData["UploadMbps"]) + uploadSpeed = UploadMbps.text + print("Upload: " + uploadSpeed + " Mbps") + allure.attach(name="Speed Test logs: ", body=str("Upload: " + uploadSpeed + " Mbps" + " Download: " + downloadSpeed + " Mbps")) + print("Access Point Verification Completed Successfully") + except NoSuchElementException: + print("Access Point Verification NOT Completed, checking Connection....") + + return downloadSpeed, uploadSpeed + + +def get_ip_address_maverick_and(request, WifiName, WifiPass, setup_perfectoMobile, connData): print("\n-------------------------------------") print("Select Wifi/AccessPoint Connection") print("-------------------------------------") print("Verifying Wifi Connection Details....") report = setup_perfectoMobile[1] driver = setup_perfectoMobile[0] - + driver.switch_to.context('WEBVIEW_1') ip_address_element_text = False ssid_with_internet = False @@ -6928,7 +8351,7 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup driver.switch_to.context(contexts[0]) # Open Settings Application - openApp(connData["appPackage-android"], setup_perfectoMobile) + openApp(connData["appPackage-android & iOS"], setup_perfectoMobile) deviceModelName = getDeviceModelName(setup_perfectoMobile) print("Selected Device Model: " + deviceModelName) @@ -6957,14 +8380,14 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup # --------------------To Turn on WIFi Switch if already OFF-------------------------------- try: driver.implicitly_wait(1) - get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_text']") + get_switch_text_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text print("get_switch_text: ",get_switch_text) print("Find wifi switch") try: #To Turn on Wi-Fi Switch if get_switch_text == "Off": # driver.implicitly_wait(3) - get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android.settings:id/switch_widget']") + get_switch_element = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -6976,7 +8399,7 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup else: try: get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_text']") + "//*[@resource-id='com.android & iOS.settings:id/switch_text']") get_switch_text = get_switch_text_element.text except: pass @@ -6985,25 +8408,157 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup pass if get_switch_text == "Off": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + + #---------------------This is to Forget current connected SSID------------------------------- + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, search_this="osVersion") != "12": + try: #To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/connected_network_category']") + try: #To forget exhisting ssid + print("To forget ssid") + check_if_no_internet_popup(driver) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/layout_details']") + additional_details_element.click() + try: + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/icon']") + forget_ssid.click() + print("Forget old ssid") + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into additional details") + except: + print("No Connected SSIDS") + else: + try: #To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]") + try: #To forget exhisting ssid + print("To forget ssid in osversion 12") + check_if_no_internet_popup(driver) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/wifi_details']") + additional_details_element.click() + try: + print("To forget ssid in osversion 12-1206") + check_if_no_internet_popup(driver) + forget_ssid = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/forget_button']//*[@resource-id='com.android & iOS.settings:id/navigation_bar_item_icon_view']") + forget_ssid.click() + print("Forget old ssid") + except: + print("Couldn't forget ssid") + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + print("Couldn't get into additional details") + except: + print("No Connected SSIDS") + #----------------------This is to Forget current connected SSID-------------------------------- + + # time.sleep(2) + print("Selecting Wifi: " + WifiName) + #allure.attach(name= body=str("Selecting Wifi: " + WifiName)) + ssid_found = False + available_ssids = False + #This is To get all available ssids + #------------------------------------------------------ + try: + for k in range(9): + available_ssids = get_all_available_ssids(driver, deviceModelName) + print("active_ssid_list: ", available_ssids) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + try: + if WifiName not in available_ssids: + scrollDown(setup_perfectoMobile) + time.sleep(2) + else: + ssid_found = True + print(WifiName+" : Found in Device") + #allure.attach(name= body=str(WifiName+" : Found in Device")) + break + except: + print("couldn't find wifi in available ssid") + if not ssid_found: + print("could not found " + WifiName + " in device") + #allure.attach(name= body=str("could not found" + WifiName + " in device")) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet + #------------------------------------------------------- + + + + #Selecting WIFI # ------------------------------------------------------- - # Verify if WiFi is connected + try: + report.step_start("Selecting Wifi: " + WifiName) + print(("Clicking WIFI")) + wifiSelectionElement = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) + wifiSelectionElement.click() + check_if_no_internet_popup(driver) + except Exception as e: + print("Exception on Selecting Wifi Network. Please check wifi Name or signal") + request.config.cache.set(key="SelectingWifiFailed", value=str(e)) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- - if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, - search_this="osVersion") != "12": + + + #Set password if Needed + # ------------------------------------------------------- + try: + check_if_no_internet_popup(driver) + time.sleep(3) + report.step_start("Set Wifi Password") + print("Set Wifi password") + wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/edittext']") + wifiPasswordElement.send_keys(WifiPass) + except NoSuchElementException: + print("Password Page Not Loaded, password May be cached in the System") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + + #Click on connect button + # ------------------------------------------------------- + try: + time.sleep(5) + report.step_start("Click Connect Button") + print("Click Connect") + joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") + joinBTNElement.click() + except NoSuchElementException: + print("Connect Button Not Enabled...Verify if Password is set properly ") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + + #Verify if WiFi is connected + # ------------------------------------------------------- + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, search_this="osVersion") != "12": 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) @@ -7013,38 +8568,36 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup 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='" + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.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 + "']"))) + WifiInternetErrMsg = WebDriverWait(driver, 60).until(EC.presence_of_element_located(( + MobileBy.XPATH, + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected']/parent::*/android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: try: - report.step_start( - "Verifying wifi connection status connected/connected without internet") + 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]" + "//*[@resource-id='com.android & iOS.settings:id/connected_list']/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[2]/android & iOS.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']" + "//*[@resource-id='com.android & iOS.settings:id/summary']" ))) if wifi_connection_status.text == "Connected": ssid_with_internet = True @@ -7057,49 +8610,48 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup # 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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet except: - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], 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 # ------------------------------------------------------- - if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, - search_this="osVersion") != "12": + if get_phone_information(setup_perfectoMobile=setup_perfectoMobile, search_this="osVersion") != "12": try: print("Into additional details") time.sleep(2) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/layout_details']") + "//*[@resource-id='com.android & iOS.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='com.android.settings:id/summary']") + "//*[@text='IP address']/parent::*/android & iOS.widget.TextView[@resource-id='com.android & iOS.settings:id/summary']") ip_address_element_text = ip_address_element.text print("Device IP address is :", ip_address_element_text) except: 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 & iOS.widget.TextView[@resource-id='android & iOS: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) + closeApp(connData["appPackage-android & iOS"], 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']") + "//*[@text='Security']/parent::*/android & iOS.widget.TextView[@resource-id='com.android & iOS.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)) @@ -7109,56 +8661,34 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup try: time.sleep(2) ssid_name_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/entity_header_title']") + "//*[@resource-id='com.android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) assert False if (ssid_name_element_text == WifiName): print("Wifi is connected to the expected ssid") else: print("Wifi is not connected to the expected ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], 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 = driver.find("//*[@resource-id='android & iOS: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")) + auto_reconnect_off.click() + print("Auto reconnect turning off") + else: + print("Auto reconnect is already off") except: - print("Couldn't forget ssid") - # closeApp(connData["appPackage-android"], setup_perfectoMobile) - # return ip_address_element_text, ssid_with_internet + print("Couldn't find auto reconnect element") + except: print("Couldn't get into Additional settings") # ------------------------------------------------------- @@ -7167,7 +8697,7 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup print("Into additional details") time.sleep(2) additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/wifi_details']") + "//*[@resource-id='com.android & iOS.settings:id/wifi_details']") additional_details_element.click() try: @@ -7181,7 +8711,7 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup try: time.sleep(2) ssid_name_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/entity_header_title']") + "//*[@resource-id='com.android & iOS.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)) @@ -7196,7 +8726,7 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup # return ip_address_element_text, ssid_with_internet else: print("Wifi is not connected to the expected ssid") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) report.step_start("Scrolling for ip address - 1") # if deviceModelName == "Galaxy S20": @@ -7222,48 +8752,30 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup 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]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[4]/android & iOS.widget.RelativeLayout[1]/android & iOS.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("Couldn't find wifi Button") - # ------------------Open WIFI page---------------------------------- + print("No Switch element found") + # ---------------------To Turn on WIFi Switch if already OFF------------------------------- + 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("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) @@ -7288,7 +8800,7 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup try: driver.implicitly_wait(1) get_switch_text_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") get_switch_text = get_switch_text_element.text # if get_switch_text is not None: # switch_text = "OFF" @@ -7301,7 +8813,7 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup if switch_text == "OFF": # driver.implicitly_wait(3) get_switch_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/switch_widget']") + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") driver.implicitly_wait(1) get_switch_element.click() driver.implicitly_wait(1) @@ -7328,45 +8840,169 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup pass if switch_text == "OFF": print("Switch is Still OFF") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet else: print("Switch is already On") check_if_no_internet_popup(driver) except: print("Couldn't turn on WIFI switch") - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + + # ---------------------This is to Forget current connected SSID------------------------------- + try: # To deal with already connected SSID + check_if_no_internet_popup(driver) + network_category = driver.find_element_by_xpath("//*[@text='Connected']") + try: # To forget existing ssid + print("To forget ssid") + check_if_no_internet_popup(driver) + additional_details_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") + additional_details_element.click() + except: + print("Couldn't get into additional details") + # try: + # check_if_no_internet_popup(driver) + # forget_ssid = driver.find_element_by_xpath( + # "//*[@resource-id='com.android & iOS.settings:id/button1']") + # forget_ssid.click() + # print("Forget old ssid") + # except: + # print("Couldn't forget ssid") + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + # return ip_address_element_text, ssid_with_internet + except: + print("No Connected SSIDS") + # ----------------------This is to Forget current connected SSID-------------------------------- + + time.sleep(2) + print("Selecting Wifi: " + WifiName) + # allure.attach(name= body=str("Selecting Wifi: " + WifiName)) + ssid_found = False + available_ssids = False + # This is To get all available ssids + # ------------------------------------------------------ + try: + for k in range(5): + available_ssids = get_all_available_ssids(driver, deviceModelName) + print("active_ssid_list: ", available_ssids) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + try: + if WifiName not in available_ssids: + scrollDown(setup_perfectoMobile) + time.sleep(2) + else: + ssid_found = True + print(WifiName + " : Found in Device") + # allure.attach(name= body=str(WifiName+" : Found in Device")) + break + except: + print("couldn't find wifi in available ssid") + if not ssid_found: + ssid_not_found = False + for k in range(5): + available_ssids = get_all_available_ssids(driver, deviceModelName) + print("active_ssid_list: ", available_ssids) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + try: + if WifiName not in available_ssids: + scroll_up(setup_perfectoMobile) + time.sleep(2) + else: + ssid_not_found = True + print(WifiName + " : Found in Device") + # allure.attach(name= body=str(WifiName+" : Found in Device")) + break + except: + print("couldn't find wifi in available ssid") + if not ssid_not_found: + print("could not found " + WifiName + " in device") + # allure.attach(name= body=str("could not found" + WifiName + " in device")) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + except: + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) + return ip_address_element_text, ssid_with_internet + # ------------------------------------------------------- + + # Selecting WIFI + # ------------------------------------------------------- + try: + report.step_start("Selecting Wifi: " + WifiName) + wifiSelectionElement = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='" + WifiName + "']"))) + wifiSelectionElement.click() + check_if_no_internet_popup(driver) + except Exception as e: + print("Exception on Selecting Wifi Network. Please check wifi Name or signal") + request.config.cache.set(key="SelectingWifiFailed", value=str(e)) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet + # ------------------------------------------------------- + + # Set password if Needed + # ------------------------------------------------------- + try: + time.sleep(3) + check_if_no_internet_popup(driver) + report.step_start("Set Wifi Password") + print("Entering password") + wifiPasswordElement = driver.find_element_by_xpath("//*[@resource-id='com.android & iOS.settings:id/password']") + wifiPasswordElement.send_keys(WifiPass) + except NoSuchElementException: + print("Password Page Not Loaded, password May be cached in the System") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + + # Click on connect button + # ------------------------------------------------------- + try: + report.step_start("Click Connect Button") + time.sleep(5) + joinBTNElement = driver.find_element_by_xpath("//*[@text='Connect']") + joinBTNElement.click() + except NoSuchElementException: + print("Connect Button Not Enabled...Verify if Password is set properly ") + check_if_no_internet_popup(driver) + # ------------------------------------------------------- + # 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.widget.TextView[@text='" + WifiName + "']"))) ssid_with_internet = True print("Wifi Successfully Connected") # time.sleep(5) check_if_no_internet_popup(driver) except: try: - check_if_no_internet_popup(driver) + print("Not able to verify the connected WiFi. Scrolling up.") + scroll_up(setup_perfectoMobile) + scroll_up(setup_perfectoMobile) + # 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 + "']"))) + "//*[@resource-id='com.android & iOS.settings:id/summary' and @text='Connected without internet']/parent::*/android & iOS.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") + print("Verifying after scrolling") + scroll_up(setup_perfectoMobile) 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 + "']"))) + "//*[@resource-id='android & iOS:id/summary' and @text='Connected']/parent::*/android & iOS.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) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet # ------------------------------------------------------- @@ -7380,7 +9016,7 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup time.sleep(5) report.step_start("Going for ip address") additional_details_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") + "//*[@resource-id='com.android & iOS.settings:id/settings_button_no_background']") additional_details_element.click() print("Entered ssid") try: @@ -7396,7 +9032,7 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup time.sleep(5) print("clicking Advanced2") advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.FrameLayout[2]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.RelativeLayout[1]") advanced_element.click() #print("Device IP address is :", ip_address_element_text) except: @@ -7404,46 +9040,36 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup time.sleep(5) print("clicking Advanced2") advanced_element = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/recycler_view']/android.widget.LinearLayout[5]/android.widget.LinearLayout[1]/android.widget.ImageView[1]") + "//*[@resource-id='com.android & iOS.settings:id/recycler_view']/android & iOS.widget.LinearLayout[5]/android & iOS.widget.LinearLayout[1]/android & iOS.widget.ImageView[1]") advanced_element.click() except: print("No advanced options") # allure.attach(name= body=str("IP address element not found")) - # closeApp(connData["appPackage-android"], setup_perfectoMobile) + # closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) # return ip_address_element_text, ssid_with_internet # Scroll Down scrollDown(setup_perfectoMobile) 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 & iOS.widget.TextView[@resource-id='android & iOS: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") - #------------------------------- Forget SSID ---------------- - try: - check_if_no_internet_popup(driver) - forget_ssid = driver.find_element_by_xpath( - "//*[@resource-id='com.android.settings:id/settings_button_no_background']") - 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")) + + # ------------------------------- Wifi Switch ---------------- + try: + print("clicking on wifi switch") + get_switch_element = driver.find_element_by_xpath( + "//*[@resource-id='com.android & iOS.settings:id/switch_widget']") + driver.implicitly_wait(2) + get_switch_element.click() except: - print("Couldn't forget ssid") - # closeApp(connData["appPackage-android"], setup_perfectoMobile) - # return ip_address_element_text, ssid_with_internet + print("couldn't click on wifi switch") + # allure.attach(name= body=str("couldn't click on wifi switch")) except: print("Couldn't get into Additional settings") # ------------------------------------------------------- @@ -7459,87 +9085,69 @@ def gets_ip_add_for_checking_and_forgets_ssid(request, WifiName, WifiPass, setup print("Exception: Verify Xpath - Update/check Xpath for Click Connections") # -----------------To Open Connections page--------------------------- - closeApp(connData["appPackage-android"], setup_perfectoMobile) + closeApp(connData["appPackage-android & iOS"], setup_perfectoMobile) return ip_address_element_text, ssid_with_internet -def get_phone_information(setup_perfectoMobile, search_this): - report = setup_perfectoMobile[1] - driver = setup_perfectoMobile[0] - - report.step_start("Get DeviceID") - params = {'property': search_this} - device_information = driver.execute_script('mobile:handset:info', params) - print("device information for "+search_this+" is: ", device_information) - return device_information -#------------Return upload download rate------------------------------ -def return_upload_download_speed_android(request, setup_perfectoMobile, get_APToMobileDevice_data): +def return_open_maverickpage_android(request, setup_perfectoMobile_android, get_APToMobileDevice_data): print("\n-------------------------------------") - print("Verify Upload & Download Speed") + print("OPEN TIP MAVERICK PAGE...........!!!!") print("-------------------------------------") - - report = setup_perfectoMobile[1] - driver = setup_perfectoMobile[0] + report = setup_perfectoMobile_android[1] + driver = setup_perfectoMobile_android[0] connData = get_APToMobileDevice_data - + currentResult=False driver.switch_to.context('WEBVIEW_1') - - try: - print("Launching Chrome") - report.step_start("Google Home Page") - driver.get(connData["webURL"]) - print("Enter Search Text") - elementFindTxt = driver.find_element_by_xpath(connData["lblSearch"]) - elementFindTxt.send_keys("Internet Speed Test") - except Exception as e: - print("Launching Chrome Failed") - print (e) - # allure.attach(name="Speed Test logs: ", body=str("Launching Safari Failed")) - # allure.attach(name="Speed Test logs: ", body=str("Error log: " + e)) - try: - print("Click Search Button") - report.step_start("Click Search Button") - time.sleep(2) - driver.implicitly_wait(2) - elelSearch = driver.find_element_by_xpath("//*[@class='aajZCb']//*[@class='nz2CCf']/li[1]/div[2]") - elelSearch.click() - except: + driver.switch_to.context('WEBVIEW_1') + contexts = driver.contexts + print("Printing Context") + print(contexts) + driver.get("http://192.168.1.1") + print(driver.get("http://192.168.1.1")) + print("successfully connected to the gateway") try: - time.sleep(2) - driver.implicitly_wait(2) - elelSearch = driver.find_element_by_xpath("//*[@class='aajZCb']//*[@class='nz2CCf']/li[1]/div[2]") - elelSearch.click() + report.step_start("Entering Password") + Pass = "openwifi" + Password = driver.find_element_by_xpath("//*[@name='luci_password']") + Password.send_keys(Pass) + print("Password entered successfully") + try: + report.step_start("Clicking Login btn ") + button_maverick = driver.find_element_by_xpath("//*[@class='btn cbi-button cbi-button-apply']") + button_maverick.click() + print("Login button clicked successfully") + try: + report.step_start("Clicking System btn ") + system = driver.find_element_by_xpath("//a[text()='System']") + system.click() + print("clicked System Button") + try: + report.step_start("Clicking Reboot btn ") + reboot = driver.find_element_by_xpath("//*[text()='Reboot']") + reboot.click() + print("Reboot Button clicked") + time.sleep(120) + print("Waiting 120 sec for AP to Reboot") + except: + print("unable to click Reboot Button") + except: + print("unable to click System Button") + except: + print("unable to click Login Button") except: - print("Search Drop Down not active...") - return False + print("unable to click Password feild") + except Exception as e: + print("Launching Safari Failed") + print(e) + + + + + + + - try: - print("Click Run Speed Test Button...") - report.step_start("Click Run Speed Test Button") - driver.find_element_by_xpath(connData["BtnRunSpeedTest"]).click() - except NoSuchElementException: - print("Error in speed test element ", NoSuchElementException) - # allure.attach(name="Speed Test logs: ", body=str("Search Run Speed Test not active..." + NoSuchElementException)) - return False - #Get upload/Download Speed - try: - print("Get Download Speed") - report.step_start("Get upload/Download Speed") - time.sleep(60) - downloadMbps = driver.find_element_by_xpath(connData["downloadMbps"]) - downloadSpeed = downloadMbps.text - print("Download: " + downloadSpeed + " Mbps") - print("Get Upload Speed") - report.step_start("Get Upload Speed") - UploadMbps = driver.find_element_by_xpath(connData["UploadMbps"]) - uploadSpeed = UploadMbps.text - print("Upload: " + uploadSpeed + " Mbps") - allure.attach(name="Speed Test logs: ", body=str("Upload: " + uploadSpeed + " Mbps" + " Download: " + downloadSpeed + " Mbps")) - print("Access Point Verification Completed Successfully") - except NoSuchElementException: - print("Access Point Verification NOT Completed, checking Connection....") - return downloadSpeed, uploadSpeed \ No newline at end of file diff --git a/libs/perfecto_libs/iOS_lib.py b/libs/perfecto_libs/iOS_lib.py index f40e8f4332d..88081778377 100644 --- a/libs/perfecto_libs/iOS_lib.py +++ b/libs/perfecto_libs/iOS_lib.py @@ -3323,4 +3323,711 @@ def return_upload_download_speed_iOS(request, setup_perfectoMobile, get_APToMobi print("Access Point Verification NOT Completed, checking Connection....") - return downloadSpeed, uploadSpeed \ No newline at end of file + return downloadSpeed, uploadSpeed + +def get_ip_address_maverick2_ios(request, WifiName, WifiPass, setup_perfectoMobile, connData): + print("\n-------------------------------------") + print("Select Wifi/AccessPoint Connection") + print("-------------------------------------") + print("Verifying Wifi Connection Details....") + reportFlag = True + is_internet = False + ip_address_element_text = False + + print("Verifying Wifi/AP Connection Details....") + report = setup_perfectoMobile[1] + driver = setup_perfectoMobile[0] + + report.step_start("Switching Driver Context") + print("Switching Context to Native") + driver.switch_to.context('NATIVE_APP') + # driver.switch_to.context(contexts[0]) + + report.step_start("Set Wifi Network to " + WifiName) + # Open Settings Application + openApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + + try: + time.sleep(2) + driver.implicitly_wait(2) + try: + print("Verifying Connected Wifi Connection") + report.step_start("Loading Wifi Page") + element = driver.find_element_by_xpath("//XCUIElementTypeCell[@name='Wi-Fi']") + element.click() + except NoSuchElementException: + print("Exception: Verify Xpath - unable to click on Wifi") + + time.sleep(2) + driver.implicitly_wait(4) + # --------------------To Turn on WIFi Switch if already OFF-------------------------------- + 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 + try: + if get_wifi_switch_element_text == "0" or get_wifi_switch_element_text == 0: + get_wifi_switch_element = driver.find_element_by_xpath("//*[@label='Wi-Fi' and @value='0']") + 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='1']") + get_wifi_switch_element_text = get_wifi_switch_element.text + except: + print("Switch is OFF") + + if get_wifi_switch_element_text == "1" or get_wifi_switch_element_text == 1: + print("WIFI Switch is ON") + break + else: + 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("WIFi switch is ON") + if (get_wifi_switch_element_text == "0" or get_wifi_switch_element_text == 0): + print("switch is still OFF") + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + else: + print("Switch is Still OFF") + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + except: + print("No switch element found") + except: + print("get_wifi_switch_element is ON") + # --------------------To Turn on WIFi Switch if already OFF-------------------------------- + + except: + print("Cannot find WIFI element") + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + + # ---------------------This is to Forget current connected SSID------------------------------- + + try: + time.sleep(4) + print("getting in to Additional details") + report.step_start("Clicking More Info") + 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") + forget_ssid = WebDriverWait(driver, 30).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@label='Forget This Network']"))) + forget_ssid.click() + print("Forget old ssid") + try: + time.sleep(2) + report.step_start("Forget SSID popup1") + forget_ssid_popup = WebDriverWait(driver, 30).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@label='Forget']"))) + forget_ssid_popup.click() + + print("**alert** Forget SSID popup killed **alert**") + except: + print("Forget SSID popup not found") + except: + print("couldn't find forget ssid element") + except: + print("No connected SSID") + + # ---------------------This is to Forget current connected SSID------------------------------- + + # ---------------------To get all available SSID------------------------------- + print("Searching for Wifi: " + WifiName) + # allure.attach(name= body=str("Searching for Wifi: " + WifiName)) + time.sleep(2) + report.step_start("Searching SSID") + print("Selecting Wifi: " + WifiName) + ssid_found = False + available_ssids = False + + try: + for check_for_all_ssids in range(9): + available_ssids = get_all_available_ssids(driver) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + try: + if (not ssid_Visible(driver, WifiName)) or (WifiName not in available_ssids): + scrollDown(setup_perfectoMobile) + time.sleep(2) + else: + 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)) + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + pass + + if not ssid_found: + print("could not found " + WifiName + " in device") + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + except: + pass + # ---------------------To get all available SSID------------------------------- + + # ---------------------This is to Select SSID------------------------------- + + # ---------------------This is to Select SSID------------------------------- + # ---------------------Set Password------------------------------- + try: + driver.implicitly_wait(5) + print("Entering Password") + report.step_start("Entering Password") + wifiPassword = driver.find_element_by_xpath("//*[@label='Password']") + wifiPassword.send_keys(WifiPass) + except NoSuchElementException: + print("Enter Password Page Not Loaded") + # ---------------------Set Password------------------------------- + + # ---------------------Click on join------------------------------- + try: + driver.implicitly_wait(4) + print("Selecting join") + report.step_start("Clicking JOIN") + joinBTN = driver.find_element_by_xpath("//*[@label='Join']") + joinBTN.click() + except Exception as e: + print("Join Button Not Enabled...Password may not be needed") + # ---------------------Click on join------------------------------- + + # ---------------------check if internet------------------------------- + try: + driver.implicitly_wait(5) + WifiInternetErrMsg2 = driver.find_element_by_xpath("//*[@label='No Internet Connection']") + # = driver.find_element_by_xpath("//*[@label='No Internet Connection']").text + except Exception as e: + is_internet = True + print("No Wifi-AP Error Internet Error: " + WifiName) + # Need to add Wait for Selected Wifi Xpath + # time.sleep(3) + # ---------------------check if internet------------------------------- + + # ---------------------Additional INFO------------------------------- + try: + driver.implicitly_wait(5) + print("Selecting SSID: ", WifiName) + report.step_start("Additional details of SSID") + additional_details_element = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@label='" + WifiName + "']"))) + # //*[@label='selected']/parent::*/parent::*/XCUIElementTypeButton[@label='More Info'] + additional_details_element.click() + + try: + driver.implicitly_wait(2) + report.step_start("Checking SSID Name as Expected") + print("Checking SSID Name") + ssidname_text = driver.find_element_by_xpath("//*[@label='" + WifiName + "']").text + print(ssidname_text) + if(ssidname_text == WifiName): + print("SSID Matched") + allure.attach(name="SSID Matched ", body=str(WifiName)) + else: + print("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") + + try: + report.step_start("Checking WiFi Address") + print("Checking WIFI address") + # (//*[@label="IP Address"]/parent::*/XCUIElementTypeStaticText)[2] + wifi_address_element_text = driver.find_element_by_xpath( + "(//*[@label='Wi-Fi Address']/parent::*/XCUIElementTypeStaticText)[2]").text + print("wifi_address_element_text: ", wifi_address_element_text) + allure.attach(name="Connected SSID WiFi-Address: ", body=str(wifi_address_element_text)) + 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] + 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: + 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)) + + # --------------------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-------------------------------- + + except Exception as e: + request.config.cache.set(key="select additional info failed", value=str(e)) + # ---------------------Additional INFO------------------------------- + + # --------------------- close app------------------------------- + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + # ---------------------close app------------------------------- +def verifyUploadDownloadSpeediOS(request, setup_perfectoMobile, get_APToMobileDevice_data): + print("\n-------------------------------------") + print("Verify Upload & Download Speed") + print("-------------------------------------") + + report = setup_perfectoMobile[1] + driver = setup_perfectoMobile[0] + connData = get_APToMobileDevice_data + currentResult = True + + contexts = driver.contexts + # print("Printing Context") + # print(contexts) + + driver.switch_to.context('WEBVIEW_1') + + try: + print("Launching Safari") + report.step_start("Google Home Page") + driver.get(connData["webURL"]) + print("Enter Search Text") + print("*%%%%%%%%%%%%%%%%%%%%%%%********") + elementFindTxt = driver.find_element_by_xpath(connData["lblSearch"]) + elementFindTxt.send_keys("192.168.1.1") + except Exception as e: + print("Launching Safari Failed") + print(e) + + return currentResult + +def get_ip_address_maverick_iOS(request, WifiName, WifiPass, setup_perfectoMobile, connData): + print("\n-------------------------------------") + print("Select Wifi/Get IP Address IOS Connection") + print("-------------------------------------") + + reportFlag = True + is_internet = False + ip_address_element_text = False + + print("Verifying Wifi/AP Connection Details....") + report = setup_perfectoMobile[1] + driver = setup_perfectoMobile[0] + + report.step_start("Switching Driver Context") + print("Switching Context to Native") + driver.switch_to.context('NATIVE_APP') + # driver.switch_to.context(contexts[0]) + + report.step_start("Set Wifi Network to " + WifiName) + # Open Settings Application + openApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + + try: + time.sleep(2) + driver.implicitly_wait(2) + try: + print("Verifying Connected Wifi Connection") + report.step_start("Loading Wifi Page") + element = driver.find_element_by_xpath("//XCUIElementTypeCell[@name='Wi-Fi']") + element.click() + except NoSuchElementException: + print("Exception: Verify Xpath - unable to click on Wifi") + + time.sleep(2) + driver.implicitly_wait(4) + # --------------------To Turn on WIFi Switch if already OFF-------------------------------- + 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 + try: + if get_wifi_switch_element_text == "0" or get_wifi_switch_element_text == 0: + get_wifi_switch_element = driver.find_element_by_xpath("//*[@label='Wi-Fi' and @value='0']") + 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='1']") + get_wifi_switch_element_text = get_wifi_switch_element.text + except: + print("Switch is OFF") + + if get_wifi_switch_element_text == "1" or get_wifi_switch_element_text == 1: + print("WIFI Switch is ON") + break + else: + 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("WIFi switch is ON") + if (get_wifi_switch_element_text == "0" or get_wifi_switch_element_text == 0): + print("switch is still OFF") + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + else: + print("Switch is Still OFF") + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + except: + print("No switch element found") + except: + print("get_wifi_switch_element is ON") + # --------------------To Turn on WIFi Switch if already OFF-------------------------------- + + except: + print("Cannot find WIFI element") + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + + # ---------------------This is to Forget current connected SSID------------------------------- + + try: + time.sleep(4) + print("getting in to Additional details") + report.step_start("Clicking More Info") + 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") + forget_ssid = WebDriverWait(driver, 30).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@label='Forget This Network']"))) + forget_ssid.click() + print("Forget old ssid") + try: + time.sleep(2) + report.step_start("Forget SSID popup1") + forget_ssid_popup = WebDriverWait(driver, 30).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@label='Forget']"))) + forget_ssid_popup.click() + + print("**alert** Forget SSID popup killed **alert**") + except: + print("Forget SSID popup not found") + except: + print("couldn't find forget ssid element") + except: + print("No connected SSID") + + # ---------------------This is to Forget current connected SSID------------------------------- + + # ---------------------To get all available SSID------------------------------- + print("Searching for Wifi: " + WifiName) + # allure.attach(name= body=str("Searching for Wifi: " + WifiName)) + time.sleep(2) + report.step_start("Searching SSID") + print("Selecting Wifi: " + WifiName) + ssid_found = False + available_ssids = False + + try: + for check_for_all_ssids in range(9): + available_ssids = get_all_available_ssids(driver) + allure.attach(name="Available SSIDs in device: ", body=str(available_ssids)) + try: + if (not ssid_Visible(driver, WifiName)) or (WifiName not in available_ssids): + scrollDown(setup_perfectoMobile) + time.sleep(2) + else: + 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)) + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + pass + + if not ssid_found: + print("could not found " + WifiName + " in device") + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + except: + pass + # ---------------------To get all available SSID------------------------------- + + # ---------------------This is to Select SSID------------------------------- + + # ---------------------This is to Select SSID------------------------------- + # ---------------------Set Password------------------------------- + try: + driver.implicitly_wait(5) + print("Entering Password") + report.step_start("Entering Password") + wifiPassword = driver.find_element_by_xpath("//*[@label='Password']") + wifiPassword.send_keys(WifiPass) + except NoSuchElementException: + print("Enter Password Page Not Loaded") + # ---------------------Set Password------------------------------- + + # ---------------------Click on join------------------------------- + try: + driver.implicitly_wait(4) + print("Selecting join") + report.step_start("Clicking JOIN") + joinBTN = driver.find_element_by_xpath("//*[@label='Join']") + joinBTN.click() + except Exception as e: + print("Join Button Not Enabled...Password may not be needed") + # ---------------------Click on join------------------------------- + + # ---------------------check if internet------------------------------- + try: + driver.implicitly_wait(5) + WifiInternetErrMsg2 = driver.find_element_by_xpath("//*[@label='No Internet Connection']") + # = driver.find_element_by_xpath("//*[@label='No Internet Connection']").text + except Exception as e: + is_internet = True + print("No Wifi-AP Error Internet Error: " + WifiName) + # Need to add Wait for Selected Wifi Xpath + # time.sleep(3) + # ---------------------check if internet------------------------------- + + # ---------------------Additional INFO------------------------------- + try: + driver.implicitly_wait(5) + print("Selecting SSID: ", WifiName) + report.step_start("Additional details of SSID") + additional_details_element = WebDriverWait(driver, 35).until( + EC.presence_of_element_located((MobileBy.XPATH, + "//*[@label='" + WifiName + "']"))) + # //*[@label='selected']/parent::*/parent::*/XCUIElementTypeButton[@label='More Info'] + additional_details_element.click() + + try: + driver.implicitly_wait(2) + report.step_start("Checking SSID Name as Expected") + print("Checking SSID Name") + ssidname_text = driver.find_element_by_xpath("//*[@label='" + WifiName + "']").text + print(ssidname_text) + if(ssidname_text == WifiName): + print("SSID Matched") + allure.attach(name="SSID Matched ", body=str(WifiName)) + else: + print("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") + + try: + report.step_start("Checking WiFi Address") + print("Checking WIFI address") + # (//*[@label="IP Address"]/parent::*/XCUIElementTypeStaticText)[2] + wifi_address_element_text = driver.find_element_by_xpath( + "(//*[@label='Wi-Fi Address']/parent::*/XCUIElementTypeStaticText)[2]").text + print("wifi_address_element_text: ", wifi_address_element_text) + allure.attach(name="Connected SSID WiFi-Address: ", body=str(wifi_address_element_text)) + 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] + 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: + 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)) + + # try: + # report.step_start("Forget 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") + # # time.sleep(2) + # # driver.implicitly_wait(3) + # try: + # report.step_start("Forget Network popup") + # forget_ssid_popup = WebDriverWait(driver, 30).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@label='Forget']"))) + # forget_ssid_popup.click() + # except: + # print("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-------------------------------- + + except Exception as e: + request.config.cache.set(key="select additional info failed", value=str(e)) + # ---------------------Additional INFO------------------------------- + + # --------------------- close app------------------------------- + closeApp(connData["bundleId-iOS-Settings"], setup_perfectoMobile) + return ip_address_element_text, is_internet + # ---------------------close app------------------------------- + +def return_open_maverickpage_iOS(request, setup_perfectoMobile_iOS, get_APToMobileDevice_data): + print("\n-------------------------------------") + print("OPEN TIP MAVERICK PAGE...........!!!!") + print("-------------------------------------") + report = setup_perfectoMobile_iOS[1] + driver = setup_perfectoMobile_iOS[0] + connData = get_APToMobileDevice_data + currentResult = True + driver.switch_to.context('WEBVIEW_1') + try: + driver.switch_to.context('WEBVIEW_1') + contexts = driver.contexts + print("Printing Context") + print(contexts) + driver.get("http://192.168.1.1") + print(driver.get("http://192.168.1.1")) + print("successfully connected to the gateway") + try: + report.step_start("Entering Password") + Pass = "openwifi" + Password = driver.find_element_by_xpath("//*[@name='luci_password']") + Password.send_keys(Pass) + print("Password entered successfully") + try: + report.step_start("Clicking Login btn ") + button_maverick = driver.find_element_by_xpath("//*[@class='btn cbi-button cbi-button-apply']") + button_maverick.click() + print("Login button clicked successfully") + try: + report.step_start("Clicking System btn ") + system = driver.find_element_by_xpath("//a[text()='System']") + system.click() + print("clicked System Button") + try: + report.step_start("Clicking Reboot btn ") + reboot = driver.find_element_by_xpath("//*[text()='Reboot']") + reboot.click() + print("Reboot Button clicked") + print("Waiting 120 sec for AP to Reboot") + time.sleep(120) + except: + print("unable to click Reboot Button") + except: + print("unable to click System Button") + except: + print("unable to click Login Button") + except: + print("unable to click Password feild") + except Exception as e: + print("Launching Safari Failed") + print(e) + diff --git a/tests/conftest.py b/tests/conftest.py index e5a6054057a..af36a905576 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -284,8 +284,6 @@ def get_device_configuration(device, request): def get_apnos(): """yields the LIBRARY for APNOS, Reduces the use of imports across files""" yield APNOS - - @pytest.fixture(scope="session") def get_equipment_ref(request, setup_controller, testbed, get_configuration): """""" diff --git a/tests/e2e/interOp/Maverick/__init__.py b/tests/e2e/interOp/Maverick/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/e2e/interOp/Maverick/android & iOS/__init__.py b/tests/e2e/interOp/Maverick/android & iOS/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/e2e/interOp/Maverick/android & iOS/test_maverick.py b/tests/e2e/interOp/Maverick/android & iOS/test_maverick.py new file mode 100644 index 00000000000..c040489c5ee --- /dev/null +++ b/tests/e2e/interOp/Maverick/android & iOS/test_maverick.py @@ -0,0 +1,63 @@ +import pytest +import allure +import sys + + + +if 'perfecto_libs' not in sys.path: + sys.path.append(f'../libs/perfecto_libs') + +pytestmark = [pytest.mark.sanity, pytest.mark.interop, pytest.mark.MaverickAndroid, pytest.mark.android, pytest.mark.interop_and, + pytest.mark.client_connectivity + , pytest.mark.interop_uc_sanity, pytest.mark.nat] + +from android_lib import closeApp, return_open_maverickpage_android, set_APconnMobileDevice_android, \ + Toggle_AirplaneMode_android, ForgetWifiConnection, openApp, \ + get_ip_address_maverick_and, wifi_disconnect_and_forget + + +class TestMaverickAndroid(object): + @allure.testcase(url="https://telecominfraproject.atlassian.net/browse/WIFI-4536", name="WIFI-4536") + @pytest.mark.maverickAnd + def test_maverick_android(self, request, get_vif_state, get_ap_logs, currentmav, + get_ToggleAirplaneMode_data,get_configuration, setup_perfectoMobile_android): + ssidName = currentmav + ssidPassword = "[BLANK]" + print("SSID_NAME: " + ssidName) + print("SSID_PASS: " + ssidPassword) + get_vif_state.append(ssidName) + + report = setup_perfectoMobile_android[1] + driver = setup_perfectoMobile_android[0] + connData = get_ToggleAirplaneMode_data + + # Set Wifi/AP Mode + ip, is_internet = get_ip_address_maverick_and(request, ssidName, ssidPassword, setup_perfectoMobile_android, + connData) + # + if is_internet: + if ip: + text_body = ("connected to " + ssidName + " (" + ip + ") " + "with internet") + else: + text_body = ("connected to " + ssidName + "with Internet, couldn't get IP address") + print(text_body) + allure.attach(name="Connection Status: ", body=str(text_body)) + + else: + allure.attach(name="Connection Status: ", body=str("No Internet access")) + assert True + + + @pytest.mark.Mavtra + def test_maverick_trail(self, request, setup_perfectoMobile_android, get_ToggleAirplaneMode_data, get_configuration, get_apnos): + report = setup_perfectoMobile_android[1] + driver = setup_perfectoMobile_android[0] + connData = get_ToggleAirplaneMode_data + + return_open_maverickpage_android(request, setup_perfectoMobile_android, connData) + for access_point in get_configuration['access_point']: + ap_ssh = get_apnos(access_point, pwd="../libs/apnos/", sdk="2.x") + iwinfo = ap_ssh.get_iwinfo() + print("iwinfo:") + print(iwinfo) + assert True diff --git a/tests/e2e/interOp/Maverick/android & iOS/test_maverick2.py b/tests/e2e/interOp/Maverick/android & iOS/test_maverick2.py new file mode 100644 index 00000000000..aa2d1b58c83 --- /dev/null +++ b/tests/e2e/interOp/Maverick/android & iOS/test_maverick2.py @@ -0,0 +1,82 @@ +import time +import pytest +import sys +import allure +import string +import random + + +if 'perfecto_libs' not in sys.path: + sys.path.append(f'../libs/perfecto_libs') + +pytestmark = [pytest.mark.regression, pytest.mark.interop, pytest.mark.android, pytest.mark.interop_and, pytest.mark.ToggleWifiMode, + pytest.mark.client_reconnect,pytest.mark.ToggleAirplaneMode] +from android_lib import closeApp, openApp, set_APconnMobileDevice_android, Toggle_AirplaneMode_android, Toggle_WifiMode_android, ForgetWifiConnection, openApp, get_ip_address_maverick_and, gets_ip_add_for_checking_and_forgets_ssid + +@allure.feature("Maverick") +class TestMaverick(object): + @pytest.mark.nolme + def test_ap_maverick(self,request, lf_tools, setup_controller, get_vif_state, get_configuration, get_ToggleAirplaneMode_data, get_ToggleWifiMode_data, setup_perfectoMobile_android, get_APToMobileDevice_data, get_ap_logs, get_apnos): + for ap in get_configuration['access_point']: + cmd = "uci show ucentral" + print(get_configuration['access_point']) + ap_ssh = get_apnos(ap, pwd="../libs/apnos/", sdk="2.x") + gw = ap_ssh.run_generic_command(cmd) + print("Status:") + print(gw) + connected, latest, active = ap_ssh.get_ucentral_status() + print("Connected:") + print(connected) + iwinfo = ap_ssh.get_iwinfo() + print("iwinfo:") + print(iwinfo) + maverick = ap_ssh.set_maverick() + print("maverick:") + print(maverick) + # reboot = ap_ssh.reboot() + # print("reboot:") + # print(reboot) + + iwinfo = ap_ssh.get_iwinfo() + print("iwinfo:") + print(iwinfo) + # for i in iwinfo: + # print(i) + # print(iwinfo) + # # print(i[0]) + # print('The result is:',i) + # # print(i.wlan0[0]) + for key, value in iwinfo.items(): + print(key, ' : ', value[0]) + ssidName = "Maverick-6AE4A3" + ssidPassword = "[BLANK]" + print("SSID_NAME: " + ssidName) + print("SSID_PASS: " + ssidPassword) + get_vif_state.append(ssidName) + + + report = setup_perfectoMobile_android[1] + driver = setup_perfectoMobile_android[0] + connData = get_ToggleAirplaneMode_data + + ip, is_internet = get_ip_address_maverick_and(request, ssidName, ssidPassword, setup_perfectoMobile_android, connData) + if ip: + if is_internet: + text_body = ("connected to " + ssidName + " (" + ip + ") " + "with internet") + else: + text_body = ("connected to " + ssidName + " (" + ip + ") " + "without internet") + print(text_body) + allure.attach(name="Connection Status: ", body=str(text_body)) + assert True + else: + allure.attach(name="Connection Status: ", body=str("Device is Unable to connect")) + assert False + verifyUploadDownloadSpeed_mav_android(request, setup_perfectoMobile_android, get_APToMobileDevice_data) + print("Succesfully displayed mav page!") + assert True + + + + + + diff --git a/tests/e2e/interOp/Maverick/android & iOS/test_maverick_ios.py b/tests/e2e/interOp/Maverick/android & iOS/test_maverick_ios.py new file mode 100644 index 00000000000..0a88a460398 --- /dev/null +++ b/tests/e2e/interOp/Maverick/android & iOS/test_maverick_ios.py @@ -0,0 +1,58 @@ +import pytest +import sys +import sys +import allure + +if 'perfecto_libs' not in sys.path: + sys.path.append(f'../libs/perfecto_libs') + +pytestmark = [pytest.mark.sanity, pytest.mark.interop, pytest.mark.iOS, pytest.mark.interop_iOS, pytest.mark.client_connectivity + ,pytest.mark.interop_uc_sanity, pytest.mark.nat, pytest.mark.maverickIOS] + +from iOS_lib import closeApp, set_APconnMobileDevice_iOS, Toggle_AirplaneMode_iOS, ForgetWifiConnection, openApp, \ + get_ip_address_maverick_iOS,return_open_maverickpage_iOS, wifi_disconnect_and_forget + +class TestMaverickIOS(object): + @allure.testcase(url="https://telecominfraproject.atlassian.net/browse/WIFI-4536", name="WIFI-4536") + @pytest.mark.maverickIOS + def test_maverick_ios(self, request, get_vif_state, get_ap_logs,currentmav, + get_ToggleAirplaneMode_data, get_configuration, setup_perfectoMobile_iOS): + + ssidName = currentmav + ssidPassword = "[BLANK]" + print("SSID_NAME: " + ssidName) + print("SSID_PASS: " + ssidPassword) + get_vif_state.append(ssidName) + report = setup_perfectoMobile_iOS[1] + driver = setup_perfectoMobile_iOS[0] + connData = get_ToggleAirplaneMode_data + + # Set Wifi/AP Mode + ip, is_internet = get_ip_address_maverick_iOS(request, ssidName, ssidPassword, setup_perfectoMobile_iOS, connData) + # + if is_internet: + if ip: + text_body = ("connected to " + ssidName + " (" + ip + ") " + "with internet") + else: + text_body = ("connected to " + ssidName + "with Internet, couldn't get IP address") + print(text_body) + allure.attach(name="Connection Status: ", body=str(text_body)) + + else: + allure.attach(name="Connection Status: ", body=str("No Internet access")) + assert True +@pytest.mark.Mavtraios +def test_maverick_trail(request, get_vif_state, get_apnos, get_configuration, + get_ToggleAirplaneMode_data, setup_perfectoMobile_iOS): + report = setup_perfectoMobile_iOS[1] + driver = setup_perfectoMobile_iOS[0] + connData = get_ToggleAirplaneMode_data + + return_open_maverickpage_iOS(request, setup_perfectoMobile_iOS, connData) + for access_point in get_configuration['access_point']: + ap_ssh = get_apnos(access_point, pwd="../libs/apnos/", sdk="2.x") + iwinfo = ap_ssh.get_iwinfo() + print("iwinfo:") + print(iwinfo) + assert True + diff --git a/tests/e2e/interOp/conftest.py b/tests/e2e/interOp/conftest.py index 679dde2baa8..11df5d05c3e 100644 --- a/tests/e2e/interOp/conftest.py +++ b/tests/e2e/interOp/conftest.py @@ -74,8 +74,8 @@ def get_APToMobileDevice_data(request, get_device_configuration): "downloadMbps": "//*[@id='knowledge-verticals-internetspeedtest__download']/P[@class='spiqle']", "UploadMbps": "//*[@id='knowledge-verticals-internetspeedtest__upload']/P[@class='spiqle']", # Android - "platformName-android": get_device_configuration["platformName-android"], - "appPackage-android": get_device_configuration["appPackage-android"] + "platformName-android & iOS": get_device_configuration["platformName-android & iOS"], + "appPackage-android & iOS": get_device_configuration["appPackage-android & iOS"] } yield passPoint_data @@ -95,26 +95,49 @@ def get_ToggleAirplaneMode_data(request, get_device_configuration): "webURL": "https://www.google.com", "lblSearch": "//*[@class='gLFyf']", "elelSearch": "(//*[@class='sbic sb43'])[1]", - "BtnRunSpeedTest": "//*[text()='RUN SPEED TEST']", + # "SpeedCheck":"" + "elelSearch": "(//*[@class='a4bIc'])[1]", + "SpeedCheck":"//*[@class='BYM4Nd']//*[@class='q8U8x MBeuO ynAwRc oewGkc LeUQr']", + "Go":"//*[@class='js-start-test test-mode-multi']", + + # "BtnRunSpeedTest": "//*[text()='RUN SPEED TEST']", "bundleId-iOS-Settings": get_device_configuration["bundleId-iOS-Settings"], "bundleId-iOS-Safari": get_device_configuration["bundleId-iOS-Safari"], - "downloadMbps": "//*[@id='knowledge-verticals-internetspeedtest__download']/P[@class='spiqle']", - "UploadMbps": "//*[@id='knowledge-verticals-internetspeedtest__upload']/P[@class='spiqle']", + # "downloadMbps": "//*[@id='knowledge-verticals-internetspeedtest__download']/P[@class='spiqle']", + # "UploadMbps": "//*[@id='knowledge-verticals-internetspeedtest__upload']/P[@class='spiqle']", + # Android + "platformName-android & iOS": get_device_configuration["platformName-android & iOS"], + "appPackage-android & iOS": get_device_configuration["appPackage-android & iOS"] + } + yield passPoint_data + + +@pytest.fixture(scope="function") +def get_maverick_google_search_data(request, get_device_configuration): + passPoint_data = { + "webURL": "https://www.google.com", + "lblSearch": "//*[@class='gLFyf']", + "elelSearch": "(//*[@class='sbic sb43'])[1]", + "TipMaverickPage": "//*[text()='192.168.1.1']", + "bundleId-iOS-Settings": get_device_configuration["bundleId-iOS-Settings"], + "bundleId-iOS-Safari": get_device_configuration["bundleId-iOS-Safari"], + # "downloadMbps": "//*[@id='knowledge-verticals-internetspeedtest__download']/P[@class='spiqle']", + # "UploadMbps": "//*[@id='knowledge-verticals-internetspeedtest__upload']/P[@class='spiqle']", # Android - "platformName-android": get_device_configuration["platformName-android"], - "appPackage-android": get_device_configuration["appPackage-android"] + "platformName-android & iOS": get_device_configuration["platformName-android & iOS"], + "appPackage-android & iOS": get_device_configuration["appPackage-android & iOS"] } yield passPoint_data @pytest.fixture(scope="function") -def get_ToggleWifiMode_data(request,get_device_configuration): +def get_ToggleWifiMode_data(request, get_device_configuration): passPoint_data = { # iOS "bundleId-iOS-Settings": get_device_configuration["bundleId-iOS-Settings"], # Android - "platformName-android": get_device_configuration["platformName-android"], - "appPackage-android": get_device_configuration["appPackage-android"] + "platformName-android & iOS": get_device_configuration["platformName-android & iOS"], + "appPackage-android & iOS": get_device_configuration["appPackage-android & iOS"] } yield passPoint_data @@ -147,7 +170,6 @@ def instantiate_profile(request): yield UProfileUtility - @pytest.fixture(scope="session") def upload_firmware(should_upload_firmware, instantiate_firmware, get_latest_firmware): firmware_id = instantiate_firmware.upload_fw_on_cloud(fw_version=get_latest_firmware, @@ -203,11 +225,10 @@ def setup_vlan(): def setup_profiles(request, setup_controller, testbed, get_equipment_ref, fixtures_ver, skip_lf, get_openflow, run_lf, instantiate_profile, get_markers, create_lanforge_chamberview_dut, lf_tools, get_security_flags, get_configuration, radius_info, get_apnos, radius_accounting_info): - param = dict(request.param) if not skip_lf: lf_tools.reset_scenario() - # VLAN Setup + # VLAN Setup if request.param["mode"] == "VLAN": vlan_list = list() @@ -233,7 +254,8 @@ def setup_profiles(request, setup_controller, testbed, get_equipment_ref, fixtur instantiate_profile, get_markers, create_lanforge_chamberview_dut, lf_tools, get_security_flags, get_configuration, radius_info, get_apnos, - radius_accounting_info, skip_lf=skip_lf, open_flow=get_openflow, run_lf=run_lf) + radius_accounting_info, skip_lf=skip_lf, open_flow=get_openflow, + run_lf=run_lf) print("sleeping for 120 sec.") time.sleep(180) print("Done sleeping") @@ -265,9 +287,9 @@ def failure_tracking_fixture(request): yield tests_failed_during_module - empty_get_vif_state_list = [] + @pytest.fixture(scope="class") def get_vif_state(get_apnos, get_configuration, request, lf_tools, skip_lf): if not skip_lf: @@ -281,6 +303,21 @@ def get_vif_state(get_apnos, get_configuration, request, lf_tools, skip_lf): else: yield empty_get_vif_state_list + +@pytest.fixture(scope="class") +def set_maverick(get_apnos, get_configuration, request, lf_tools, skip_lf, self): + client = self.ssh_cli_connect() + cmd = "/etc/init.d/ucentral stop && /usr/libexec/ucentral/maverick.sh" + if self.mode: + cmd = f"cd ~/cicd-git/ && ./openwrt_ctl.py {self.owrt_args} -t {self.tty} --action " \ + f"cmd --value \"{cmd}\" " + stdin, stdout, stderr = client.exec_command(cmd) + output = stdout.read().replace(b":~# iwinfo", b"").decode('utf-8') + o = output + client.close() + return o + + @pytest.hookimpl(tryfirst=True, hookwrapper=True) def pytest_runtest_makereport(item, call): outcome = yield @@ -360,7 +397,6 @@ def pytest_runtest_makereport(item, call): def pytest_sessionfinish(session, exitstatus): - try: if reporting_client is not None: print() @@ -404,14 +440,14 @@ def setup_perfectoMobile_android(request, get_device_configuration): urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) capabilities = { - 'platformName': get_device_configuration["platformName-android"], - 'model': get_device_configuration["model-android"], + 'platformName': get_device_configuration["platformName-android & iOS"], + 'model': get_device_configuration["model-android & iOS"], 'browserName': 'mobileOS', # 'automationName' : 'Appium', 'securityToken': PERFECTO_DETAILS["securityToken"], 'useAppiumForWeb': 'false', 'useAppiumForHybrid': 'false', - # 'bundleId' : request.config.getini("appPackage-android"), + # 'bundleId' : request.config.getini("appPackage-android & iOS"), } if not is_device_Available_timeout(request, capabilities['model']): @@ -608,7 +644,7 @@ def setup_perfectoMobile_iOS(request, get_device_configuration): except Exception as e: TestCaseName = nCurrentTestMethodNameSplit print("\nUpgrade Python to 3.9 to avoid test_ string in your test case name, see below URL") - # print("https://www.andreagrandi.it/2020/10/11/python39-introduces-removeprefix-removesuffix/") + # print("https://www.anhttps://docs.google.com/spreadsheets/d/1hBCZ8MrTPt1CsZkhGVorWTayfAQgR8LpZ6l7aUc7EHM/edit?usp=sharingdreagrandi.it/2020/10/11/python39-introduces-removeprefix-removesuffix/") projectname = PERFECTO_DETAILS["projectName"] projectversion = PERFECTO_DETAILS["projectVersion"] @@ -658,6 +694,8 @@ def teardown(): yield -1 else: yield driver, reporting_client + + # Does a HTTP GET request to Perfecto cloud and gets response and information related to a headset def response_device(request, model): securityToken = PERFECTO_DETAILS["securityToken"] @@ -666,6 +704,7 @@ def response_device(request, model): resp = requests.get(url=url) return ET.fromstring(resp.content) + # Get an attribute value from the handset response def get_attribute_device(responseXml, attribute): try: @@ -674,6 +713,7 @@ def get_attribute_device(responseXml, attribute): print(f"Unable to get value of {attribute} from response") return "" + # Checks to see if a particular handset is available def is_device_available(request, model): try: @@ -690,6 +730,7 @@ def is_device_available(request, model): print("The device is currently allocated to:" + allocated_to) return False + # Checks whether the device is available or not.If the device is not available rechecks depending upon the # Checks whether the device is available or not.If the device is not available rechecks depending upon the @@ -699,24 +740,25 @@ def is_device_Available_timeout(request, model): timerValue = 5 timerThreshold = 80 if not device_available: - while(timerValue <= timerThreshold): + while (timerValue <= timerThreshold): print("Last checked at:" + strftime("%Y-%m-%d %H:%M:%S", gmtime())) print(f"Waiting for: {timerValue} min(s)") - time.sleep(timerValue*60) + time.sleep(timerValue * 60) print("Checking now at:" + strftime("%Y-%m-%d %H:%M:%S", gmtime())) device_available = is_device_available(request, model) - if(device_available): + if (device_available): return True else: timerValue = timerValue + 5 - if(timerValue > timerThreshold): + if (timerValue > timerThreshold): return False else: return True else: return True + def get_device_attribuites(request, model, attribute): try: responseXml = response_device(request, model) @@ -728,3 +770,35 @@ def get_device_attribuites(request, model, attribute): except: attribute_value = False return attribute_value + + +@pytest.fixture(scope="class") +def currentmav(request, get_apnos, get_configuration): + for access_point in get_configuration['access_point']: + cmd = "uci show ucentral" + print(get_configuration['access_point']) + ap_ssh = get_apnos(access_point, pwd="../libs/apnos/", sdk="2.x") + gw = ap_ssh.run_generic_command(cmd) + print("Status:") + print(gw) + connected, latest, active = ap_ssh.get_ucentral_status() + print("Connected:") + print(connected) + maverick = ap_ssh.set_maverick() + print("maverick:") + print(maverick) + iwinfo = ap_ssh.get_iwinfo() + print("iwinfo:") + print(iwinfo) + for key, value in iwinfo.items(): + print(key, ' : ', value[0]) + final = value[0] + return final + + + + + + + + diff --git a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/client_connect_test/android/test_general_security_modes.py b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/client_connect_test/android/test_general_security_modes.py index 86a89b4398f..e76044870a1 100644 --- a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/client_connect_test/android/test_general_security_modes.py +++ b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/client_connect_test/android/test_general_security_modes.py @@ -77,6 +77,7 @@ class TestBridgeModeConnectSuiteOne(object): @allure.testcase(url="https://telecominfraproject.atlassian.net/browse/WIFI-4570", name="WIFI-4570") @pytest.mark.fiveg @pytest.mark.wpa2_personal + @pytest.mark.Sub def test_ClientConnect_5g_WPA2_Personal_Bridge(self, request, get_vif_state, get_ap_logs, get_ToggleAirplaneMode_data, setup_perfectoMobile_android): diff --git a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_20mhz.py b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_20mhz.py index 31f9bf09fa3..54f9ce71de4 100644 --- a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_20mhz.py +++ b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_20mhz.py @@ -67,7 +67,6 @@ @pytest.mark.usefixtures("setup_profiles") class TestBridgeModeConnectSuiteOne(object): """ Client Connect SuiteOne - """ @allure.testcase(url="https://telecominfraproject.atlassian.net/browse/WIFI-7656", name="WIFI-7656") @@ -1728,3 +1727,4 @@ def test_ClientConnect_bridge_wpa2_chn144_20Mhz_US_5g(self, request, get_vif_sta else: allure.attach(name="Connection Status: ", body=str("Device is Unable to connect")) assert False + diff --git a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_40mhz.py b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_40mhz.py index 18f71fa0fea..7d6d19dd9e6 100644 --- a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_40mhz.py +++ b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_40mhz.py @@ -1162,6 +1162,4 @@ def test_ClientConnect_bridge_wpa2_chn11_40Mhz_US_2g(self, request, get_vif_stat assert True else: allure.attach(name="Connection Status: ", body=str("Device is Unable to connect")) - assert False - - + assert False \ No newline at end of file diff --git a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_80mhz.py b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_80mhz.py index ba8ebbc0b37..abaedd6212b 100644 --- a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_80mhz.py +++ b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/country_code_channel_division/country_code_US/iOS/test_US_80mhz.py @@ -1025,5 +1025,3 @@ def test_ClientConnect_bridge_wpa2_chn11_80Mhz_US_2g(self, request, get_vif_stat else: allure.attach(name="Connection Status: ", body=str("Device is Unable to connect")) assert False - - diff --git a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/rate_limiting/android/test_rate_limiting.py b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/rate_limiting/android/test_rate_limiting.py index 535fafda734..0dac8e80f11 100644 --- a/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/rate_limiting/android/test_rate_limiting.py +++ b/tests/e2e/interOp/validation_of_operating_modes/bridge_mode/rate_limiting/android/test_rate_limiting.py @@ -169,6 +169,7 @@ def test_rate_limiting_wpa2_5g(self, request, get_vif_state, get_ap_logs, @pytest.mark.wpa @pytest.mark.twog + @pytest.mark.speedcheckk def test_rate_limiting_wpa_2g(self, request, get_vif_state, get_ap_logs, get_ToggleAirplaneMode_data, setup_perfectoMobile_android): profile_data = setup_params_general["ssid_modes"]["wpa"][0] diff --git a/tests/fixtures_2x.py b/tests/fixtures_2x.py index 7b182034e52..f4f413f3d60 100644 --- a/tests/fixtures_2x.py +++ b/tests/fixtures_2x.py @@ -408,6 +408,11 @@ def setup_profiles(self, request, param, setup_controller, testbed, get_equipmen mode = "BRIDGE" instantiate_profile_obj.set_mode(mode=mode) vlan_id = 1 + if parameter['mode'] == "NONE": + mode = "NONE" + instantiate_profile_obj.set_mode(mode=mode) + vlan_id = 1 + print("No Mode is selected!..") if parameter['mode'] == "VLAN": mode = "VLAN" instantiate_profile_obj.set_mode(mode=mode)