from appium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
import sys
sys.path.append(r'C:\Users\Administrator\PycharmProjects\appium_new')
from util.readConfig import read_ini
from util.get_by_local import locate_element
from appium import webdriver
from testcase.swipe import swipe
class test_login:
def get_driver(self):
capabilities = {
"platformName": "Android",
"deviceName": "127.0.0.1:62001",
"app": "C:\\Users\\Administrator\\PycharmProjects\\appium_new\\apk\\mukewang.apk"
, "noReset": "true",
"automationName": "UiAutomator2"
}
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', capabilities)
print(self.driver.current_activity)
time.sleep(10) # 不能省,启动需要时间
return self.driver
def login(self):
locate = locate_element(self.get_driver())
no_update = self.driver.find_element_by_id('cn.com.open.mooc:id/positiveBtn')
no_update.click()
mine = self.driver.find_elements_by_class_name('android.support.v7.app.ActionBar$Tab')
mine[3].click()
time.sleep(2)
self.driver.find_element_by_xpath('//*[contains(@text,"点击登录")]').click()
phone = self.driver.find_element_by_id('cn.com.open.mooc:id/account_edit')
phone.clear()
phone.send_keys('13166427863')
password = self.driver.find_element_by_id('cn.com.open.mooc:id/password_edit')
password.clear()
password.send_keys('x')
login_button = self.driver.find_element_by_id('cn.com.open.mooc:id/login')
login_button.click()
def test_webview(self):
# mine = driver.find_elements_by_class_name('android.support.v7.app.ActionBar$Tab')
# mine[1].click()
time.sleep(4)
webview = self.driver.contexts
print(webview)
def get_toast(self):
phone = self.driver.find_element_by_id('cn.com.open.mooc:id/account_edit')
phone.clear()
phone.send_keys('13166427863')
self.driver.find_element_by_xpath('//*[contains(@text,"点击登录")]').click()
toast_element = ("xpath", "//*[contains(@tsxt,'请输入密码')]")
WebDriverWait(self.driver, 10, 0.1).until(EC.presence_of_element_located(toast_element))
test_login=test_login()
# swipe=swipe()
# swipe.swipe_on('left')
# swipe.swipe_on('left')
# time.sleep(2)
# swipe.swipe_on('left')
# driver.find_element_by_id('cn.com.open.mooc:id/viewpager').click()
test_login.login()
C:\python32\python.exe C:/Users/Administrator/PycharmProjects/appium_new/testcase/test.py
com.imooc.component.imoocmain.splash.MCSplashActivity
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/appium_new/testcase/test.py", line 75, in <module>
test_login.login()
File "C:/Users/Administrator/PycharmProjects/appium_new/testcase/test.py", line 46, in login
password.send_keys('x')
File "C:\python32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "C:\python32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "C:\python32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in execute
self.error_handler.check_response(response)
File "C:\python32\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response
raise wde
File "C:\python32\lib\site-packages\appium\webdriver\errorhandler.py", line 24, in check_response
super(MobileErrorHandler, self).check_response(response)
File "C:\python32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: java.lang.NullPointerException
at android.support.test.uiautomator.UiObject2.setText(UiObject2.java:601)
at io.appium.uiautomator2.model.UiObject2Element.setText(UiObject2Element.java:129)
at io.appium.uiautomator2.handler.SendKeysToElement.safeHandle(SendKeysToElement.java:83)
at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:56)
at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:202)
at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:193)
at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:514)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:841)
Process finished with exit code 1