• # coding=utf-8
    from appium import webdriver
    import time
    import unittest
    import os
    import os.path
    import xlrd
    
    class jbt(unittest.TestCase):
        @classmethod
        def setUpClass(cls):
            PATH = lambda x: os.path.join(os.path.dirname(os.path.realpath(__file__)), x)
            # print(PATH('zhihuiebao.apk'))
            desired_caps = {}
            desired_caps['platformName'] = 'Android'
            desired_caps['platformVersion'] = '7.0'
            desired_caps['deviceName'] = 'HMKNW17929029793'
            desired_caps['appPackage'] = 'com.jianbao.doctor'
            desired_caps['appActivity'] = '.activity.SplashActivity'
            desired_caps['app'] = PATH('zhihuiebao.apk')
            desired_caps['noReset'] = True
            desired_caps['noSign'] = True
            desired_caps["unicodeKeyboard"] = True
            desired_caps["resetKeyBoard"] = True
            desired_caps["automationName"] = 'uiautomator2'
            cls.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
        @classmethod
        def tearDownClass(cls):
            cls.driver.quit()
            print('teaDown')
    
        def test_name(self):
            path = r'D:\work\dropdesk\python\jbt_element.xlsx'
            excel = xlrd.open_workbook(path)
            sheet = excel.sheets()[0]
            element_data = sheet.row_values(0)
            assert_data = sheet.row_values(1)
            sendkeys = sheet.row_values(2)
            print(element_data, assert_data, sendkeys)
    
            driver = self.driver
            time.sleep(5)
            for i in range(4):
                driver.swipe(1000, 1000, 100, 1000, 1000)
    
            try:
                self.assertEqual(driver.find_element_by_xpath(element_data[1]).text, assert_data[1])
                driver.find_element_by_xpath(element_data[1]).click()
    
            except:
                pass
    
            # 账号
            time.sleep(5)
            self.driver.find_element_by_xpath(element_data[2]).send_keys(sendkeys[1])
            time.sleep(5)
            print('user_name is ok')
            self.driver.find_element_by_xpath(element_data[3]).send_keys(sendkeys[2])
            print('user_pw is ok')
            # self.driver.back()
            time.sleep(2)
            self.driver.find_element_by_xpath(element_data[4]).click()
            time.sleep(10)
            self.assertEqual(self.driver.find_element_by_xpath(element_data[5]).text, assert_data[2])
            time.sleep(2)
            # self.driver.back()
            self.driver.find_element_by_xpath(element_data[6]).click()
            time.sleep(3)
            self.driver.find_element_by_xpath(element_data[7]).click()
            print("选定城市")
            driver.get_screenshot_as_file("./jbt_login.png")
    
    
    
    if __name__ == '__main__':
        unittest.main()
    
    

  • from appium import webdriver
    import unittest
    import time
    import  selenium
    
    class test_Case(unittest.TestCase):
        def setUp(self):
            caps = {}
            caps["platformName"] = "IOS"
            caps["deviceName"] = "iphone"
            caps["automationName"] = "XCUITest"
            caps["platformVersion"] = "11.3.1"
            caps["udid"] = "1ec199ea8d17687e0f7f42888552baa509494f9a"
            caps['bundleId'] = 'com.example.apple-samplecode.UICatalog.dxh'
            caps["newCommandTimeout"] = 600
            self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
    
    
    
        def tearDown(self):
    
            self.driver.quit()
            print("out")
    
        def wait_element(self,xpath, timeout=30):
            # driver = self.driver
            deadline = time.time() + timeout
            while time.time() < deadline:
                try:
                    el = self.driver.find_element_by_xpath(xpath)
                    return el
                except selenium.common.exceptions.NoSuchElementException:
                    time.sleep(.2)
            raise RuntimeError("NoSuchElementException in wait_element")
    
        def test_1(self):
            self.wait_element('//*[@name="Action Sheets"]').click()
            time.sleep(2)
            self.driver.find_element_by_xpath('//*[@name="Okay / Cancel"]').click()
            time.sleep(3)
            self.driver.get_screenshot_as_file("./uicatalog.png")
    
    
    
    if __name__ == '__main__':
        unittest.main()
    
    
    
  • # -*- coding: utf-8 -*-
    from appium import webdriver
    import time
    import unittest
    import HTMLTestRunner
    class net_music(unittest.TestCase):
        @classmethod
        def setUpClass(cls):
            desired_caps = {}
            desired_caps['platformName'] = 'Android'
            desired_caps['platformVersion'] = '7.0'
            desired_caps['deviceName'] = 'HMKNW17929029793'
            desired_caps['appPackage'] = 'com.netease.cloudmusic'
            desired_caps['appActivity'] = '.activity.LoadingActivity'
            desired_caps['noReset'] = True
            desired_caps["unicodeKeyboard"] = True
            desired_caps["resetKeyBoard"] = True
            desired_caps["newCommandTimeout"] = 600
            cls.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
        @classmethod
        def tearDownClass(cls):
            cls.driver.quit()
    
        def test_case_1(self):
            time.sleep(10)
    
            try:
                self.assertEqual(self.driver.find_element_by_id("com.netease.cloudmusic:id/k9").text, "立即体验")
                print("app第一次安装")
                self.driver.find_element_by_id("com.netease.cloudmusic:id/k9").click()
            except:
                print("app不是第一次安装")
            time.sleep(10)
            # 点击搜索按钮
            self.driver.find_element_by_xpath(u'//android.widget.TextView[@content-desc="搜索"]').click()
            time.sleep(5)
            # 输入搜索歌名
            self.driver.find_element_by_id("com.netease.cloudmusic:id/search_src_text").send_keys("500 miles")
            time.sleep(5)
            # 选定歌曲
            self.driver.find_element_by_id("com.netease.cloudmusic:id/ays").click()
            time.sleep(5)
            # 播放
            self.driver.find_element_by_id("com.netease.cloudmusic:id/e4").click()
            time.sleep(10)
    
    
    if __name__ == '__main__':
        suite = unittest.TestSuite()
        suite.addTest(net_music("test_case_1"))
        #unittest.TextTestRunner(verbosity=2).run(suite)
        timestr = time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(time.time()))
        print(time.localtime(time.time()))
        filename = r'D:\study\appium\appium_report\appium_report_' + timestr + '.html'
        print(timestr)
        print(filename)
        fp = open(filename, "wb")
        runner = HTMLTestRunner.HTMLTestRunner(
            stream=fp,
            title='result',
            description='report'
        ).run(suite)
        fp.close()
    
  • http://127.0.0.1:4723/wd/hub/session
    

    http://127.0.0.1:4723/wd/hub/session/fe5c4b6d-1161-495f-9d19-1443d605e2db/element
    

    http://127.0.0.1:4723/wd/hub/session/fe5c4b6d-1161-495f-9d19-1443d605e2db/element/1/click
    

    http://127.0.0.1:4723/wd/hub/session/fe5c4b6d-1161-495f-9d19-1443d605e2db
    

  • 请问提示 请选择用例 是啥问题,找到原因了吗

  • 请问你这个问题解决了吗,连接不上数据库,我本地其他服务都能数据库连上。。。

    额,这个默认端口是3306,之前配置的不是这个端口。。


  • 这里错了啊,检查下路径是否准确

  • 你这个198楼已经给出方法了

  • 我们是在数据库中加密/解密,然后用正则拉出来~

  • 测试做得有些迷茫 at 2018年01月12日
    仅楼主可见