mirror of
https://github.com/Telecominfraproject/wlan-testing.git
synced 2025-11-01 19:37:54 +00:00
Added Enterprise code in Android lib
This commit is contained in:
@@ -2062,6 +2062,346 @@ def reportClient(value):
|
||||
# except:
|
||||
# pass
|
||||
# return ssid_list
|
||||
#------------Enterprise Mode code----------------------------
|
||||
def get_ip_address_eap_and(request, WifiName, User, ttls_passwd, setup_perfectoMobile, connData):
|
||||
print("\n-------------------------------------")
|
||||
print("Select Wifi/AccessPoint Connection")
|
||||
print("-------------------------------------")
|
||||
print("Verifying Wifi Connection Details....")
|
||||
report = setup_perfectoMobile[1]
|
||||
driver = setup_perfectoMobile[0]
|
||||
|
||||
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"], 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.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']")
|
||||
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.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(3):
|
||||
available_ssids = get_all_available_ssids(driver)
|
||||
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 = 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")
|
||||
# -------------------------------------------------------
|
||||
|
||||
# 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")
|
||||
# -------------------------------------------------------
|
||||
|
||||
# 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: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
|
||||
# -------------------------------------------------------
|
||||
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")
|
||||
#allure.attach(name= body=str("IP address element not found"))
|
||||
|
||||
# closeApp(connData["appPackage-android"], setup_perfectoMobile)
|
||||
# return ip_address_element_text, ssid_with_internet
|
||||
|
||||
try:
|
||||
check_if_no_internet_popup(driver)
|
||||
driver.implicitly_wait(3)
|
||||
time.sleep(2)
|
||||
auto_reconnect_off = driver.find("//*[@resource-id='android:id/switch_widget']")
|
||||
auto_reconnect_off_text = auto_reconnect_off.text
|
||||
if auto_reconnect_off_text != "Off":
|
||||
auto_reconnect_off.click()
|
||||
print("Auto reconnect turning off")
|
||||
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")
|
||||
# -------------------------------------------------------
|
||||
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"], setup_perfectoMobile)
|
||||
return ip_address_element_text, ssid_with_internet
|
||||
|
||||
def close_driver(driver):
|
||||
driver.close()
|
||||
|
||||
Reference in New Issue
Block a user