UI自动化+android+web测试基础3-3+购物车相关的测试用例

最近做了京东购物车相关的测试用例

1.将购物车内所有商品进行结算看价格是否跟结算价格一致

#-*- coding:utf-8 -*-
import  unittest
from util import firefoxutil,urlutil
class ShopCar(unittest.TestCase):
    # 实例化 对象用的
    @classmethod
    def setUpClass(self):
        # 实例化对象
        self.firefox=firefoxutil.FireFox()
        #实例化url
        self.URL=urlutil.URL()
        pass
    def setUp(self):
       self.firefox.firefox_start(self.URL.JD_SHOP_CAR)
       pass
    def tearDown(self):
        self.firefox.firefox_close()
        pass
    def test_shop_car(self):
        # 点击登陆按钮
        self.firefox.ClickLink("登录")

        # 设置休眠,以为有frame 需要弹出,所以需要时间让他弹出 设置五秒休眠
        self.firefox.TimeSleep(firefoxutil.ENUMS.FIVE_TIME)

        # 切换到frame
        self.firefox.seitch_to_id_frame("dialogIframe")
        # 点击账号登陆
        self.firefox.ClickClass("login-tab-r")
        # 输入用户名 密码 以及点击登陆按钮
        self.firefox.SendkeysID("loginname", "15284391655")
        self.firefox.SendkeysID("nloginpwd", "fei961216")
        # 点击登陆
        self.firefox.ClickID("loginsubmit")
        # 第一条购物车流程的的测试用例,点击全部选择商品,将商品所有的总价加起来
        self.firefox.ClickName("toggle-checkboxes")
        # 设置休眠时间,设置休眠的原因是因为我们在点击全部选中的时候,需要时间去反应过来,同时向服务器提交数据
        self.firefox.TimeSleep(firefoxutil.ENUMS.FIVE_TIME)
        #判断每一件商品的选择按钮有没有点上
        self.checkItems=self.firefox.FindNames("checkItem")
        #使用for 循环判断有没有选择上
        #在这里因为上面点击的全部选中,又因为购物车的数据是存在服务器上面的
        #那如果全部选中了,那么下一次再点击全部选中就成了一个都没有选中,
        # 所以我们需要对 checkbox 进行判断,如果选中了,就不点,没选中,我就给他全部手动选中
        for index in self.checkItems:
            if index.get_attribute("checked")!="true":
                index.click()
                # 设置休眠,原因是这里点击for循环太快,而点击选中,需要向服务器提交数据
                self.firefox.TimeSleep(firefoxutil.ENUMS.TWO_TIME)
        #计算五件商品的总价与总计的价格是不是相等
        #开始查找一组元素 返回是list列表
        self.prices=self.firefox.FindXpaths("//div[@class='item-form']/div[6]/strong")
        #使用for循环打印
        #注意网页里获取内容是unicode编码格式
        #首先我们需要对unicode格式进行编码,编码为utf-8格式
        #对编码的格式进行替换¥提交为空,在专为float类型,就可以进行加法运算`
        self.checkItems = self.firefox.FindNames("checkItem")
        #定义sum进行相加
        sums=0
        for index in range(0,len(self.prices)):
            #得到内容
            price_before=self.prices[index].text
            #进行utf-8编码
            price_aftre=price_before.encode("UTF-8")
            #对字符串进行转换
            price_replace=price_aftre.replace("¥"," ")
            #最后转为float类型
            price_float= float(price_replace)
            #打印内容
            print  price_float
            #判断如果是选中就加起来,没有选择的就不加起来
            print self.checkItems[index].get_attribute("checked")
            if self.checkItems[index].get_attribute("checked")=="true":
                sums+=price_float
        print  "总价",sums
        # 查找总价的控件,进行断言 xpath
        ems=self.firefox.FindXpath("//div[@class='price-sum']/div/span/em").text.encode("utf-8").replace("¥","")
        message=float(ems)
        self.assertEqual(sums,message)
        pass
自己慢慢看,会看懂的,至少比mvp强,哈哈哈
2. 第二条就是比如说我们购物车里有五件商品,我们做一个操作,第一件商品我们不点,后四件商品我们选上
#-*- coding:utf-8 -*- import unittest from util import firefoxutil,urlutil class ShopCheckBox(unittest.TestCase): @classmethod  def setUpClass(self): self.firefox=firefoxutil.FireFox() self.URL=urlutil.URL() pass  def setUp(self): self.firefox.firefox_start(self.URL.JD_SHOP_CAR) pass  def tearDown(self): self.firefox.firefox_close() pass  def shop_login(self): # 点击登录按钮,登录进去  # 点击登陆按钮  self.firefox.ClickLink("登录") # 设置休眠,以为有frame 需要弹出,所以需要时间让他弹出 设置五秒休眠  self.firefox.TimeSleep(firefoxutil.ENUMS.FIVE_TIME) # 切换到frame  self.firefox.seitch_to_id_frame("dialogIframe") # 点击账号登陆  self.firefox.ClickClass("login-tab-r") # 输入用户名 密码 以及点击登陆按钮  self.firefox.SendkeysID("loginname", "13193571088") self.firefox.SendkeysID("nloginpwd", "123123.") # 点击登陆  self.firefox.ClickID("loginsubmit") # 设置休眠,因为登录需要反应时间  self.firefox.TimeSleep(firefoxutil.ENUMS.FIVE_TIME) pass  def test_checkbox_four_one(self): self.shop_login() #测试用例如下,因为上面和下面都有全部选择按钮,首先我们点击上面全选按钮  #接下来下面的五件商品有没有全部选中,如果全部选中,我们将第一个选择为不选中  #如果没有全部选中,那我们就讲后面的四个选中,第一个不选中  #如果有几个是选中的,有几个是未选中的,我们就将第一个不选中。后面几个选中   #点击全部选中按钮  self.firefox.ClickClass("jdcheckbox") # 查询五个checkbox是不是全部选中  self.checkItems=self.firefox.FindNames("checkItem") # 使用 for循环取判断  for index in range(0,len(self.checkItems)): #如果index为0,如果是选中状态我们就改成不选中,其他如果是不选中状态我们就改成选中状态  if index==0: if self.checkItems[index].get_attribute("checked")=="true": #点击一下,设置为不选中  self.checkItems[index].click() #设置休眠,因为选中以后,需要服务器提交数据,需要时间刷新浏览器  self.firefox.TimeSleep(firefoxutil.ENUMS.TWO_TIME) else: if self.checkItems[index].get_attribute("checked")!="true": self.checkItems[index].click() self.firefox.TimeSleep(firefoxutil.ENUMS.TWO_TIME) # 我们再次重新查找控件,判断是不是第一个是未选中的,后面四个是选中的  self.checkItems=self.firefox.FindNames("checkItem") # 使用 for循环 和断言来判断是不是符合我们的预期  for index in range(0,len(self.checkItems)): if index ==0: #断言 获取的属性值是不是为空  self.assertEqual(self.checkItems[index].get_attribute("checked"),None) else: #断言 是不是为true 因为我们选中返回的是true  isSelect=self.checkItems[index].get_attribute("checked") self.assertTrue(isSelect) #通过class查询一组全部选选择控件  self.jdcheckboxs=self.firefox.FindNames("toggle-checkboxes") #使用for循环  for index in range(0,len(self.jdcheckboxs)): print index self.firefox.TimeSleep(firefoxutil.ENUMS.TWO_TIME) #获取属性,进行断言,判断是不是选中  self.assertEqual(self.jdcheckboxs[index].get_attribute("checked"),None) #验证复选框的全部选中有没有效果

3.我们做的就是购物车的

def test_select_all(self):
    # 调用登陆的方法
    self.shop_login()
    #验证全部选中
    #默认选项框有两种情况存在
    #一种是全部被选中或者全部不被选中,或者有一部分选中一部分没有选中
    #我们要的肖国盛全部选中
    #查找购物车里面的复选框,无论多少个,通过列表返回
    self.checkItems=self.firefox.FindNames("checkItem")
    #for 循环
    for item in self.checkItems:
        #获取属性,进行判断
        if item.get_attribute("checked")!="true":
            #点击一下
            item.click()
            # 设置休眠的原因是因为网络加载需要时间
            self.firefox.TimeSleep(firefoxutil.ENUMS.TWO_TIME)

    #进行断言
    #查找全部选中按钮,看看有没有没选中
    self.toggle_checkboxes=self.firefox.FindNames("toggle-checkboxes")
    #使用for 循环进行断言
    for index in self.toggle_checkboxes:
        #断言
        self.assertEqual(index.get_attribute("checked"),"true")


就写这些啦,想到哪更到哪。。。。。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值