为了测试一种情况,我在目录TestCases下新建了一个test_login.py和test_welcome.py,然后发现在模块里面各自运行时,都是正常的,在命令行运行时,后者可以正常,前者总是出错:

pytest加载测试用例的一个问题:A session is either terminated or not started

 

 

二. 测试代码分析

先看看两个模块的代码是怎么设计的

test_login.py

 

from appium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from appium.webdriver.common.mobileby import MobileBy
import time, pytest
import logging
from Common.my_logging import *


#操作对象的设备信息
desired_caps = {}
desired_caps["platformName"] = "Android"
desired_caps["platformVersion"] = "5.1.1"
desired_caps["deviceName"] = "Android Emulator"
desired_caps["appPackage"] = "com.xxzb.fenwoo"
desired_caps["appActivity"] = "com.xxzb.fenwoo.activity.addition.WelcomeActivity"

#连接appium
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(3)
logging.info("加载test_login")
logging.info("test_login_driver是: " + str(driver))



@pytest.mark.login
def test_login_success():
    logging.info("test_login开始了!")
    logging.info("test_login的driver是: " + str(driver))
    size = driver.get_window_size()
    for i in range(3):
        driver.swipe(size["width"] * 0.9, size["height"] * 0.5, size["width"] * 0.1, size["height"] * 0.5, 200)
    WebDriverWait(driver, 10, 1).until(EC.visibility_of_element_located((MobileBy.ID, "com.xxzb.fenwoo:id/btn_start")))
    driver.find_element_by_id("com.xxzb.fenwoo:id/btn_start").click()
    WebDriverWait(driver, 10, 1).until(EC.visibility_of_element_located((MobileBy.ID, "com.xxzb.fenwoo:id/btn_login")))
    driver.find_element_by_id("com.xxzb.fenwoo:id/btn_login").click()
    WebDriverWait(driver, 10, 1).until(EC.visibility_of_element_located((MobileBy.ID, "com.xxzb.fenwoo:id/et_phone")))
    driver.find_element_by_id("com.xxzb.fenwoo:id/et_phone").send_keys("18684720553")
    driver.find_element_by_id("com.xxzb.fenwoo:id/btn_next_step").click()
    WebDriverWait(driver, 10, 1).until(EC.visibility_of_element_located((MobileBy.ID, "com.xxzb.fenwoo:id/et_pwd")))
    driver.find_element_by_id("com.xxzb.fenwoo:id/et_pwd").send_keys("python")
    driver.find_element_by_id("com.xxzb.fenwoo:id/btn_next_step").click()
    assert True == True
View Code

相关文章:

  • 2021-06-03
  • 2022-12-23
  • 2021-08-08
  • 2021-12-28
  • 2021-07-17
  • 2021-06-08
  • 2021-06-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-05
  • 2021-04-23
  • 2021-12-07
  • 2022-12-23
  • 2020-10-01
  • 2022-12-23
相关资源
相似解决方案