'Selenium Python - Login to application from Azure DevOps
MyScript is working totally fine in local with load_dontenv()
I am trying to pass username and password to my Python Test Script from Azure DevOps(Library->SecretFile) which is .env
content of .env (no filename give for .env .env named as .env)
[email protected]
PASSWORD=examplepassword
YAML file
script: | pip3 install python-dotenv displayName: 'Install dotenv'
task: DownloadSecureFile@1 inputs: secureFile: '.env'
script: | seleniumbase install chromedriver displayName: 'Install chromedriver'
script: | pip install pytest pytest-azurepipelines displayName: 'Install Pytest' env:
USERNAME_YAML: $(USERNAME)
PASSWORD_YAML: $(PASSWORD)
script: | pytest example.py --browser=chrome -n=8 -v -s --slow displayName: 'Login Test'
python script
import requests
from seleniumbase import BaseCase
from datetime import datetime
from selenium.webdriver.common.keys import Keys
import os
class smoke(BaseCase):
#.env file info
username=os.getenv('USERNAME_YAML')
password=os.getenv('PASSWORD_YAML')
def leadverification(self):
if self.env=="production":
self.open("https://prd.cms.com")
elif self.env=="develop":
self.open("https://dev.cms.com")
self.update_text(self.cmsemail,self.username)
self.update_text(self.cmspword,self.password)
self.click(self.cmsloginbtn)
Error Message in Azure Pipeline:
selector - the selector of the text field
text - the new text to type into the text field
by - the type of selector to search by (Default: CSS Selector)
timeout - how long to wait for the selector to be visible
retry - if True, use JS if the Selenium text update fails
"""
self.__check_scope()
if not timeout:
timeout = settings.LARGE_TIMEOUT
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
timeout = self.__get_new_timeout(timeout)
selector, by = self.__recalculate_selector(selector, by)
if self.__is_shadow_selector(selector):
self.__shadow_type(selector, text, timeout)
return
element = self.wait_for_element_visible(
selector, by=by, timeout=timeout
)
self.__demo_mode_highlight_if_active(selector, by)
if not self.demo_mode and not self.slow_mode:
self.__scroll_to_element(element, selector, by)
try:
element.clear() # May need https://stackoverflow.com/a/50691625
backspaces = Keys.BACK_SPACE * 42 # Is the answer to everything
element.send_keys(backspaces) # In case autocomplete keeps text
except (StaleElementReferenceException, ENI_Exception):
self.wait_for_ready_state_complete()
time.sleep(0.16)
element = self.wait_for_element_visible(
selector, by=by, timeout=timeout
)
try:
element.clear()
except Exception:
pass # Clearing the text field first might not be necessary
except Exception:
pass # Clearing the text field first might not be necessary
self.__demo_mode_pause_if_active(tiny=True)
pre_action_url = self.driver.current_url
if type(text) is int or type(text) is float:
text = str(text)
try:
> if not text.endswith("\n"):
E AttributeError: 'NoneType' object has no attribute 'endswith'
Solution 1:[1]
Based on your error:
AttributeError: 'NoneType' object has no attribute 'endswith'
That would have come from one of the following two lines if either self.username or self.password was None (The Python 'NoneType'):
self.update_text(self.cmsemail,self.username)
self.update_text(self.cmspword,self.password)
And those lines would have an issue if one of these next lines wasn't pulling data:
username=os.getenv('USERNAME_YAML')
password=os.getenv('PASSWORD_YAML')
So I would check to see that those lines return strings, or else you'll run into the issue you had.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Michael Mintz |
