def testLogin(self): """ test login :return: """ 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() # login the app bsnsCommon.login(self.email, self.password) # check the result self.check_result() except Exception as ex: self.logger.error(str(ex))
def choose_shipping_payment_methods_in_checkout(shipping_method, payment_method): """ choose method for shipping and payment :param shipping_method: :param payment_method: :return: """ # choose shipping method shipping_methods = Element("checkout", "shopping_method").get_element_list() if shipping_methods is not None: methods = [] for i in range(len(shipping_methods)): methods[i] = shipping_methods[i].get_attribute("text") if methods[i] is not None: if methods[i] == shipping_method: logger.info("Choose the shipping method is:" + shipping_method) Element("checkout", "shopping_method").gets(i).click() else: logger.info("The shipping method is none!") # choose payment method if not Element("checkout", "payment_method").is_exist(): common.my_swipe_to_up() else: payment_methods = Element("checkout", "payment_method").get_element_list() if payment_methods is not None: payments = [] for i in range(len(payment_methods)): payments[i] = payment_methods[i].get_attribute("text") if payments[i] == payment_method: logger.info("Choose the payment method is:" + payment_method) Element("checkout", "payment_method").gets(i).click() else: logger.info("The payment method is none!")
def return_index(): """ return then index :return: """ # Determine whether there is BottomNavigation logger.info("Determine whether there is BottomNavigation") while not Element("BottomNavigation", "BottomNavigation").is_exist(): # key event:back logger.info("Key event:back") common.back() sleep(1) if Element("BottomNavigation", "BottomNavigation").is_exist(): break logger.info("Swipe down") common.my_swipe_to_down() sleep(1) if Element("BottomNavigation", "BottomNavigation").is_exist(): break # click the shop button Element("BottomNavigation", "SHOP").gets(0).click() wait_loading()
def testAddress(self): try: email = loginGls[0][1] password = loginGls[0][2] bsnsCommon.login(email, password) bsnsCommon.wait_loading() if Element("Alert", "update_title").is_exist(): Element("Alert", "cancel").click() else: pass # go to 'ME' bsnsCommon.go_to_me() # go to address_book Element("address_management", "address_book").click() # add address Element("address_management", "add_address").click() bsnsCommon.input_address(self.first_name, self.last_name, self.phone, self.zip_code, self.address_1, self.address_2, self.city, self.country, self.state) # check result self.check_result() except Exception as ex: self.logger.error(str(ex))
def testChangePassword(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() # enter the account setting Element("profile", "profile_tv").clicks(0) bsnsCommon.wait_loading() # enter the change password Element("account_setting", "change_password").click() bsnsCommon.wait_loading() self.input_password(self.old_password, self.new_password, self.confirm_password) self.check_result() except Exception as ex: self.logger.error(str(ex))
def testMyTickets(self): try: login_email = loginGls[0][1] login_pass = loginGls[0][2] bsnsCommon.login(login_email, login_pass) bsnsCommon.wait_loading() bsnsCommon.cancel_update() bsnsCommon.go_to_me() sleep(1) Element("my_tickets", "my_tickets").click() bsnsCommon.wait_loading() Element("my_tickets", "add_tickets").click() bsnsCommon.wait_loading() Element("my_tickets", "tickets_topic").click() bsnsCommon.wait_loading() self.inputTickets(self.first_name, self.last_name, self.email, self.language, self.content) self.checkResult() except Exception as ex: self.logger.error(str(ex))
def checkResult(self): common.my_swipe_to_up() goods = Element("recently_viewed", "goods_name").gets(0) value = goods.get_attribute("text") self.logger.info("recently goods_name is : " + value) if value == self.goods_name: self.assertEqual(1, 1)
def check_result(self): self.CheckPoint = self.log.take_shot(self.driver, self.case_name) self.logger.info("Take shot, the picture path is " + self.CheckPoint) result = self.first_name + " " + self.last_name if self.results == "1": bsnsCommon.wait_loading() element_list = Element("address_management", "recipient").get_element_list() for i in range(len(element_list)): value = element_list[i].get_attribute("text") if result == value: self.assertEqual(1, 1) if self.results == "0": sleep(1) if Element("Alert", "layout").does_exist(): value = Element("Alert", "message").get_attribute("text") self.assertEqual(value, self.message) sleep(1) Element("Alert", "confirm").click()
def testQty_minus(self): try: # Enter to the shopping cart self.logger.info("Enter to the shopping cart") Element("Shopping_cart", "shopping_cart").click() bsnsCommon.wait_loading() Element("Shopping_cart", "goods_num").send_keys(0, "0") # change qty_minus os.popen("adb shell input keyevent 61") sleep(1) os.popen("adb shell input keyevent 66") if Element("Alert", "layout").does_exist(): value = Element("Alert", "message").get_attribute("text") self.assertEqual(value, self.message_min) sleep(1) Element("Alert", "confirm").click() # return the index bsnsCommon.return_index() except Exception as ex: self.logger.error(str(ex))
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))
def check_result(self): """ check result :return: """ self.checkPoint = self.log.take_shot(self.driver, self.case_name) self.logger.info("Take shot, the picture path is:" + self.checkPoint) # login successfully if self.results == '1': bsnsCommon.wait_loading() if not Element("Alert", "layout").dose_exist(): self.message = "" if Element("BottomNavigation", "BottomNavigation").dose_exist(): value = "" self.assertEqual(value, self.message) bsnsCommon.logout() # login fail if self.results == '0': sleep(1) if Element("Alert", "layout").does_exist(): value = Element("Alert", "message").get_attribute("text") self.assertEqual(value, self.message) sleep(1) Element("Alert", "confirm").click() else: pass
def login(email, password): """ login app :return: """ # cancel for update cancel_update() logger.info("Begin login the app") if Element("BottomNavigation", "BottomNavigation").is_exist(): logger.debug("Current is already login, first logout") logout() logger.debug("Begin login") else: pass # Element("profile", "SignIn").click() # wait_loading() if Element("login", "fblogin").is_exist(): login_input(email, password) else: Element("login", "loginText").click() login_input(email, password) logger.info("End login the app")
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
def check_result(self): """ check the result :return: """ self.CheckPoint = self.log.take_shot(self.driver, self.case_name) self.logger.info("Take shot, the picture path is " + self.CheckPoint) # login success if self.results == '1': bsnsCommon.wait_loading() value = Element("profile", "user").get_attribute("text") self.assertEqual(value, self.message) # login fail if self.results == '0': sleep(1) if Element("Alert", "layout").does_exist(): value = Element("Alert", "message").get_attribute("text") self.assertEqual(value, self.message) sleep(1) Element("Alert", "confirm").click()
def testProfileAddressDelete(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() # enter my address self.logger.info("Enter the my address") Element("profile", "profile_tv").clicks(3) self.addAddress() # delete address bsnsCommon.wait_loading() except Exception as ex: self.logger.error(str(ex))
def check_result(self, num): """ check the result :return: """ self.CheckPoint = self.log.take_shot(self.driver, self.case_name) self.logger.info("Take shot, the picture path is " + self.CheckPoint) if self.results == '1': goods_num = Element("Shopping_cart", "shopping_cart").get_attribute("text") self.assertEqual(int(num) + 1, int(goods_num)) if self.results == '0': sleep(1) if Element("Alert", "layout").does_exist(): value = Element("Alert", "message").get_attribute("text") self.assertEqual(value, self.message) sleep(1) Element("Alert", "confirm").click() Element("add_cart", "cancel").click()
def testDeleteAddress(self): try: email = loginGls[0][1] password = loginGls[0][2] # login app bsnsCommon.login(email, password) bsnsCommon.wait_loading() if Element("Alert", "update_title").is_exist(): Element("Alert", "cancel").click() else: pass # go to 'ME' bsnsCommon.go_to_me() sleep(1) # go to add address page Element("address_management", "address_book").click() if Element("Address", "delete_address").is_exist(): # delete address Element("Address", "delete_address").clicks(0) if Element("Alert", "layout").does_exist(): Element("Alert", "confirm").click() else: self.addAddress() # delete address Element("Address", "delete_address").clicks(0) if Element("Alert", "layout").does_exist(): Element("Alert", "confirm").click() except Exception as ex: self.logger.error(str(ex))
def changeCurrency(self): # change currency Element("account_setting", "change_currency").click() sleep(1) Element("change_currency", "currency").clicks(1) self.value = Element("change_currency", "currency").gets(1).get_attribute("text") self.logger.info("Currency is:" + self.value)
def get_shipping_price_in_checkout(): """ get the shipping price in checkout :return: shipping_price """ shipping_price_text = Element("checkout", "shipping_price").get_attribute("text") shipping_price = shipping_price_text[shipping_price_text.find("$")+1:] return float(shipping_price)
def get_freebie_price_in_checkout(): """ get the freebie price in checkout :return:freebie_price """ freebie_price_text = Element("checkout", "freebie_price").get_attribute("text") freebie_price = freebie_price_text[freebie_price_text.find("$")+1:] return float(freebie_price)
def get_subtotal_price_in_checkout(): """ get the subtotal price in checkout :return:subtotal_price """ subtotal_price_text = Element("checkout", "subtotal").get_attribute("text") subtotal_price = subtotal_price_text[subtotal_price_text.find("$")+1:] return float(subtotal_price)
def get_total_price_in_checkout(): """ get the total price in checkout :return:total_price """ total_price_text = Element("checkout", "total").get_attribute("text") total_price = total_price_text[total_price_text.find("$")+1:] return float(total_price)
def get_coupon_code_price_in_checkout(): """ get the coupon code price in checkout :return:coupon_code_price """ coupon_code_price_text = Element("checkout", "coupon_code_price").get_attribute("text") coupon_code_price = coupon_code_price_text[coupon_code_price_text.find("$")+1:] return float(coupon_code_price)
def write_reviews(self): if self.user_name != "default": Element("Review", "user_name").send_key(self.user_name) Element("Review", "content").send_key(self.content) Element("Review", "submit").click()
def input_password(self, old_password, new_password, confirm_password): # input old password Element("change_password", "old_pass").send_key(old_password) # input new password Element("change_password", "new_pass").send_key(new_password) # input confirm password Element("change_password", "confirm_pass").send_key(confirm_password) # click submit button Element("change_password", "change_password").click()
def check_result(self, price): self.CheckPoint = self.log.take_shot(self.driver, self.case_name) result = Element("Shopping_cart", "total_price").get_attribute("text") total_price = result[result.find("$")+1:] self.assertEqual(total_price, price)
def clearCache(self): self.cache = Element("account_setting", "cache_size").get_attribute("text") self.logger.info("Cache size is:" + self.cache) Element("account_setting", "clear_cache").click() if Element("Alert", "clear_cache_sure").is_exist(): Element("Alert", "clear_cache_sure").click() else: pass
def register(self): """ register :return: """ Element("register", "input").send_keys(0, self.email) Element("register", "input").send_keys(1, self.password) Element("register", "input").send_keys(2, self.confirm_password) Element("register", "register").click()
def check_result(self): if Element("Alert", "layout").does_exist(): value = Element("Alert", "message").get_attribute("text") self.assertEqual(value, self.message) sleep(1) Element("Alert", "confirm").click()
def enter_cart(): """ enter the shopping cart :return: """ logger.info("Enter add cart page") if not Element("Good_details", "add").is_exist(): common.my_swipe_to_up() else: Element("Good_details", "add").click()
def check_result(self): result = Element("Shopping_cart", "total_price").get_attribute("text") total_price = result[result.find("$"):] while float(total_price) < 100: # change qty_add Element("Shopping_cart", "plus_qty").clicks(0) else: if Element("Shopping_cart", "shipping").is_exist(): self.assertEqual("1", "1") else: self.assertEqual("1", "")
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)