每次会调两次driver,第一次可以获取到i的值,第二次就获取错误,无法从.yaml中读取数据
来源:5-14 多进程、unittest、HTMLTestRunner、启动服务流程梳理代码重构

慕田峪3519252
2020-05-06
#base_driver
import time
from appium import webdriver
from util.write_user_command import WriteUserCommand
class BaseDriver:
def android_driverC(self,i):
print("this is app_androidC:",i)
#devices_name adb devices
#port
write_file = WriteUserCommand()
devices = write_file.get_value('user_info_'+str(i),'deviceName')
port = write_file.get_value('user_info_'+str(i),'port')
C_caps = {}
C_caps["platformName"] = "Android"
C_caps["platformVersion"] = "5.1"
C_caps["deviceName"] = devices
C_caps["app"] = "C:\\Users\\tingfeng\\Downloads\\youbei-1.5.0.apk"
C_caps["appPackage"] = "com.youbei.chefu"
C_caps["appWaitActivity"] = "com.youbei.chefu.MainActivity"
C_caps["noReset"] = True
#C_caps["unicodeKeyboard"] = True # 使用Unicode编码方式发送字符串
#C_caps["resetKeyboard"] = True # 隐藏键盘
print(C_caps)
c_driver = webdriver.Remote("http://127.0.0.1:"+ port +"/wd/hub", C_caps)
time.sleep(10)
return c_driver
login_page
from util.get_by_local import GetByLocal
import time
from driver import Push_Driver
from base.base_driver import BaseDriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class LoginPage:
#获取登录页面所有的页面元素信息
def __init__(self,i):
base_driver = BaseDriver()
self.driver = base_driver.android_driverC(i)
self.get_by_local = GetByLocal(self.driver)
def click(self):
self.get_by_local.get_element('washcar').click()
if __name__ =="__main__":
login_page = LoginPage(0)
login_page.click()
#get_by_local
class GetByLocal:
def __init__(self,i):
self.base_driver = BaseDriver()
self.driver = self.base_driver.android_driverC(i)
def get_element(self,key):
# 去localelement拿并区分
read_ini = Read_Ini()
local =read_ini.get_value(key)
if local != None: #不等于空才执行下面的步骤
by = local.split('>')[0]
local_by = local.split('>')[1]
#print(local_by)
if by == 'classname':
return self.driver.find_elements_by_class_name(local_by)
elif by == 'xpath':
return self.driver.find_element_by_xpath(local_by)
else:
return None
if __name__ == '__main__':
get_by_local = GetByLocal()
get_by_local.get_element('washcar')
- login_page去调base_driver启动,但每次会调两次,第一次i有值是0或1,第二次再调这应该是变成了session了吧 ,实在找不到问题了,求老师看下
#报错信息如下
D:\python3\python.exe D:/Pycharm/Project/new_appium/page/login_page.py
this is app_androidC: 0
{'platformName': 'Android', 'platformVersion': '5.1', 'deviceName': '127.0.0.1:21503', 'app': 'C:\\Users\\tingfeng\\Downloads\\youbei-1.5.0.apk', 'appPackage': 'com.youbei.chefu', 'appWaitActivity': 'com.youbei.chefu.MainActivity', 'noReset': True}
this is app_androidC: <appium.webdriver.webdriver.WebDriver (session="f4d2f39a-fff5-4a78-92f0-6db758b38bba")>
Traceback (most recent call last):
File "D:/Pycharm/Project/new_appium/page/login_page.py", line 24, in <module>
login_page = LoginPage(0)
File "D:/Pycharm/Project/new_appium/page/login_page.py", line 18, in __init__
self.get_by_local = GetByLocal(self.driver)
File "D:\Pycharm\Project\new_appium\util\get_by_local.py", line 11, in __init__
self.driver = self.base_driver.android_driverC(i)
File "D:\Pycharm\Project\new_appium\base\base_driver.py", line 15, in android_driverC
devices = write_file.get_value('user_info_'+str(i),'deviceName')
File "D:\Pycharm\Project\new_appium\util\write_user_command.py", line 27, in get_value
value = data[key][port]
KeyError: 'user_info_<appium.webdriver.webdriver.WebDriver (session="f4d2f39a-fff5-4a78-92f0-6db758b38bba")>'
Process finished with exit code 1
写回答
1回答
-
Mushishi
2020-05-07
ni这个i在哪里传递?
022020-05-08
相似问题