测试人社区

appium server端运行脚本报错a session is either terminated or not started

步骤:启动cmd,在命令行窗口输入appium,运行脚本,脚本代码如下

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support.wait import WebDriverWait


class TestDw():

    def setup(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['deviceName'] = 'emulator-5554'
        desired_caps['appPackage'] = 'com.xueqiu.android'
        desired_caps['appActivity'] = 'com.xueqiu.android.common.MainActivity'
        desired_caps['noReset'] = 'true'  # 不重置APP状态
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
        self.driver.implicitly_wait(10)

    def teardown(self):
        self.driver.quit()

    def test_search(self):
        '''
        进入搜索框,输入阿里巴巴,定位阿里巴巴股票价格
        '''
        self.driver.find_element_by_id('com.xueqiu.android:id/tv_search').click()
        self.driver.find_element_by_id('com.xueqiu.android:id/search_input_text').send_keys("阿里巴巴")
        self.driver.find_element_by_xpath('//*[@resource-id="com.xueqiu.android:id/name" and @text="阿里巴巴"]').click()
        locator = (MobileBy.ID, 'com.xueqiu.android:id/current_price')
        ele = WebDriverWait(self.driver, 10).until(lambda x: x.find_element(*locator))
        current_price = float(ele.text)
        assert current_price > 200

报错信息如下:

同样的脚本,使用appium desktop运行正常,日志附上日志.txt (29.7 KB)