• “I love you not for who you are, but for who I am with you.”—Edward Scissorhands
    我爱你不是因为你是谁,而是我在你面前可以是谁 ---《剪刀手爱德华》

  • 作业五

  • 作业4

  • 作业3

  • 作业1

  • 第二题

  • #许庚超

    weather: rain
    title: 杭州线下第一期_Yaml作业
    room:
    number: 309
    place: 浙江\n杭州\n沈塘桥\n中国电信
    wifi:
    - xiaomi_0E09
    - '12345678'
    smoking: false
    peoples:
    - Susan
    - Sully
    - Smile
    - Ruby
    - Your-Name
    food: ~
  • Author only
  • 作业二

    目录结构(已Testerhomelogin2为例)

    loginpage.py

    class LoginPage():

    #登陆页面的输入用户名的框
    def input_username(self,driver):
    return driver.find_element_by_id('user_login')

    #登陆页面输入密码的框
    def input_password(self,driver):
    return driver.find_element_by_id('user_password')
    #登陆页面的登陆按钮
    def click_commit(self,driver):
    return driver.find_element_by_name("commit")

    #登陆页面的记住我按钮
    def click_remeberme(self,driver):
    return driver.find_element_by_id('user_remember_me')

    #对输入框进行输入操作
    def action_sendkeys(self,ele,values):
    ele.send_keys(values)

    #对控件进行点击操作
    def action_click(self,ele):
    ele.click()

    #登陆的业务流程
    def testerhomelogin(self,driver,username,password):
    self.action_sendkeys(self.input_username(driver),username)
    print ("输入用户名:",username)
    self.action_sendkeys(self.input_password(driver),password)
    print ("输入密码:",password)
    self.action_click(self.click_remeberme(driver))
    print("选中记住我")
    self.action_click(self.click_commit(driver))
    print ("点击登录按钮")

    register.py

    class RegisterPage():

    #用户名元素
    def input_username(self,driver):
    return driver.find_element_by_id("user_login")

    #名字元素
    def input_name(self,driver):
    return driver.find_element_by_id("user_name")

    #Email元素
    def input_email(self,driver):
    return driver.find_element_by_id("user_email")

    #密码元素
    def input_password(self,driver):
    return driver.find_element_by_id("user_password")

    #确认密码元素
    def input_password_confirmation(self,driver):
    return driver.find_element_by_id("user_password_confirmation")

    #验证码元素
    def input_rucaptcha(self,driver):
    return driver.find_element_by_name("_rucaptcha")

    #提交注册信息按钮
    def click_commit(self,driver):
    return driver.find_element_by_name("commit")

    #定义输入操作
    def action_sendkeys(self,ele,values):
    ele.send_keys(values)

    #定义点击按钮操作
    def action_click(self,ele):
    ele.click()

    #testerhome注册逻辑
    def testerhome_register(self,driver,args):#可变参数如何使用
    #输入用户名
    self.action_sendkeys(self.input_username(driver),args[0])
    print("输入用户名:",args[0])
    #输入名字
    self.action_sendkeys(self.input_name(driver),args[1])
    print("输入名字:",args[1])
    #输入Email
    self.action_sendkeys(self.input_email(driver),args[2])
    print("输入邮箱:",args[2])
    #输入密码
    self.action_sendkeys(self.input_password(driver),args[3])
    print("输入密码:",args[3])
    #再次输入密码(确认密码)
    self.action_sendkeys(self.input_password_confirmation(driver),args[4])
    print("确认密码:",args[4])
    #输入验证码
    self.action_sendkeys(self.input_rucaptcha(driver),args[5])
    print("输入验证码:",args[5])
    #点击提交注册信息按钮
    self.action_click(self.click_commit(driver))
    print("点击注册按钮”)

    testerhomecase.py

    from selenium import webdriver
    import unittest
    import loginpage
    import register

    class TesterhomeCase(unittest.TestCase):
    def setUp(self):
    self.driver=webdriver.Chrome()
    self.driver.maximize_window()


    def test_login_01_case(self,username="testuser",password="123456"):
    self.driver.get("https://testerhome.com/account/sign_in")
    testerhomelogin=loginpage.LoginPage()
    testerhomelogin.testerhomelogin(self.driver,username,password)

    def test_register_01_case(self):
    self.driver.get("https://testerhome.com/account/sign_up")
    testerhomeregister=register.RegisterPage()
    #测试数据,一个list
    testdata=["testuser","testuser2","123456@qq.com","123456","123456","xasdf"]
    testerhomeregister.testerhome_register(self.driver,testdata)

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


    if __name__ == "__main__":
    unittest.main()

    运行结果

    没有完成部分

    1.Xpath 和css selector还不是很懂,在查找元素的时候没有使用这俩种方法,后面补充上去
    2.excel作为数据驱动这块没有加上去
    3.PageObjects的还不是很理解,希望老师这块多讲讲

  • import xlrd
    from appium import webdriver
    import unittest
    import time
    import selenium


    class SnowBallTestCase(unittest.TestCase):
    # @classmethod
    def setUp(self):
    caps={}
    caps["platformName"] = "Android"
    caps["deviceName"] = "demo"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    # caps["platformVersion"] = '5.0.0'
    caps["newCommandTimeout"] = 600
    caps["unicodeKeyboard"] = True
    caps["resetKeyboard"] = True
    caps["noReset"] = True
    caps["automationName"] ="UiAutomator2"
    self.driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub",caps)
    self.driver.implicitly_wait(20)

    # @classmethod
    def tearDown(self):
    self.driver.quit()

    #send_keys的值还没有做到读取
    #断言还没有加上去
    #有更新和跳过页面的还未处理
    def test_login(self):
    CaseList=self.change_Excel_ToCase("SnowBallUiTestCase.xlsx",'login')
    self.runCase(CaseList)

    def test_addBallFriends(self):
    CaseList=self.change_Excel_ToCase("SnowBallUiTestCase.xlsx",'addBallFriends')
    self.runCase(CaseList)

    def runCase(self,CaseList):
    for eachaction in CaseList:
    if eachaction[0]=='click':
    self.wait_find_elemet(eachaction[2],eachaction[3]).click()
    else:
    self.wait_find_elemet(eachaction[2],eachaction[3]).send_keys('12345678')
    print(eachaction[1])

    def change_Excel_ToCase(self,filepath,sheetname):
    excelpath=filepath
    workbook=xlrd.open_workbook(excelpath) #打开excel文件
    worksheet=workbook.sheet_by_name(sheetname) #获取待测casesheet的表格
    CaseList=[]
    max_rows=worksheet.nrows
    for i in range(0,max_rows):
    rowvalues=worksheet.row_values(i)
    if "no" in rowvalues[-1]:
    continue
    else:
    templist=[]
    templist.append(rowvalues[0])
    templist.append(rowvalues[-2])
    if worksheet.row_values(i)[1] != "NULL":
    templist.append(worksheet.row_values(0)[1])
    templist.append(worksheet.row_values(i)[1])
    elif worksheet.row_values(i)[2] != "NULL":
    templist.append(worksheet.row_values(0)[2])
    templist.append(worksheet.row_values(i)[2])
    else:
    templist.append(worksheet.row_values(0)[3])
    templist.append(worksheet.row_values(i)[3]) #templist=['click','点击-我的','id','com.xueqiu.android:id/tv_login']
    CaseList.append(templist)
    print (CaseList)
    return CaseList


    def wait_find_elemet(self,method,conditions,timeout=30):
    deadtime=time.time()+timeout
    while time.time() < deadtime:
    try:
    if method =="xpath":
    ele=self.driver.find_element_by_xpath(conditions)
    elif method== "id":
    ele=self.driver.find_element_by_id(conditions)
    else:
    ele=self.driver.find_element_by_accessibility_id(conditions)
    return ele
    except selenium.common.exceptions.NoSuchElementException:
    time.sleep(1)
    raise RuntimeError("No such Element!")


    if __name__ == "__main__":
    unittest.main()

    test_login 的截图

    运行结果截图

    test_addBallFriends的步骤截图和运行结果截图



    疑问

    同时运行test_login 和 test_addBallFriends 这俩个case的时候,如果不添加caps["automationName"] ="UiAutomator2", test_addBallFriends这个case中下拉列表无法定位,如果添加这个属性,test_login这个case的某些元素就无法定位, 这种情况该怎么做容错?

  • 作业一

    import time
    import unittest

    from appium import webdriver

    import selenium


    def wait_element(driver,xpath,timeout=30):
    timeouts=time.time()+timeout
    while time.time() < timeouts:
    try:
    el=driver.find_element_by_xpath(xpath)
    return el
    except selenium.common.exceptions.NoSuchElementException:
    time.sleep(2)
    raise RuntimeError("No such Element!")


    class Testios(unittest.TestCase):
    def setUp(self):
    caps={}
    caps['bundleId']= "com.example.apple-samplecode.UICatalog.dxh"
    self.driver =webdriver.Remote("http://192.168.31.77:8100/wd/hub",caps)
    # self.driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub",caps)

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

    def testone(self):
    wait_element(self.driver,"//*[@name='Action Sheets']").click()
    time.sleep(2)
    wait_element(self.driver,'//*[@name="Okay / Cancel"]').click()
    ok_element=wait_element(self.driver,"//XCUIElementTypeButton[@name='OK']")
    self.assertEquals(ok_element.text,'OK',"element is not ok button")
    time.sleep(2)
    print (self.driver.session_id)


    if __name__ == "__main__":
    unittest.main()

  • python代码实现

    from appium import webdriver
    import unittest

    class XueqiuDemo(unittest.TestCase):
    def setUp(self):
    caps = {}
    caps["platformName"] = "Android"
    caps["deviceName"] = "demo"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    caps['newCommandTimeout'] = 600
    # self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
    self.driver = webdriver.Remote("http://192.168.31.99:4723/wd/hub", caps)
    self.driver.implicitly_wait(30)

    def testxueqiu(self):
    self.driver.find_element_by_id("user_profile_icon").click()
    self.driver.find_element_by_id("tv_login").click()
    self.driver.find_element_by_id("tv_login_by_phone_or_others").click()
    self.driver.find_element_by_id("register_phone_number").send_keys("1589943251")
    self.driver.find_element_by_id("register_code").send_keys("2345")
    self.driver.find_element_by_id("button_next").click()
    self.driver.gsm_call("13758119492",'call') #只支持模拟器
    self.driver.background_app(3) # app 切换到后台3秒钟
    self.driver.launch_app()

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

    if __name__ == "__main__":
    unittest.main()

    修改本地command.py

    修改本地webdriver.py

    运行结果

  • newCommandTimeout是不是应该是600,也不是字符串吧

  • 作业一

    # This sample code uses the Appium python client
    # pip install Appium-Python-Client
    # Then you can paste this into a file and simply run with Python


    from appium import webdriver
    import unittest
    import time
    class neteasedemo(unittest.TestCase):
    def setUp(self):
    caps = {}
    caps["platformName"] = "Android"
    caps["deviceName"] = "HA598PNVCE4LAMGM"
    caps["appPackage"] = "com.netease.cloudmusic"
    caps["appActivity"] = ".activity.LoadingActivity"
    caps["newCommandTimeout"] = 600
    caps["unicodeKeyboard"] = True #able to input unicode
    caps["resetKeyboard"] = True # hide the system keyboard
    self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
    self.driver.implicitly_wait(20)
    print ("sessionId:",self.driver.session_id)

    def tearDown(self):
    print ('-----start to quit unit test!---')
    self.driver.quit()

    def testPlaySong(self):
    #skip the login page
    skip_btn = self.driver.find_element_by_id("com.netease.cloudmusic:id/k9")
    skip_btn.click()
    #click the search button
    search_btn = self.driver.find_element_by_accessibility_id("搜索")
    search_btn.click()
    # input the song which you want to search
    search_song = self.driver.find_element_by_id("com.netease.cloudmusic:id/search_src_text")
    search_song.send_keys("房东的猫")
    # press enter key on the keyboard!
    self.driver.press_keycode(66)
    #click to play the song
    play_song_btn = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.support.v4.view.ViewPager/android.widget.ListView/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.RelativeLayout")
    play_song_btn.click()


    if __name__ =="__main__":
    unittest.main()






  • 代码

    import unittest
    from appium import webdriver

    class apidemotest(unittest.TestCase):
    def setUp(self):
    caps = {}
    caps["platformName"] = "Android"
    caps["deviceName"] = "demo"
    caps["appPackage"] = "com.example.android.apis"
    caps["appActivity"] = ".ApiDemos"
    caps["newCommandTimeout"] = 600
    self.driver=webdriver.Remote("http://localhost:4723/wd/hub", caps)
    self.driver.implicitly_wait(20)
    print ("Session:",self.driver.session_id)

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

    def testclickapp(self):
    el1 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.ListView/android.widget.TextView[3]")
    el1.click()

    if __name__ == '__main__':
    unittest.main()

    运行结果

  • 创建seesion

    http://127.0.0.1:4723/wd/hub/session

    查找控件 App的位置

    http://127.0.0.1:4723/wd/hub/session/e29f70dc-26b6-47ef-8dde-6539747ed68b/element

    完成点击

    http://127.0.0.1:4723/wd/hub/session/e29f70dc-26b6-47ef-8dde-6539747ed68b/element/1/click

    销毁session

    http://127.0.0.1:4723/wd/hub/session/e29f70dc-26b6-47ef-8dde-6539747ed68b

  • # This sample code uses the Appium python client
    # pip install Appium-Python-Client
    # Then you can paste this into a file and simply run with Python

    from appium import webdriver

    caps = {}
    caps["platformName"] = "Android"
    caps["deviceName"] = "demo"
    caps["appPackage"] = "com.example.android.apis"
    caps["appActivity"] = ".ApiDemos"
    caps["newCommandTimeout"] = "600"

    driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

    el1 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.ListView/android.widget.TextView[3]")
    el1.click()
    print (driver.session_id)
    #session_id:8ea03033-d0e7-4158-a199-8828f5a483b2
    driver.quit()
  • # This sample code uses the Appium python client
    # pip install Appium-Python-Client
    # Then you can paste this into a file and simply run with Python

    from appium import webdriver
    # import time


    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "demo"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"

    driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

    driver.implicitly_wait(30)
    el1 = driver.find_element_by_id("com.xueqiu.android:id/user_profile_icon")
    el1.click()
    el2 = driver.find_element_by_id("com.xueqiu.android:id/tv_login")
    el2.click()
    el3 = driver.find_element_by_id("com.xueqiu.android:id/tv_login_by_phone_or_others")
    el3.click()
    el4 = driver.find_element_by_id("com.xueqiu.android:id/register_phone_number")
    el4.send_keys("1589943251")
    el5 = driver.find_element_by_id("com.xueqiu.android:id/register_code")
    el5.send_keys("2345")
    el6 = driver.find_element_by_id("com.xueqiu.android:id/button_next")
    el6.click()

    driver.quit()
  • 作业四

    $ curl https://testerhome.com/search?q=shell |grep -A 1 'class="topic title' | grep -v -e "--" -e "<d" | sed 's/<em>//g' | sed 's#</em>##g' |awk -F '>' '{print $2}' | awk -F '<' '{print $1}' |sed 's/&quot;//g'

  • 作业一

    $ curl https://testerhome.com 2>/dev/null | grep -B 1 "fa fa-diamond" | grep -v -e "fa fa-diamond" -e "--" |sed 's/ //g'

    ##Output:
    selenium+PIL+tesseract实现web简单验证码识别
    十年了,回顾一路走来的测试
    当阿里云遇上docker(萌新入门三天两夜苦战docker记录贴)
    自研的接口自动化测试平台
    Planting为测试工程师开发的部署框架
    UI自动化测试项目[AirtestProject]资源汇总
    使用Python测试DLL/SO动态链接库接口
    使用PythonJPype模块调用Jar
    UiAutomator2检测Toast信息方法
    app_process与反射大法实现安卓截屏
    如何攻破Web软件(Howtobreakwebsoftware)
    [持续交付实践]从交付流水线到研发协作平台
    59元小米智能插座改造客厅灯日记
    HtmlTestRunner_cn1.1,支持截图,失败重试,兼容py2&amp;py3
    TesterHome深圳线下第一期职业辅导沙龙总结以及PPT
    MySQL技术内幕—InnoDB存储引擎(第二版)》读后总结
    全周期的数据环境方案-MacacaDataHub
    关于jmeter性能测试的局限性
    网易UI自动化工具Airtest浅用记录
    利用anyproxyapp网络流量测试

  • 作业一

    $ for file in *
    > do
    > if [ -f "$file" ]
    > then
    > echo $file is a file
    > else
    > echo $file is a directory
    > fi
    > done

  • 广告 sdk 自动化测试实践 at November 10, 2017

    👍

  • 支持