Selenium Python-从Azure DevOps登录到应用程序



MyScript在本地使用load_dontenv((时工作得非常好

我正试图将用户名和密码从Azure DevOps(库->SecretFile(传递到我的Python测试脚本,该脚本是.env

.env的内容(没有为.env.env命名的文件名(

USERNAME=user@username.com
PASSWORD=examplepassword

YAML文件

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脚本

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)

Azure管道中的错误消息:

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'

基于您的错误:

AttributeError: 'NoneType' object has no attribute 'endswith'

如果self.usernameself.password为None(Python的"NoneType"(,则这将来自以下两行中的一行:

self.update_text(self.cmsemail,self.username)
self.update_text(self.cmspword,self.password)

如果下一条线路中有一条没有提取数据,那么这些线路就会出现问题:

username=os.getenv('USERNAME_YAML')
password=os.getenv('PASSWORD_YAML')

所以我会检查这些行是否返回字符串,否则就会遇到问题。

相关内容

最新更新