Example #1
0
def clear_cart():
    """
    clear the shopping cart
    :return:
    """
    logger.info("Clear the shopping cart")
    goods_list = []
    while Element("Shopping_cart", "goods_name").is_exist():
        logger.info("Get the goods name")
        element_list = Element("Shopping_cart", "goods_name").get_element_list()

        if element_list is not None:
            last_goods_name = element_list[-1].get_attribute("text")

            for i in range(len(element_list)):
                logger.info("Delete goods")

                Element("Shopping_cart", "delete_goods").clicks(i)

                Element("Alert", "confirm").click()

                wait_loading()
        if last_goods_name not in goods_list:

            logger.info("Goods is not end")

            logger.info("Swipe up, if not end")

            common.my_swipe_to_up()

            goods_list.append(last_goods_name)
        else:
            logger.info("Goods is end")
            break
Example #2
0
def delete_goods_in_cart(goods_name):
    """
    delete goods in shopping cart
    :param goods_name: you need delete goods's name
    :return:
    """
    logger.info("Delete the goods which we choose")
    goods_list = []

    logger.info("Determine whether there is a goods")
    while Element("Shopping_cart", "goods_name").is_exist():

        logger.info("Get the goods name")
        element_list = Element("Shopping_cart", "goods_name").get_element_list()

        if element_list is not None:

            logger.info("Get the last goods name")
            last_goods_name = element_list[-1].get_attribute("text")

            for i in range(len(element_list)):

                value = element_list[i].get_attribute("text")

                if value == goods_name:

                    logger.info("Delete goods")

                    Element("Shopping_cart", "delete_goods").clicks(i)

                    Element("Alert", "confirm").click()

                    wait_loading()

                    return

        if last_goods_name not in goods_list:

            logger.info("Goods is not end")

            logger.info("Swipe up, if not end")

            common.my_swipe_to_up()

            goods_list.append(last_goods_name)
        else:
            logger.info("Goods is end")
            return
    def testSave(self):

        try:

            self.logger.info("Enter the profile")

            # find the bottom Navigation bar
            while not Element("BottomNavigation", "BottomNavigation").is_exist():
                sleep(1)
            else:
                # enter the profile
                Element("BottomNavigation", "profile").click()

            bsnsCommon.wait_loading()

            # first login
            user_name = loginCls[0][1]
            password = loginCls[0][2]

            bsnsCommon.login(user_name, password)

            bsnsCommon.wait_loading()

            bsnsCommon.return_index()

            self.logger.info("Enter the goods details")

            while not Element("Shop", "goods").is_exist():
                myCommon.my_swipe_to_up()
            else:
                myCommon.my_swipe_to_up()
                Element("Shop", "goods").clicks(0)

            bsnsCommon.wait_loading()

            self.logger.info("Get the goods's name")

            self.goods_name = Element("title", "title").get_attribute("text")

            Element("Good_details", "save").click()

            self.check_result(self.goods_name)

        except Element as ex:

            self.logger.error(str(ex))
    def testSettingFeedBack(self):
        try:
            self.logger.info("Enter the profile")

            # find the bottom Navigation bar
            while not Element("BottomNavigation", "BottomNavigation").is_exist():
                sleep(1)
            else:
                # enter the profile
                Element("BottomNavigation", "profile").click()

            bsnsCommon.wait_loading()

            myCommon.my_swipe_to_up()

            # enter my address
            self.logger.info("Enter the setting")

            element_list = Element("profile", "profile_tv").get_element_list()

            for i in range(len(element_list)):

                element_name = element_list[i]

                if element_name == "Setting":

                    element_list[i].click()

                    break

            bsnsCommon.wait_loading()

            Element("setting", "feed_back").click()

            bsnsCommon.wait_loading()

            Element("feed_back", "email").send_key(self.email)

            Element("feed_back", "advice").send_key(self.advice)

            Element("title","rightButton").click()

        except Exception as ex:
            self.logger.error(str(ex))
Example #5
0
def get_total_price_in_cart():
    """
    get the all goods price in shopping cart
    :return:
    """
    logger.info("Determine whether there is a goods")
    goods_list = []
    total_price = 0
    while Element("Shopping_cart", "goods_name").is_exist():
        logger.info("Get the goods name")
        element_list = Element("Shopping_cart", "goods_name").get_element_list()

        if element_list is not None:

            logger.info("Get the last goods name")
            last_goods_name = element_list[-1].get_attribute("text")

            for i in range(len(element_list)):

                goods_name = element_list[i].get_attribute("text")

                if goods_name not in goods_list:
                    goods_list.append(goods_name)

                    goods_price_text = Element("Shopping_cart", "goods_price").gets(i).get_attribute("text")
                    goods_price = goods_price_text[goods_price_text.find("$")+1:]
                    goods_num = Element("Shopping_cart", "goods_num").gets(i).get_attribute("text")

                    one_goods_price = float(goods_price)*int(goods_num)
                    total_price += one_goods_price

            if last_goods_name not in goods_list:

                logger.info("Goods is not end")

                logger.info("Swipe up, if not end")

                common.my_swipe_to_up()

                goods_list.append(last_goods_name)
            else:
                logger.info("Goods is end")
                break
    return str(total_price)
Example #6
0
def logout():
    """
    logout the app
    :return:
    """
    # if already sign in , first sign out
    while not Element("profile", "SignOut").is_exist():

        # swipe up
        common.my_swipe_to_up()
    else:

        logger.debug("Begin logout")
        Element("profile", "SignOut").click()

        if Element("Alert", "confirm").is_exist():
            Element("Alert", "confirm").click()

        wait_loading()
        logger.debug("End logout")
    def testReview(self):
        try:
            self.logger.info("Enter the goods details")

            while not Element("Shop", "goods").is_exist():
                myCommon.my_swipe_to_up()
            else:
                myCommon.my_swipe_to_up()
                Element("Shop", "goods").clicks(0)

            bsnsCommon.wait_loading()

            self.logger.info("Enter the write review")
            while not Element("Good_details", "write_review").is_exist():
                myCommon.my_swipe_to_up()
            else:
                Element("Good_details", "write_review").click()

            bsnsCommon.wait_loading()

            self.logger.info("Write review")

            self.write_reviews()

            self.check_result()

        except Exception as ex:
            self.logger.error(str(ex))
Example #8
0
    def testAddCart(self):
        try:
            self.logger.info("Enter the goods details")

            while not Element("Shop", "goods").is_exist():
                myCommon.my_swipe_to_up()
            else:
                myCommon.my_swipe_to_up()
                Element("Shop", "goods").clicks(0)

            bsnsCommon.wait_loading()

            self.logger.info("Get the goods's name")

            self.goods_name = Element("title", "title").get_attribute("text")

            self.logger.info("Enter the shopping cart")

            Element("Shopping_cart", "shopping_cart").click()

            bsnsCommon.wait_loading()

            bsnsCommon.delete_goods_in_cart(self.goods_name)

            myCommon.back()

            bsnsCommon.wait_loading()

            goods_num = Element("Shopping_cart", "shopping_cart").get_attribute("text")

            self.logger.info("Add goods to cart")

            self.add_cart()

            self.check_result(goods_num)

        except Exception as ex:
            self.logger.error(str(ex))
Example #9
0
def add_goods_in_cart(num):
    """
     add goods to cart
    :param num: goods number
    :return:
    """

    if num == 0:
        return

    goods_name_list = []

    for i in range(num):

        if Element("BottomNavigation", "BottomNavigation").is_exist():
            common.my_swipe_to_up()

        while not Element("Shop", "goods").is_exist():
                common.my_swipe_to_up()
        else:
            Element("Shop", "goods").clicks(i)

            goods_name = Element("title", "title").get_attribute("text")

            goods_name_list.append(goods_name)

            enter_cart()

            if Element("add_cart", "add_cart").does_exist():

                logger.info("Select size")
                Element("add_cart", "size").clicks(0)

            Element("add_cart", "buy").click()
        logger.info("Return index")
        return_index()
    return goods_name_list
    def testRecentlyViewed(self):
        try:
            self.logger.info("Enter the goods details")

            while not Element("Shop", "goods").is_exist():
                myCommon.my_swipe_to_up()
            else:
                myCommon.my_swipe_to_up()
                Element("Shop", "goods").clicks(0)

            bsnsCommon.wait_loading()

            self.logger.info("Get the goods's name")

            self.goods_name = Element("title", "title").get_attribute("text")

            # return the index
            bsnsCommon.return_index()

            self.logger.info("Enter the profile")

            # find the bottom Navigation bar
            while not Element("BottomNavigation", "BottomNavigation").is_exist():
                sleep(1)
            else:
                # enter the profile
                Element("BottomNavigation", "profile").click()

            bsnsCommon.wait_loading()

            myCommon.my_swipe_to_up()

            # enter my address
            self.logger.info("Enter the recently viewed")

            element_list = Element("profile", "profile_tv").get_element_list()

            for i in range(len(element_list)):

                element_name = element_list[i]

                if element_name == "Recently Viewed":

                    element_list[i].click()

                    break

            bsnsCommon.wait_loading()

            self.check_result(self.goods_name)

        except Exception as ex:
            self.logger.error(str(ex))
    def check_result(self, goods_name):

        value = Element("Good_details", "save").get_attribute("text")

        while value != "saved":
            sleep(1)
        else:
            bsnsCommon.return_index()

        self.logger.info("Enter the profile")

        # find the bottom Navigation bar
        while not Element("BottomNavigation", "BottomNavigation").is_exist():
            sleep(1)
        else:
            # enter the profile
            Element("BottomNavigation", "profile").click()

        bsnsCommon.wait_loading()

        self.logger.info("Enter the my wish list")

        Element("profile", "profile_tv").clicks(2)

        bsnsCommon.wait_loading()

        goods_list = []

        self.logger.info("Determine whether there is a goods")

        while Element("wish_list", "goods_name").is_exist():
            self.logger.info("Get the goods name")

            element_list = Element("Shopping_cart", "goods_name").get_element_list()

            if element_list is not None:

                self.logger.info("Get the last goods name")
                last_goods_name = element_list[-1].get_attribute("text")

                for i in range(len(element_list)):

                    value = element_list[i].get_attribute("text")

                    if value == goods_name:

                        self.assertEqual("1", "1")

                        Element("Shopping_cart", "delete_goods").clicks(i)

                        Element("Alert", "confirm").click()

                        bsnsCommon.wait_loading()

                        return

            if last_goods_name not in goods_list:

                self.logger.info("Goods is not end")

                self.logger.info("Swipe up, if not end")

                myCommon.my_swipe_to_up()

                goods_list.append(last_goods_name)
            else:
                self.logger.info("Goods is end")
                self.assertEqual("1", "0")
                return