模块未找到错误:Azure DevOps Selenium Python中没有名为"POM"的模块

k2fxgqgv  于 2023-01-11  发布在  Python
关注(0)|答案(1)|浏览(132)

请帮助我解决此错误:我在Azure DevOps上运行自动化测试Selenium Python。我可以在本地计算机上运行通过,但在Azure DevOps上运行失败

    • 1.这是错误日志:**
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents: shell
pytest -s  ./TestScript/test_smoketest.py --html=pytest_selenium_test_report.html
========================== Starting Command Output ===========================
"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\27823a4e-e3d1-4223-9442-76c34c20d6cd.cmd""
============================= test session starts =============================
platform win32 -- Python 3.7.9, pytest-7.2.0, pluggy-1.0.0
rootdir: D:\a\1\s
plugins: azurepipelines-1.0.4, html-3.2.0, metadata-2.0.4, nunit-1.0.3
collected 0 items / 1 error
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
No Result Found to Publish 'D:\a\1\s\test-output.xml'.
##[error]1 test(s) failed, 0 test(s) collected.
Skipping uploading of coverage data.

=================================== ERRORS ====================================
________________ ERROR collecting TestScript/test_smoketest.py ________________
ImportError while importing test module 'D:\a\1\s\TestScript\test_smoketest.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
c:\hostedtoolcache\windows\python\3.7.9\x64\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
TestScript\test_smoketest.py:10: in <module>
    from POM.loginPage import Loginpage
E   ModuleNotFoundError: No module named 'POM'
------------- generated Nunit xml file: D:\a\1\s\test-output.xml --------------
--- generated html file: file:///D:/a/1/s/pytest_selenium_test_report.html ----
=========================== short test summary info ===========================
ERROR TestScript/test_smoketest.py
!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
============================== 1 error in 0.11s ===============================
##[error]Cmd.exe exited with code '2'.

这是我的代码结构:enter image description here

    • 2.这是蓝色管道. yml:**
trigger:
- main

pool:
  vmImage: windows-latest

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '3.7'
    architecture: 'x64'

- script: |
    python -m pip install --upgrade pip
  displayName: 'Instal dependencies'
- script: |
    pip install webdriver-manager
    pip install selenium
    pip install pytest pytest-azurepipelines
    pip install pytest-html
    set PYTHONPATH
  displayName: 'Import libriary'

- script: |    
    pytest -s  ./TestScript/test_smoketest.py --html=pytest_selenium_test_report.html
  displayName: 'Run test script'
    • 3.这是测试脚本[test_smoketest. py]**
import pytest
import pytest_html
import sys
import os
import time
sys.path.append(os.path.join(os.path.dirname(__file__), "...", "..."))

from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from POM.loginPage import Loginpage
from POM.profile import Profile
from Setup import settings


@pytest.fixture
def driver():
    driver = webdriver.Chrome(ChromeDriverManager().install())
    driver.get(settings.link)
    driver.execute_script("localStorage.setItem('accessToken', '{}');".format(settings.accessToken_admin))
    time.sleep(2)
    driver.refresh()
    driver.maximize_window()
    yield driver
    driver.close()
    driver.quit()
    print("Complete test case")

def test_login_with_accessToken(driver):
    loginPage = Loginpage(driver)
    loginPage.wait_for_welcomeBanner()

def test_login_with_SSO(driver):
    profile = Profile(driver)    
    profile.click_Avartar()
    profile.click_Logout()
    time.sleep(6)
    loginPage = Loginpage(driver)
    loginPage.click_SSO()
    loginPage.input_email(settings.email)
    loginPage.click_remember()
    loginPage.click_login()
    loginPage.wait_for_welcomeBanner()

我尝试将init. py添加到每个文件夹,但仍然不起作用

enxuqcxy

enxuqcxy1#

尝试更改sys.path.append(os.path.join(os.path.dirname(__file__), "...", "..."))
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))

相关问题