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()

posted @ 2018-06-16 17:26  天际流云  阅读(117)  评论(0编辑  收藏  举报