zoukankan      html  css  js  c++  java
  • orderzmz

    #-*- coding:utf-8 -*-
    import APPMethod,PublicMethod,os
    from appium import webdriver
    from TOMTOP.androidtest import *
    from time import *
    
    class Order():
        def __init__(self,keywords):
            self.keywords=keywords
    
            conName='K06TJ64180003473'
            taskTepmDir='C:\01mywork\workspace\ROBOT\TestAutomationForIT5\data'
            #startAppium(conName,taskTepmDir)
            self.desired_caps = {}
            self.desired_caps['platformName']='Android'
            self.desired_caps['platformVersion']='6.0'
            self.desired_caps['deviceName']='K06TJ64180003473'
            self.desired_caps['appPackage']='com.amazon.mShop.android.shopping'
            self.desired_caps['appActivity']='com.amazon.mShop.home.HomeActivity'
            self.desired_caps['appWaitActivity']='com.amazon.mShop.home.HomeActivity'
            self.driver = webdriver.Remote('http://localhost:4723/wd/hub',self.desired_caps)
            self.driver.implicitly_wait(10)
    
        def search(self):
            driver=self.driver
            SetSougouIme(self.desired_caps['deviceName'])
            APPMethod.click_element(driver,'rs_search_src_text','id')
            driver.find_element_by_id('rs_search_src_text').send_keys(self.keywords)
            driver.press_keycode(66)
            SetAppiumIme(self.desired_caps['deviceName'])
    
        # 粗略的翻阅商品详情页
        def rough_reading_of_details(self):
            pass
    
        # 仔细的翻阅商品详情页
        def read_the_details_carefully(self):
            pass
    
        # 加入购物车
        def add_to_cart(self):
            driver=self.driver
            for i in range(5):
                driver.swipe(100,810,100,390)
                try:
                    sleep(2)
                    driver.find_element_by_accessibility_id('Add to Cart').click()
                except:
                    print u'没找到Add to Cart,再往下滑一下!'
    
        # 直接购买
        def buy_now(self):
            driver=self.driver
            for i in range(5):
                driver.swipe(100,810,100,390)
                try:
                    sleep(2)
                    driver.find_element_by_accessibility_id('Buy Now').click()
                except:
                    print u'没找到Buy Now,再往下滑一下!'
    
        # 选择颜色和尺寸
        def select_size_color(self):
            driver=self.driver
            APPMethod.wait_element_OK(driver,'glow_subnav_label','id')
            sleep(10)
            print u'上滑一下'
            driver.swipe(100,800,100,410)
            sleep(5)
            print u'点击选择尺寸按钮'
            locator=driver.find_element_by_xpath('//android.widget.Button[contains(@content-desc,"Size")]').location
            x=int(locator['x'])
            y=int(locator['y'])
            driver.tap([(x+300,y+60)])
            sleep(5)
            driver.tap([(82,657)])# 选择尺寸82 240 397
            sleep(5)
            driver.flick(100,800,500,800)# 快速右滑
            driver.flick(100,800,500,800)
            driver.tap([(130,1000)])# 选择颜色
            sleep(5)
            '''
            cmd='adb shell input keyevent 4'#触发手机上的back键,实现DONE退出
            os.popen(cmd)
            driver.tap([(640,475)])# 点击DONE坐标
            '''
            driver.find_element_by_accessibility_id('DONE').click()# 返回 DONE
            sleep(3)
            self.buy_now()
            cmd='adb shell input keyevent 4'#触发手机上的back键,实现退出
            os.popen(cmd)
            sleep(5)
    
        def for_product(self):
            driver=self.driver
            APPMethod.wait_element_OK(driver,'item_title','id')
            print u'开始向上滑动'
            for i in range(30):
                # 统计显示的商品名称数量,并打印
                p_title=driver.find_elements_by_id('item_title')
                for i in range(len(p_title)):
                    if p_title[i].text=="Lark & Ro Women's Sleeveless Color-Block A-Line Dress":
                        p_title[i].click()
                        self.select_size_color()
                        break
                # 滑动页面
                driver.swipe(100,800,100,410)
                PublicMethod.random_sleep(1,3)
            print u'向上滑动完成了'
    
    
    if __name__=='__main__':
        keywords='dress'
        order=Order(keywords)
        order.search()
        order.for_product()

    #-*- coding:utf-8 -*-import APPMethod,PublicMethod,osfrom appium import webdriverfrom TOMTOP.androidtest import *from time import *
    class Order():    def __init__(self,keywords):        self.keywords=keywords
            conName='K06TJ64180003473'        taskTepmDir='C:\01mywork\workspace\ROBOT\TestAutomationForIT5\data'        #startAppium(conName,taskTepmDir)        self.desired_caps = {}        self.desired_caps['platformName']='Android'        self.desired_caps['platformVersion']='6.0'        self.desired_caps['deviceName']='K06TJ64180003473'        self.desired_caps['appPackage']='com.amazon.mShop.android.shopping'        self.desired_caps['appActivity']='com.amazon.mShop.home.HomeActivity'        self.desired_caps['appWaitActivity']='com.amazon.mShop.home.HomeActivity'        self.driver = webdriver.Remote('http://localhost:4723/wd/hub',self.desired_caps)        self.driver.implicitly_wait(10)
        def search(self):        driver=self.driver        SetSougouIme(self.desired_caps['deviceName'])        APPMethod.click_element(driver,'rs_search_src_text','id')        driver.find_element_by_id('rs_search_src_text').send_keys(self.keywords)        driver.press_keycode(66)        SetAppiumIme(self.desired_caps['deviceName'])
        # 粗略的翻阅商品详情页    def rough_reading_of_details(self):        pass
        # 仔细的翻阅商品详情页    def read_the_details_carefully(self):        pass
        # 加入购物车    def add_to_cart(self):        driver=self.driver        for i in range(5):            driver.swipe(100,810,100,390)            try:                sleep(2)                driver.find_element_by_accessibility_id('Add to Cart').click()            except:                print u'没找到Add to Cart,再往下滑一下!'
        # 直接购买    def buy_now(self):        driver=self.driver        for i in range(5):            driver.swipe(100,810,100,390)            try:                sleep(2)                driver.find_element_by_accessibility_id('Buy Now').click()            except:                print u'没找到Buy Now,再往下滑一下!'
        # 选择颜色和尺寸    def select_size_color(self):        driver=self.driver        APPMethod.wait_element_OK(driver,'glow_subnav_label','id')        sleep(10)        print u'上滑一下'        driver.swipe(100,800,100,410)        sleep(5)        print u'点击选择尺寸按钮'        locator=driver.find_element_by_xpath('//android.widget.Button[contains(@content-desc,"Size")]').location        x=int(locator['x'])        y=int(locator['y'])        driver.tap([(x+300,y+60)])        sleep(5)        driver.tap([(82,657)])# 选择尺寸82 240 397        sleep(5)        driver.flick(100,800,500,800)# 快速右滑        driver.flick(100,800,500,800)        driver.tap([(130,1000)])# 选择颜色        sleep(5)        '''        cmd='adb shell input keyevent 4'#触发手机上的back键,实现DONE退出        os.popen(cmd)        driver.tap([(640,475)])# 点击DONE坐标        '''        driver.find_element_by_accessibility_id('DONE').click()# 返回 DONE        sleep(3)        self.buy_now()        cmd='adb shell input keyevent 4'#触发手机上的back键,实现退出        os.popen(cmd)        sleep(5)
        def for_product(self):        driver=self.driver        APPMethod.wait_element_OK(driver,'item_title','id')        print u'开始向上滑动'        for i in range(30):            # 统计显示的商品名称数量,并打印            p_title=driver.find_elements_by_id('item_title')            for i in range(len(p_title)):                if p_title[i].text=="Lark & Ro Women's Sleeveless Color-Block A-Line Dress":                    p_title[i].click()                    self.select_size_color()                    break            # 滑动页面            driver.swipe(100,800,100,410)            PublicMethod.random_sleep(1,3)        print u'向上滑动完成了'

    if __name__=='__main__':    keywords='dress'    order=Order(keywords)    order.search()    order.for_product()

  • 相关阅读:
    语句被终止。完成执行语句前已用完最大递归 100
    Sql日期时间格式转换(转)
    MVC 记录操作日志与过滤特殊字符
    掌握这些,自学效率嗖嗖的!
    正式开始聊聊自学那些事儿!
    《可执行的自学编程方法体系》前言-为什么我要分享自己的自学经验总结?
    系统化的学习才是有效的学习!
    知识学了就忘怎么办?
    “面试”是绝佳的学习方式!
    分水岭:知识的深度拓展
  • 原文地址:https://www.cnblogs.com/liuyun66535309/p/9190927.html
Copyright © 2011-2022 走看看