How to use step_impl method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

booking.py

Source:booking.py Github

copy

Full Screen

...77 78 return ret_date79 80@given(u'手机已安装掌上如家')81def step_impl(context):82 el = context.testStep.driver.is_app_installed('com.ziipin.homeinn')83 assert el84@given(u'手机当前运行应用不为掌上如家')85def step_impl(context):86 if context.testStep.current_app('com.ziipin.homeinn'):87 context.current_app_right = True88 else:89 context.current_app_right = False90 91@when(u'用户启动掌上如家')92def step_impl(context):93 if context.current_app_right==False:94 el = context.testStep.driver.start_activity('com.ziipin.homeinn', '.activity.SplashActivity')95 assert el96@then(u'掌上如家会出现')97def step_impl(context):98 if context.current_app_right==False:99 context.testStep.wait_window('.activity.SplashActivity', 5)100 101@given(u'掌上如家是新版本安装后第一次启动')102def step_impl(context):103 if context.current_app_right==False:104 # wait for startshow activity105 if context.testStep.wait_window('.activity.StartShowActivity', 5):106 context.first_launch = True107 else:108 context.first_launch = False109@when(u'用户左划屏幕直到出现“{widget_text}”并点击“{widget_text}”')110def step_impl(context, widget_text):111 if context.current_app_right==False:112 if context.first_launch==True:113 finish = False114 while not (finish):115 try:116 context.testStep.has_widget(widget_text)117 except Exception:118 context.testStep.driver.swipe(600,486, 98,489, 500)119 else:120 finish = True121 122 start = context.testStep.has_widget(widget_text)123 assert start124 context.testStep.tap_widget(start)125 126 # wait for main window127 context.testStep.wait_widget('过夜房')128 context.testStep.wait_widget('com.ziipin.homeinn:id/n_search_start_btn')129 context.testStep.wait_widget('预订')130 context.testStep.wait_widget('活动')131 context.testStep.wait_widget('服务')132 context.testStep.wait_widget('我的') 133 context.testStep.tap_permision_widget("accept")134 135@given(u'用户尚未登录掌上如家')136def step_impl(context):137 context.testStep.tap_widget('我的')138 try:139 context.testStep.wait_widget('密码登录', 1)140 context.log_on = False141 except:142 context.log_on = True143 144 145@given(u'掌上如家的“{widget_text}”为灰色不可用')146def step_impl(context, widget_text):147 button_widget = context.testStep.has_widget(widget_text)148 149 if button_widget.get_attribute('clickable')=="false":150 pass151 else:152 raise Exception153 154 155@given(u'掌上如家的“{widget_text}”为可用')156def step_impl(context, widget_text):157 button_widget = context.testStep.has_widget(widget_text)158 159 if button_widget.get_attribute('clickable')=="true":160 pass161 else:162 raise Exception 163 164@when(u'用户输入账号密码')165def step_impl(context):166 if context.log_on==False:167 context.testStep.input_textbox('com.ziipin.homeinn:id/login_id_input', decrypt("beHome", context.usr))168 context.testStep.input_textbox('com.ziipin.homeinn:id/login_pwd_input', decrypt("beHome", context.auth))169 context.testStep.tap_widget('登录')170@then(u'用户已经登录掌上如家')171def step_impl(context):172 context.testStep.wait_widget('我的订单')173@then(u'掌上如家跳转到民宿选择酒店界面')174def step_impl(context):175 raise NotImplementedError(u'STEP: Then 掌上如家跳转到民宿选择酒店界面')176 177@given(u'掌上如家当前界面不为首页')178def step_impl(context):179 if context.testStep.wait_window('.activity.MainActivity', 5):180 context.current_window_right = True181 else:182 context.current_window_right = False183@when(u'用户按返回直到有“预订”页面可点击')184def step_impl(context):185 try:186 booking_page_widget = context.testStep.has_widget("预订")187 except NoSuchElementException:188 found = False189 else:190 found = True191 192 while(found==False):193 context.testStep.tap_widget("com.ziipin.homeinn:id/back_btn")194 try:195 booking_page_widget = context.testStep.has_widget("预订")196 except NoSuchElementException:197 found = False198 else:199 found = True200 201 202#############################################################################203@given(u'掌上如家“当前位置”为“{widget_text}”')204def step_impl(context, widget_text):205 element = context.testStep.has_widget(widget_text, context.testStep._under('当前位置'))206 context.element = element207 208@given(u'当前时间在{start_time}点到{end_time}点之间')209def step_impl(context, start_time, end_time):210 today = datetime.datetime.now()211 logging.debug("%s", today)212 if int(today.hour)>=int(start_time) and int(today.hour)<int(end_time):213 pass214 else:215 assert False216 217@given(u'掌上如家有“再次预订”')218def step_impl(context):219 context.testStep.wait_widget("再次预订", 1, 1, True)220 hotel_widget = context.testStep.has_widget('com.ziipin.homeinn:id/item_hotel_name')221 context.hotel = hotel_widget.text222 # remove brand of full hotel name223 context.hotel = context.hotel[context.hotel.find('-')+1:len(context.hotel)]224 logging.info("hotel:%s", context.hotel)225@given(u'掌上如家“{room_type}”有“{member_price}”房间')226def step_impl(context, room_type, member_price):227 room_type_widget = context.testStep.has_widget(room_type)228 #context.room_type_widget229 member_price_widget = context.testStep.has_widget(member_price, context.testStep._under(room_type_widget))230 booking_widgets = context.testStep.has_widgets("//android.widget.Button[@text='预订']",231 context.testStep._under(room_type_widget)+232 context.testStep._right(member_price_widget))233 # find widget that is exactly right of member price widget234 i = 0235 logging.debug("i:%d", i)236 found = False237 while (i < len(booking_widgets)):238 # if top of member price widget is higher than bottom of booking widget239 # and bottom of member price widget is lower than top of booking widget240 # we consider them are on the same horizontal lines241 logging.debug("member_price_widget top: %d booking_widgets[%d] bottom: %d",242 member_price_widget.location.get('y') ,i\243 , booking_widgets[i].location.get('y')+booking_widgets[i].size["height"])244 logging.debug("member_price_widget bottom: %d booking_widgets[%d] top: %d",245 member_price_widget.location.get('y')+member_price_widget.size["height"] ,i\246 , booking_widgets[i].location.get('y'))247 if member_price_widget.location.get('y')\248 < booking_widgets[i].location.get('y')+booking_widgets[i].size["height"] \249 and member_price_widget.location.get('y')+member_price_widget.size["height"]\250 > booking_widgets[i].location.get('y'):251 found = True252 logging.debug("found")253 break254 255 i = i + 1256 logging.debug("i:%d", i)257 258 if found == False:259 context.failed260 261 context.booking_widget = booking_widgets[i]262@given(u'掌上如家有“{widget_text}”的订单')263def step_impl(context, widget_text):264 context.testStep.wait_widget(widget_text)265 order_widget = context.testStep.has_widget(widget_text)266 context.order_widget = order_widget267 268@given(u'掌上如家“过夜房”页面显示不为“{checkin}”入住,“{checkout}”离店')269def step_impl(context, checkin, checkout):270 check_in_date = _parse_date(checkin)271 logging.debug("check in date: " + str(check_in_date))272 check_out_date = _parse_date(checkout)273 logging.debug("check out date: " + str(check_out_date))274 275 check_in_date_month = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_month_1').text276 logging.debug("check_in_date_month: " + check_in_date_month)277 278 check_in_date_day = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_day_1').text279 logging.debug("check_in_date_day: " + check_in_date_day)280 281 check_out_date_month = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_month_2').text282 logging.debug("check_out_date_month: " + check_out_date_month)283 284 check_out_date_day = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_day_2').text285 logging.debug("check_out_date_day: " + check_out_date_day)286 context.check_in_date = _parse_date(check_in_date_month+check_in_date_day+u'日')287 logging.debug("context.check_in_date: " + str(context.check_in_date))288 context.check_out_date = _parse_date(check_out_date_month+check_out_date_day+u'日')289 logging.debug("context.check_out_date: " + str(context.check_out_date))290 291 if (check_in_date)==context.check_in_date and (check_out_date)==context.check_out_date:292 #context.testStep.has_widget(str(check_in_date.month)+"月")293 #context.testStep.has_widget(str(check_out_date.month)+"月")294 #context.testStep.has_widget(str(check_in_date.day), context.testStep._left("入住"))295 #context.testStep.has_widget(str(check_out_date.day), context.testStep._left("离店"))296 context.check_in_out_right = True297 else:298 context.check_in_out_right = False299 300@given(u'掌上如家显示“{widget_text}”或者有“{tips}”的订单')301def step_impl(context, widget_text, tips):302 try:303 context.testStep.wait_widget(widget_text)304 except:305 context.testStep.wait_widget(tips, 3)306@given(u'用户有可用电子券')307def step_impl(context):308 try:309 context.coupon = context.testStep.has_widget('您有可用电子券')310 except NoSuchElementException:311 context.coupon = None312 logging.info("no coupon available")313@when(u'用户点击以上的“{widget_text}”')314def step_impl(context, widget_text):315 context.testStep.tap_widget(context.element)316 317@when(u'用户点击入住日期为“{checkin}”')318def step_impl(context, checkin):319 check_in_date = _parse_date(checkin)320 logging.debug("check in date: " + str(check_in_date))321 context.testStep.tap_date_in_calendar(check_in_date)322@when(u'用户点击离店日期为“{checkout}”')323def step_impl(context, checkout):324 check_out_date = _parse_date(checkout)325 logging.debug("check out date: " + str(check_out_date))326 context.testStep.tap_date_in_calendar(check_out_date)327 328@when(u'用户选择第一个酒店')329def step_impl(context):330 context.hotel = context.testStep.has_widget("com.ziipin.homeinn:id/text_hotel_name").text331 # remove brand of full hotel name332 context.hotel = context.hotel[context.hotel.find('-')+1:len(context.hotel)]333 334 context.testStep.tap_widget("com.ziipin.homeinn:id/text_hotel_name")335 336@when(u'用户选择第一个不是已满的酒店')337def step_impl(context):338 hotel_widget = context.testStep.has_widget("com.ziipin.homeinn:id/text_hotel_name")339 hotel_widget_text = hotel_widget.text340 if len(hotel_widget_text)>8:341 hotel_widget_text=hotel_widget_text[0:8]342 logging.debug("hotel_widget_text:%s", hotel_widget_text)343 price_widget_text = context.testStep.has_widget("com.ziipin.homeinn:id/text_hotel_price").text344 logging.debug("price_widget_text:%s", price_widget_text)345 if price_widget_text==u'满房':346 found = False347 else:348 found = True349 350 while (found==False):351 next_hotel_widget = context.testStep.has_widget("com.ziipin.homeinn:id/text_hotel_name", 352 context.testStep._under(hotel_widget_text))353 next_hotel_widget_text = next_hotel_widget.text354 if len(next_hotel_widget_text)>8:355 next_hotel_widget_text=next_hotel_widget_text[0:8]356 logging.debug("next_hotel_widget_text:%s", next_hotel_widget_text)357 price_widget_text = context.testStep.has_widget("com.ziipin.homeinn:id/text_hotel_price", 358 context.testStep._under(next_hotel_widget_text)).text359 logging.debug("price_widget_text:%s", price_widget_text)360 361 if price_widget_text==u'满房':362 found = False363 context.testStep._swipe_to_distination_half_by_half(next_hotel_widget, hotel_widget, "top2top")364 logging.debug("not found")365 else:366 found = True367 logging.debug("found")368 369 hotel_widget_text = next_hotel_widget_text370 hotel_widget = next_hotel_widget371 372 context.hotel = hotel_widget_text373 # remove brand of full hotel name374 context.hotel = context.hotel[context.hotel.find('-')+1:len(context.hotel)]375 logging.info("hotel:%s", context.hotel)376 context.testStep.tap_widget(hotel_widget)377 378@when(u'用户选择第二个不是已满的酒店')379def step_impl(context):380 index = 0381 hotel_widget = context.testStep.has_widget("com.ziipin.homeinn:id/text_hotel_name")382 hotel_widget_text = hotel_widget.text383 logging.debug("hotel_widget_text:%s", hotel_widget_text)384 price_widget_text = context.testStep.has_widget("com.ziipin.homeinn:id/text_hotel_price").text385 logging.debug("price_widget_text:%s", price_widget_text)386 if price_widget_text==u'满房':387 found = False388 else:389 found = True390 index = index + 1391 392 while (found==False) or (index<2):393 next_hotel_widget = context.testStep.has_widget("com.ziipin.homeinn:id/text_hotel_name", 394 context.testStep._under(hotel_widget_text))395 logging.debug("hotel_widget_text:%s", hotel_widget_text)396 next_hotel_widget_text = next_hotel_widget.text397 price_widget_text = context.testStep.has_widget("com.ziipin.homeinn:id/text_hotel_price", 398 context.testStep._under(hotel_widget_text)).text399 logging.debug("price_widget_text:%s", price_widget_text)400 401 if price_widget_text==u'满房':402 found = False403 context.testStep._swipe_to_distination_half_by_half(next_hotel_widget, hotel_widget, "top2top")404 else:405 found = True406 index = index + 1407 408 hotel_widget_text = next_hotel_widget_text409 hotel_widget = next_hotel_widget410 411 context.hotel = hotel_widget_text412 # remove brand of full hotel name413 context.hotel = context.hotel[context.hotel.find('-')+1:len(context.hotel)]414 logging.info("hotel:%s", context.hotel)415 context.testStep.tap_widget(hotel_widget)416 417 418 419@when(u'用户展开第一个不是已满的房型')420def step_impl(context):421 room_widget = context.testStep.has_widget("com.ziipin.homeinn:id/room_name")422 room_widget_text = room_widget.text423 logging.debug("room_widget_text:%s", room_widget_text)424 price_widget_text = context.testStep.has_widget("com.ziipin.homeinn:id/room_price").text425 logging.debug("price_widget_text:%s", price_widget_text)426 if price_widget_text==u'满房':427 found = False428 else:429 found = True430 431 while (found==False):432 next_room_widget = context.testStep.has_widget("com.ziipin.homeinn:id/room_name", 433 context.testStep._under(room_widget_text))434 next_room_widget_text = next_room_widget.text435 logging.debug("next_room_widget_text:%s", next_room_widget_text)436 price_widget_text = context.testStep.has_widget("com.ziipin.homeinn:id/room_price", 437 context.testStep._under(next_room_widget_text)).text438 logging.debug("price_widget_text:%s", price_widget_text)439 440 if price_widget_text==u'满房':441 found = False442 context.testStep._swipe_to_distination_half_by_half(next_room_widget, room_widget, "bottom2top")443 logging.debug("not found")444 else:445 found = True446 logging.debug("found")447 448 room_widget_text = next_room_widget_text449 room_widget = next_room_widget450 context.room_type = room_widget_text451 logging.debug("room_type:%s", context.room_type)452 453 if price_widget_text.find(u'门市价')==-1:454 end_p = context.testStep.has_widget("com.ziipin.homeinn:id/room_title_layout")455 context.testStep._swipe_to_distination_half_by_half(room_widget, end_p)456 context.testStep.tap_widget(room_widget)457 458@when(u'用户划动第一个不是已满的房型到最顶')459def step_impl(context):460 room_widget = context.testStep.has_widget("com.ziipin.homeinn:id/room_name")461 room_widget_text = room_widget.text462 logging.debug("room_widget_text:%s", room_widget_text)463 price_widget_text = context.testStep.has_widget("com.ziipin.homeinn:id/room_price").text464 logging.debug("price_widget_text:%s", price_widget_text)465 if price_widget_text==u'满房':466 found = False467 else:468 found = True469 470 while (found==False):471 next_room_widget = context.testStep.has_widget("com.ziipin.homeinn:id/room_info_layout", 472 context.testStep._under(room_widget_text))473 logging.debug("room_widget_text:%s", hotel_widget_text)474 next_room_widget_text = next_room_widget.text475 price_widget_text = context.testStep.has_widget("com.ziipin.homeinn:id/room_price", 476 context.testStep._under(room_widget_text)).text477 logging.debug("price_widget_text:%s", price_widget_text)478 479 if price_widget_text==u'满房':480 found = False481 context.testStep._swipe_to_distination_half_by_half(room_widget, room_widget, "bottom2top")482 logging.debug("not found")483 else:484 found = True485 logging.debug("found")486 487 room_widget_text = next_room_widget_text488 room_widget = next_room_widget489 490 context.room_type = room_widget_text491 logging.info("room_type:%s", context.room_type)492 end_p = context.testStep.has_widget("com.ziipin.homeinn:id/room_title_layout")493 context.testStep._swipe_to_distination_half_by_half(room_widget, end_p)494@when(u'用户上划屏幕查看房型直到酒店房型有“{room_type}”')495def step_impl(context, room_type):496 try:497 room_type_widget = context.testStep.has_widget(room_type)498 except NoSuchElementException:499 found = False500 else:501 found = True502 context.room_type_widget = room_type_widget503 end_p = context.testStep.has_widget("com.ziipin.homeinn:id/room_title_layout")504 start_p = context.testStep.has_widget("com.ziipin.homeinn:id/room_name")505 start_p_text = start_p.text506 logging.debug("start_p_text is %s", start_p_text)507 context.testStep._swipe_to_distination_half_by_half(start_p, end_p)508 end_location = end_p.location.get('y')509 logging.debug("end_location is %s", end_location)510 last_location = None511 512 while (not found):513 end_p = context.testStep.has_widget(start_p_text)514 start_p = context.testStep.has_widgets('房', context.testStep._under(end_p))515 start_p_text = start_p[0].text516 logging.debug("start_p_text is %s", start_p_text)517 location = start_p[0].location.get('y')518 logging.debug("location is %s", location)519 if not location == last_location:520 last_location = location521 logging.debug("last_location is %s", last_location)522 else:523 break524 #logging.info(str(start_p.location))525 #logging.info(str(start_p.size))526 #context.testStep.swipe_widget_by_direction("com.ziipin.homeinn:id/room_info_layout", "up")527 context.testStep._swipe_to_distination_half_by_half(start_p[0], end_p, "bottom2bottom")528 try:529 room_type_widget = context.testStep.has_widget(room_type)530 except NoSuchElementException:531 found = False532 else:533 found = True534 context.room_type_widget = room_type_widget535 536@when(u'用户在关键字搜索栏中输入“{destination}”')537def step_impl(context, destination):538 context.testStep.input_textbox_uft8("com.ziipin.homeinn:id/search_filter_input", destination)539@when(u'用户在城市中输入“{city}”')540def step_impl(context, city):541 context.testStep.input_textbox_uft8("com.ziipin.homeinn:id/city_input", city)542@when(u'用户上划“{room_type}”到屏幕最顶')543def step_impl(context, room_type):544 room_type_widget = context.testStep.has_widget(room_type)545 end_p = context.testStep.has_widget("com.ziipin.homeinn:id/room_title_layout")546 context.testStep._swipe_to_distination_half_by_half(room_type_widget, end_p)547 548 549@when(u'用户点击“{member_price}”右边的“{booking}”按钮')550def step_impl(context, member_price, booking):551 context.testStep.tap_widget(context.booking_widget)552@when(u'用户选择“{hotel}”酒店')553def step_impl(context, hotel):554 try:555 hotel_widget = context.testStep.tap_widget(hotel)556 except NoSuchElementException:557 hotel_widget = context.testStep.tap_widget(hotel[0:8])558 context.hotel = hotel559 # remove brand of full hotel name560 context.hotel = context.hotel[context.hotel.find('-')+1:len(context.hotel)]561 562@when(u'用户向下滑动提交订单页面')563def step_imp(context):564 start_p = context.testStep.has_widget('信用住,先住后付')565 end_p = context.testStep.has_widget("com.ziipin.homeinn:id/order_hotel_name")566 context.testStep._swipe_to_distination_half_by_half(start_p, end_p)567@when(u'用户向下滑动首页')568def step_imp(context):569 start_p = context.testStep.has_widget('立即预订')570 end_p = context.testStep.has_widget("com.ziipin.homeinn:id/main_brand_text")571 context.testStep._swipe_to_distination_half_by_half(start_p, end_p)572@when(u'用户上划屏幕查看订单详情直到有“{widget_text}”')573def step_impl(context, widget_text):574 #context.testStep.wait_widget("com.ziipin.homeinn:id/main_content")575 start_p = context.testStep.has_widget("com.ziipin.homeinn:id/main_content")576 577 end_p = start_p578 context.testStep._swipe_to_distination_half_by_half(start_p, end_p, "bottom2top")579 580 try:581 cancel_booking_widget = context.testStep.has_widget(widget_text)582 except NoSuchElementException:583 found = False584 else:585 found = True586 587 while (not found):588 start_p = context.testStep.has_widget("com.ziipin.homeinn:id/main_content")589 590 end_p = start_p591 context.testStep._swipe_to_distination_half_by_half(start_p, end_p, "bottom2top")592 try:593 cancel_booking_widget = context.testStep.has_widget(widget_text)594 except NoSuchElementException:595 found = False596 else:597 found = True598@when(u'用户上划屏幕查看我的页面直到有“{widget_text}”')599def step_impl(context, widget_text):600 start_p = context.testStep.has_widget("我的", context.testStep._right("服务"))601 602 end_p = context.testStep.has_widget("我的订单")603 context.testStep._swipe_to_distination_half_by_half(start_p, end_p, "top2bottom")604 605 try:606 my_option_widget = context.testStep.has_widget(widget_text)607 except NoSuchElementException:608 found = False609 else:610 found = True611 612 while (not found):613 start_p = context.testStep.has_widget("我的", context.testStep._right("服务"))614 615 end_p = context.testStep.has_widget("我的订单")616 context.testStep._swipe_to_distination_half_by_half(start_p, end_p, "top2bottom")617 try:618 my_option_widget = context.testStep.has_widget(widget_text)619 except NoSuchElementException:620 found = False621 else:622 found = True623@when(u'用户上划屏幕查看房型直到有“{widget_text}”按钮')624def step_impl(context, widget_text):625 try:626 button_widget = context.testStep.has_widget(widget_text)627 except NoSuchElementException:628 found = False629 else:630 found = True631 end_p = context.testStep.has_widget("com.ziipin.homeinn:id/room_title_layout")632 start_p = context.testStep.has_widget("com.ziipin.homeinn:id/room_name")633 start_p_text = start_p.text634 logging.debug("start_p_text is %s", start_p_text)635 context.testStep._swipe_to_distination_half_by_half(start_p, end_p)636 end_location = end_p.location.get('y')637 logging.debug("end_location is %s", end_location)638 last_location = None639 640 while (not found):641 end_p = context.testStep.has_widget(start_p_text)642 start_p = context.testStep.has_widgets('房', context.testStep._under(end_p))643 start_p_text = start_p[0].text644 logging.debug("start_p_text is %s", start_p_text)645 location = start_p[0].location.get('y')646 logging.debug("location is %s", location)647 if not location == last_location:648 last_location = location649 logging.debug("last_location is %s", last_location)650 else:651 break652 #logging.info(str(start_p.location))653 #logging.info(str(start_p.size))654 #context.testStep.swipe_widget_by_direction("com.ziipin.homeinn:id/room_info_layout", "up")655 context.testStep._swipe_to_distination_half_by_half(start_p[0], end_p, "bottom2bottom")656 try:657 button_widget = context.testStep.has_widget(widget_text)658 except NoSuchElementException:659 found = False660 else:661 found = True662@when(u'用户点击以上订单')663def step_impl(context):664 context.testStep.tap_widget(context.order_widget)665 666@when(u'用户上划自助服务页面')667def step_impl(context):668 context.testStep.swipe_widget_by_direction("com.ziipin.homeinn:id/main_content", "up")669 670@when(u'用户选择第一个房间')671def step_impl(context):672 room_widget = context.testStep.has_widget('com.ziipin.homeinn:id/room_sel_checker', context.testStep._under('自助选房'))673 context.testStep.tap_widget(room_widget)674@when(u'用户选择最后一个房间')675def step_impl(context):676 room_widget = context.testStep.has_widget('com.ziipin.homeinn:id/room_sel_checker', context.testStep._above('确定选房'))677 context.testStep.tap_widget(room_widget)678 679@when(u'用户点击过夜房入住离店日期')680def step_impl(context):681 check_in_date_month = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_month_1').text682 logging.debug("check_in_date_month: " + check_in_date_month)683 684 check_in_date_day = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_day_1').text685 logging.debug("check_in_date_day: " + check_in_date_day)686 687 check_out_date_month = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_month_2').text688 logging.debug("check_out_date_month: " + check_out_date_month)689 690 check_out_date_day = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_day_2').text691 logging.debug("check_out_date_day: " + check_out_date_day)692 context.check_in_date = _parse_date(check_in_date_month+check_in_date_day+u'日')693 logging.info("context.check_in_date: " + str(context.check_in_date))694 context.check_out_date = _parse_date(check_out_date_month+check_out_date_day+u'日')695 logging.info("context.check_out_date: " + str(context.check_out_date))696 697 context.testStep.tap_widget('com.ziipin.homeinn:id/n_date_layout')698 699@when(u'用户点击酒店详情页入店离店时间')700def step_impl(context):701 check_in_date = context.testStep.has_widget('com.ziipin.homeinn:id/start_date').text702 logging.debug("check_in_date: " + check_in_date)703 704 check_out_date = context.testStep.has_widget('com.ziipin.homeinn:id/end_date').text705 logging.debug("check_out_date: " + check_out_date)706 context.check_in_date = _parse_date(check_in_date)707 logging.info("context.check_in_date: " + str(context.check_in_date))708 context.check_out_date = _parse_date(check_out_date)709 logging.info("context.check_out_date: " + str(context.check_out_date))710 711 context.testStep.tap_widget("com.ziipin.homeinn:id/detail_date")712 713@when(u'用户选择搜索结果中第一个地点')714def step_impl(context):715 result_type_widget = context.testStep.has_widget("com.ziipin.homeinn:id/type_text")716 result_type_widget_text = result_type_widget.text717 logging.debug("result_type_widget_text:%s", result_type_widget_text)718 result_widget = context.testStep.has_widget("com.ziipin.homeinn:id/area_text")719 result_widget_text = result_widget.text720 logging.debug("result_widget_text:%s", result_widget_text)721 722 if not result_type_widget_text==u'地点':723 found = False724 else:725 found = True726 727 while (found==False):728 next_result_type_widget = context.testStep.has_widget("com.ziipin.homeinn:id/type_text", 729 context.testStep._under(result_widget_text))730 next_result_type_widget_text = next_result_type_widget.text731 logging.debug("next_result_type_widget_text:%s", next_result_type_widget_text)732 result_widget = context.testStep.has_widget("com.ziipin.homeinn:id/area_text", 733 context.testStep._under(result_widget_text))734 result_widget_text = result_widget.text735 logging.debug("result_widget_text:%s", result_widget_text)736 737 if not next_result_type_widget_text==u'地点':738 found = False739 context.testStep._swipe_to_distination_half_by_half(next_result_type_widget,\740 result_type_widget, "bottom2top")741 logging.debug("not found")742 else:743 found = True744 logging.debug("found")745 746 result_widget_text = result_widget_text747 result_type_widget = next_result_type_widget748 context.destination_key_word = result_widget_text749 logging.info("destination_key_word:%s", context.destination_key_word)750 context.testStep.tap_widget(result_type_widget)751 752@when(u'用户选择搜索结果中第一个酒店')753def step_impl(context):754 result_type_widget = context.testStep.has_widget("com.ziipin.homeinn:id/type_text")755 result_type_widget_text = result_type_widget.text756 logging.debug("result_type_widget_text:%s", result_type_widget_text)757 result_widget = context.testStep.has_widget("com.ziipin.homeinn:id/area_text")758 result_widget_text = result_widget.text759 logging.debug("result_widget_text:%s", result_widget_text)760 761 if not result_type_widget_text==u'酒店':762 found = False763 else:764 found = True765 766 while (found==False):767 next_result_type_widget = context.testStep.has_widget("com.ziipin.homeinn:id/type_text", 768 context.testStep._under(result_widget_text))769 next_result_type_widget_text = next_result_type_widget.text770 logging.debug("next_result_type_widget_text:%s", next_result_type_widget_text)771 result_widget = context.testStep.has_widget("com.ziipin.homeinn:id/area_text", 772 context.testStep._under(result_widget_text))773 result_widget_text = result_widget.text774 logging.debug("result_widget_text:%s", result_widget_text)775 776 if not next_result_type_widget_text==u'酒店':777 found = False778 context.testStep._swipe_to_distination_half_by_half(next_result_type_widget,\779 result_type_widget, "bottom2top")780 logging.debug("not found")781 else:782 found = True783 logging.debug("found")784 785 result_widget_text = result_widget_text786 result_type_widget = next_result_type_widget787 context.hotel = result_widget_text788 # remove brand of full hotel name789 context.hotel = context.hotel[context.hotel.find('-')+1:len(context.hotel)]790 logging.info("context.hotel:%s", context.hotel)791 context.testStep.tap_widget(result_type_widget)792 793@when(u'用户点击关键词搜索')794def step_impl(context):795 key_word_widget = context.testStep.has_widget("com.ziipin.homeinn:id/n_main_key_text")796 context.destination_key_word = key_word_widget.text797 logging.debug("context.destination_key_word:%s", context.destination_key_word)798 context.testStep.tap_widget(key_word_widget)799 800@when(u'用户选择列表中第一个{area}')801def step_impl(context, area):802 district_widget = context.testStep.has_widget("com.ziipin.homeinn:id/area_text")803 context.destination_key_word = district_widget.text804 logging.debug("context.destination_key_word:%s", context.destination_key_word)805 context.testStep.tap_widget(district_widget)806 807@when(u'用户选择列表中中间一个{area}')808def step_impl(context, area):809 district_widgets = context.testStep.has_widgets("com.ziipin.homeinn:id/area_text")810 context.destination_key_word = district_widgets[int(len(district_widgets)/2)-1].text811 logging.debug("context.destination_key_word:%s", context.destination_key_word)812 context.testStep.tap_widget(district_widgets[int(len(district_widgets)/2)-1])813 814@when(u'用户选择列表中最后一个{area}')815def step_impl(context, area):816 district_widgets = context.testStep.has_widgets("com.ziipin.homeinn:id/area_text")817 district_widget_text = district_widgets[0].text818 819 result_list_widget = context.testStep.has_widget("com.ziipin.homeinn:id/result_list")820 bottom = False821 822 while (bottom==False):823 context.testStep._swipe_to_distination_half_by_half(result_list_widget, result_list_widget, "bottom2top")824 district_widgets = context.testStep.has_widgets("com.ziipin.homeinn:id/area_text")825 logging.debug("district_widget_text:%s", district_widget_text)826 logging.debug("district_widgets[0].text:%s", district_widgets[0].text)827 828 if district_widget_text==district_widgets[0].text:829 bottom = True830 else:831 district_widget_text = district_widgets[0].text832 833 context.destination_key_word = district_widgets[len(district_widgets)-1].text834 logging.debug("context.destination_key_word:%s", context.destination_key_word)835 context.testStep.tap_widget(district_widgets[len(district_widgets)-1])836 837@when(u'用户滑动列表直到有“{brand}”品牌并选择')838def step_impl(context, brand):839 try:840 widget = context.testStep.has_widget(brand)841 except NoSuchElementException:842 found = False843 else:844 found = True845 846 bottom = False847 brand_widget_text = None848 checker_widgets = context.testStep.has_widgets('com.ziipin.homeinn:id/checker')849 brand_widgets = context.testStep.has_widgets('com.ziipin.homeinn:id/brand_name_text')850 851 while (found==False) and (bottom==False):852 logging.debug("brand_widget_text:%s", brand_widget_text)853 logging.debug("len(brand_widgets):%d", len(brand_widgets))854 logging.debug("brand_widgets[0].text:%s", brand_widgets[0].text)855 856 if brand_widget_text==brand_widgets[0].text:857 bottom = True858 else:859 brand_widget_text = brand_widgets[0].text860 861 context.testStep._swipe_to_distination_half_by_half(checker_widgets[len(checker_widgets)-1], checker_widgets[0], "bottom2top")862 try:863 widget = context.testStep.has_widget(brand)864 except NoSuchElementException:865 found = False866 checker_widgets = context.testStep.has_widgets('com.ziipin.homeinn:id/checker')867 brand_widgets = context.testStep.has_widgets('com.ziipin.homeinn:id/brand_name_text')868 else:869 found = True870 871 if found==True:872 found = False873 i = 0874 875 while (found==False):876 logging.debug("checker_widgets[i].location.get('y'): " + str(checker_widgets[i].location.get('y')))877 878 if widget.location.get('y')<checker_widgets[i].location.get('y')+checker_widgets[i].size['height']\879 and widget.location.get('y')+widget.size['height']>checker_widgets[i].location.get('y'):880 found = True881 if checker_widgets[i].get_attribute('checked')=='false':882 context.testStep.tap_widget(widget)883 else:884 i = i + 1885 logging.debug("i: %d", i)886 887 else:888 assert False889@when(u'用户滑动列表并点击所有品牌')890def step_impl(context):891 found = False892 bottom = False893 brand_widget_text = None894 895 while (found==False) and (bottom==False):896 checker_widgets = context.testStep.has_widgets('com.ziipin.homeinn:id/checker')897 brand_widgets = context.testStep.has_widgets('com.ziipin.homeinn:id/brand_name_text')898 logging.debug("len(checker_widgets):%d", len(checker_widgets))899 logging.debug("len(brand_widgets):%d", len(brand_widgets))900 logging.debug("brand_widget_text:%s", brand_widget_text)901 logging.debug("brand_widgets[0].text:%s", brand_widgets[0].text)902 903 if brand_widget_text==brand_widgets[0].text:904 bottom = True905 else:906 brand_widget_text = brand_widgets[0].text907 908 for i in range(len(checker_widgets)):909 logging.debug("i: %d", i)910 logging.debug("brand_widgets[%s].text:%s", i, brand_widgets[i].text)911 if checker_widgets[i].get_attribute('checked')=='false':912 logging.debug("tap checker_widgets[%s]", i)913 context.testStep.tap_widget(checker_widgets[i])914 915 context.testStep._swipe_to_distination_half_by_half(checker_widgets[len(checker_widgets)-1], checker_widgets[0], "bottom2top")916 917@when(u'用户划动右则字母控件,从顶划到n字')918def step_impl(context):919 list_sider_widget = context.testStep.has_widget('com.ziipin.homeinn:id/list_sider')920 context.testStep.swipe_widget('com.ziipin.homeinn:id/list_sider', "middle", 1, "middle", "middle")921 922 923@when(u'用户执行取消订单等一系列动作')924def step_impl(context):925 context.execute_steps(u'''926##########################################################927 假如 掌上如家显示“过夜房”页面928 当 用户点击“我的”929 那么 掌上如家跳转到我的界面930 当 用户点击“我的订单”931 那么 掌上如家跳转到“我的订单”界面932 假如 掌上如家有“预订成功”的订单933 当 用户点击以上订单934###############订单详情界面################################935 那么 掌上如家跳转到“订单详情”界面936 而且 掌上如家有“立即支付”按钮937 当 用户上划屏幕查看订单详情直到有“取消订单”938 当 用户点击“取消订单”939 那么 掌上如家提示“是否取消当前订单”940 当 用户点击“是”941 那么 掌上如家提示“订单取消成功”942 ''')943 944@when(u'用户执行修改入住日期为“{checkin}”,离店日期为“{checkout}”等一系列动作')945def step_impl(context, checkin, checkout):946 if context.check_in_out_right == False:947 context.execute_steps(u'''948 当 用户点击过夜房入住离店日期949 ###############选择入住时间界面################################950 那么 掌上如家跳转到选择入住时间界面951 而且 掌上如家有“可选择90天内日期”提示952 而且 掌上如家有“完成”按键953 当 用户点击入住日期为“'''+checkin+u'''”954 那么 掌上如家入住日期显示为“'''+checkin+u'''”955 当 用户点击离店日期为“'''+checkout+u'''”956 ##########################################################957 ''')958 959@when(u'用户执行选择第一个不是已满的酒店,选择第一个不是已满的房型,提交订单等一系列动作')960def step_impl(context):961 context.execute_steps(u'''962 当 用户选择第一个不是已满的酒店963#--------------酒店详情界面------------------------------------#964 那么 掌上如家跳转到选房预订界面965 而且 掌上如家有房型列表966 当 用户展开第一个不是已满的房型967 那么 掌上如家房型会有“门市价”控件968 当 用户划动第一个不是已满的房型到最顶969 那么 掌上如家房型会有“会员价”控件970 而且 掌上如家房型会有“预订”按钮971 当 用户点击“预订”按钮972#--------------提交订单界面-----------------------------------#973 那么 掌上如家跳转到“提交订单”界面974 当 用户点击“提交订单”按钮975 ''')976 977@when(u'用户执行选择第一个不是已满的房型,提交订单等一系列动作')978def step_impl(context):979 context.execute_steps(u'''980#--------------酒店详情界面------------------------------------#981 那么 掌上如家跳转到选房预订界面982 而且 掌上如家有房型列表983 当 用户展开第一个不是已满的房型984 那么 掌上如家房型会有“门市价”控件985 当 用户划动第一个不是已满的房型到最顶986 那么 掌上如家房型会有“会员价”控件987 而且 掌上如家房型会有“预订”按钮988 当 用户点击“预订”按钮989#--------------提交订单界面-----------------------------------#990 那么 掌上如家跳转到“提交订单”界面991 当 用户点击“提交订单”按钮992 ''')993 994@then(u'掌上如家“当前位置”为“{widget_text}”')995def step_impl(context, widget_text):996 element = context.testStep.has_widget(widget_text, context.testStep._under('当前位置'))997 context.element = element998 999@then(u'掌上如家“最近选择”不为空')1000def step_impl(context):1001 context.testStep.has_widget('最近选择')1002 context.testStep.has_widget('com.ziipin.homeinn:id/city_text',\1003 context.testStep._under('最近选择')+context.testStep._above('热门城市'))1004 1005@then(u'掌上如家“最近选择”为空')1006def step_impl(context):1007 try:1008 context.testStep.has_widget('最近选择')1009 except NoSuchElementException:1010 pass1011 else:1012 assert False1013 1014@then(u'掌上如家“当前位置”不为“{widget_text}”')1015def step_impl(context, widget_text):1016 element = context.testStep.has_widget("com.ziipin.homeinn:id/city_text")1017 logging.debug("current_pos:%s", element.text)1018 if not element.text==widget_text:1019 pass1020 else:1021 raise Exception1022 1023@then(u'掌上如家城市显示为“{widget_text}”')1024def step_impl(context, widget_text):1025 current_city = context.testStep.has_widget("com.ziipin.homeinn:id/city_layout")1026 current_city.find_element_by_string(widget_text)1027@then(u'掌上如家“{roomtype}”页面有“{keyword}”条件')1028def step_impl(context, roomtype, keyword):1029 context.testStep.wait_widget(roomtype)1030 context.testStep.wait_widget(keyword)1031@then(u'掌上如家{verb}选择入住时间界面')1032def step_impl(context, verb):1033 today = datetime.date.today()1034 context.testStep.wait_widget('选择入住时间')1035 context.testStep.wait_widget('离店')1036 1037@then(u'掌上如家入住日期显示为“{checkin}”')1038def step_impl(context, checkin):1039 context.testStep.wait_widget("com.ziipin.homeinn:id/start_date_tab")1040 checkinview = context.testStep.has_widget("com.ziipin.homeinn:id/start_date_tab")1041 checkinview.text.find(str(context.check_in_date.month)+u"月")1042 checkinview.text.find(str(context.check_in_date.day)+u"日")1043 1044@then(u'掌上如家离店日期显示为“请选择离店时间”')1045def step_impl(context):1046 checkoutview = context.testStep.has_widget("com.ziipin.homeinn:id/end_date_tab")1047 if checkoutview.text.find(u'请选择离店时间')==-1:1048 assert False1049 else:1050 pass1051@then(u'掌上如家“过夜房”页面显示为“{checkin}”入住,“{checkout}”离店')1052def step_impl(context, checkin, checkout):1053 context.check_in_date = _parse_date(checkin)1054 logging.info("check in date: " + str(context.check_in_date))1055 context.check_out_date = _parse_date(checkout)1056 logging.info("check out date: " + str(context.check_out_date))1057 context.testStep.has_widget(str(context.check_in_date.month)+"月")1058 context.testStep.has_widget(str(context.check_out_date.month)+"月")1059 context.testStep.has_widget(str(context.check_in_date.day))1060 context.testStep.has_widget(str(context.check_out_date.day))1061@then(u'掌上如家酒店页面显示为“{checkin}”入住,“{checkout}”离店')1062def step_impl(context, checkin, checkout):1063 context.check_in_date = _parse_date(checkin)1064 logging.debug("check in date: " + str(context.check_in_date))1065 context.check_out_date = _parse_date(checkout)1066 logging.debug("check out date: " + str(context.check_out_date))1067 if len(str(context.check_in_date.day)) == 1:1068 context.testStep.has_widget(str(context.check_in_date.month)+"月0"+str(context.check_in_date.day)+"日")1069 else:1070 context.testStep.has_widget(str(context.check_in_date.month)+"月"+str(context.check_in_date.day)+"日")1071 1072 if len(str(context.check_out_date.day)) == 1:1073 context.testStep.has_widget(str(context.check_out_date.month)+"月0"+str(context.check_out_date.day)+"日")1074 else:1075 context.testStep.has_widget(str(context.check_out_date.month)+"月"+str(context.check_out_date.day)+"日")1076 1077@then(u'掌上如家跳转到选房预订界面')1078def step_impl(context):1079 try:1080 context.testStep.wait_widget(context.hotel)1081 except NoSuchElementException:1082 context.testStep.wait_widget((context.hotel)[0:9])1083@then(u'掌上如家关键词搜索列表显示“{hotel}”')1084def step_impl(context, hotel):1085 try:1086 hotel_widget = context.testStep.has_widget(hotel)1087 except NoSuchElementException:1088 hotel_widget = context.testStep.has_widget(hotel[0:9])1089 context.hotel = hotel 1090 # remove brand of full hotel name1091 context.hotel = context.hotel[context.hotel.find('-')+1:len(context.hotel)]1092 1093@then(u'掌上如家的“{widget_text}”为灰色不可用')1094def step_impl(context, widget_text):1095 button_widget = context.testStep.has_widget(widget_text)1096 1097 if button_widget.get_attribute('clickable')=="false":1098 pass1099 else:1100 raise Exception1101 1102 1103@then(u'掌上如家的“{widget_text}”为可用')1104def step_impl(context, widget_text):1105 button_widget = context.testStep.has_widget(widget_text)1106 1107 if button_widget.get_attribute('clickable')=="true":1108 pass1109 else:1110 raise Exception 1111 1112@then(u'掌上如家品牌列表的“{widget_text}”右方圆圈为已勾选')1113def step_impl(context, widget_text):1114 found = False1115 i = 01116 brand_widgets = context.testStep.has_widgets('com.ziipin.homeinn:id/checker')1117 button_widget = context.testStep.has_widget(widget_text)1118 1119 while (found==False):1120 logging.debug("button_widget.location.get('y'): " + str(button_widget.location.get('y')))1121 logging.debug("brand_widgets[i].location.get('y')+brand_widgets[i].size['height']: " \1122 + str(brand_widgets[i].location.get('y')+brand_widgets[i].size['height']))1123 logging.debug("button_widget.location.get('y')+button_widget.size['height']: " \1124 + str(button_widget.location.get('y')+button_widget.size['height']))1125 logging.debug("brand_widgets[i].location.get('y'): " + str(brand_widgets[i].location.get('y')))1126 1127 if button_widget.location.get('y')<brand_widgets[i].location.get('y')+brand_widgets[i].size['height']\1128 and button_widget.location.get('y')+button_widget.size['height']>brand_widgets[i].location.get('y'):1129 found = True1130 else:1131 i = i + 11132 logging.debug("i: %d", i)1133 1134 if brand_widgets[i].get_attribute('checked')=="true":1135 pass1136 else:1137 raise Exception 1138@then(u'掌上如家品牌列表所有品牌为不可用,全部为可用')1139def step_impl(context):1140 top = False1141 checker_widgets = context.testStep.has_widgets('com.ziipin.homeinn:id/checker')1142 brand_widget = context.testStep.has_widget('com.ziipin.homeinn:id/brand_name_text')1143 brand_widget_text = brand_widget.text1144 logging.debug("brand_widget_text: %s", brand_widget_text)1145 1146 while (top==False):1147 if brand_widget_text==u'全部品牌':1148 if checker_widgets[0].get_attribute('checked')=="false":1149 raise Exception1150 1151 i = 1 1152 logging.debug("i: %d", i)1153 while i<len(checker_widgets):1154 if checker_widgets[i].get_attribute('checked')=="true":1155 raise Exception1156 i += 11157 else:1158 for i in range(len(checker_widgets)):1159 logging.debug("i: %d", i)1160 if checker_widgets[i].get_attribute('checked')=="true":1161 raise Exception1162 1163 logging.debug("_swipe_to_distination_half_by_half")1164 context.testStep._swipe_to_distination_half_by_half(checker_widgets[0]\1165 , checker_widgets[len(checker_widgets)-1], "top2bottom")1166 1167 checker_widgets = context.testStep.has_widgets('com.ziipin.homeinn:id/checker')1168 if brand_widget_text==brand_widget.text:1169 top = True1170 else:1171 brand_widget_text = brand_widget.text1172 logging.debug("brand_widget_text: %s", brand_widget_text)1173 1174 1175 1176@then(u'掌上如家订单的入住日期为“{checkin}”,离店日期为“{checkout}”')1177def step_impl(context, checkin, checkout):1178 check_in_date = _parse_date(checkin)1179 logging.debug("check in date: " + str(check_in_date))1180 check_out_date = _parse_date(checkout)1181 logging.debug("check out date: " + str(check_out_date))1182 context.testStep.has_widget('入住 '+str(check_in_date)+' / 离店 '+str(check_out_date))1183 1184@then(u'掌上如家“过夜房”页面入住和离店日期显示为原来的日期')1185def step_impl(context):1186 check_in_date_month = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_month_1').text1187 logging.debug("check_in_date_month: " + check_in_date_month)1188 1189 check_in_date_day = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_day_1').text1190 logging.debug("check_in_date_day: " + check_in_date_day)1191 1192 check_out_date_month = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_month_2').text1193 logging.debug("check_out_date_month: " + check_out_date_month)1194 1195 check_out_date_day = context.testStep.has_widget('com.ziipin.homeinn:id/n_date_day_2').text1196 logging.debug("check_out_date_day: " + check_out_date_day)1197 check_in_date = _parse_date(check_in_date_month+check_in_date_day+u'日')1198 logging.info("check_in_date: " + str(check_in_date))1199 check_out_date = _parse_date(check_out_date_month+check_out_date_day+u'日')1200 logging.info("check_out_date: " + str(check_out_date))1201 logging.info("context.check_in_date: " + str(context.check_in_date))1202 logging.info("context.check_out_date: " + str(context.check_out_date))1203 1204 if context.check_in_date==check_in_date and context.check_out_date==check_out_date:1205 pass1206 else:1207 assert False1208 1209@then(u'掌上如家离店日期显示“{widget_text}”')1210def step_impl(context, widget_text):1211 widget = context.testStep.has_widget('com.ziipin.homeinn:id/end_date_tab')1212 if widget.text.find(widget_text)==-1:1213 assert False1214 1215@when(u'用户选择第一个周边商户的“去这里”按钮')1216def step_impl(context):1217 context.testStep.tap_widget('com.ziipin.homeinn:id/near_layout')1218 context.testStep.tap_widget('去这里')1219 1220######################wait_widget############################################1221@then(u'掌上如家{verb}“{widget_text}”页面')1222def step_impl(context, verb, widget_text):1223 context.testStep.wait_widget(widget_text, 30, 1, True)1224 1225@given(u'掌上如家{verb}“{widget_text}”页面')1226def step_impl(context, verb, widget_text):1227 context.testStep.wait_widget(widget_text, 30, 1, True)1228 1229@when(u'掌上如家{verb}“{widget_text}”页面')1230def step_impl(context, verb, widget_text):1231 context.testStep.wait_widget(widget_text, 30, 1, True)1232 1233@then(u'掌上如家{verb}“{widget_text}”界面')1234def step_impl(context, verb, widget_text):1235 context.testStep.wait_widget(widget_text, 30, 1, True)1236@then(u'掌上如家{verb}“{widget_text}”提示')1237def step_impl(context, verb, widget_text):1238 context.testStep.wait_widget(widget_text)1239@then(u'掌上如家{verb}“{widget_text}”按键')1240def step_impl(context, verb, widget_text):1241 context.testStep.wait_widget(widget_text, 30, 1, True)1242 1243@then(u'掌上如家{verb}“{widget_text}”按钮')1244def step_impl(context, verb, widget_text):1245 context.testStep.wait_widget(widget_text, 30, 1, True)1246 1247@then(u'掌上如家{verb}“{widget_text}”控件')1248def step_impl(context, verb, widget_text):1249 context.testStep.wait_widget(widget_text, 30, 1, True)1250 1251@given(u'掌上如家有去选房控件')1252def step_impl(context):1253 try:1254 context.testStep.wait_widget('去选房', 5, 1, True)1255 context.select_room = None1256 except:1257 pass1258 1259@then(u'掌上如家跳转到地图选择酒店界面')1260def step_impl(context):1261 context.testStep.wait_widget(context.city)1262 1263@then(u'掌上如家提示“{widget_text}”')1264def step_impl(context, widget_text):1265 context.testStep.wait_widget(widget_text)1266 1267@then(u'掌上如家有“{widget_text}”')1268def step_impl(context, widget_text):1269 context.testStep.wait_widget(widget_text, 30, 1, True)1270 1271@then(u'掌上如家页面有酒店列表')1272def step_impl(context):1273 context.testStep.wait_widget("com.ziipin.homeinn:id/text_hotel_name", 30, 1, True)1274@then(u'掌上如家有房型列表')1275def step_impl(context):1276 try:1277 context.testStep.wait_widget("com.ziipin.homeinn:id/room_info_layout", 30, 1, True)1278 except TimeoutException:1279 context.testStep.swipe_up_and_retry('您的网络好像不太给力,请稍后再试', '点击重试')1280 context.testStep.wait_widget("com.ziipin.homeinn:id/room_info_layout")1281 1282@then(u'掌上如家有收藏酒店列表')1283def step_impl(context):1284 context.testStep.wait_widget("com.ziipin.homeinn:id/favorite_list", 30, 1, True)1285 1286@then(u'掌上如家出现选择优惠券界面')1287def step_impl(context):1288 if not (context.coupon == None):1289 context.testStep.wait_widget('选择优惠券')1290 1291@then(u'掌上如家有预订酒店名')1292def step_impl(context):1293 logging.debug("context.hotel: " + context.hotel)1294 context.testStep.wait_widget(context.hotel, 5)1295@then(u'掌上如家有预订房型')1296def step_impl(context):1297 logging.debug("context.room_type: " + context.room_type)1298 context.testStep.wait_widget(context.room_type, 5)1299@then(u'掌上如家有搜索结果')1300def step_impl(context):1301 context.testStep.wait_widget('com.ziipin.homeinn:id/area_text', 5)1302@then(u'掌上如家“过夜房”页面有{area}的条件')1303def step_impl(context, area):1304 context.testStep.wait_widget(context.destination_key_word, 5)1305 1306@then(u'掌上如家“过夜房”页面的品牌不变')1307def step_impl(context):1308 context.testStep.wait_widget(context.brand, 5)1309 1310@then(u'掌上如家出现通讯录界面')1311def step_impl(context):1312 context.testStep.wait_widget('选择联系人', 5)1313 context.testStep.tap_permision_widget("accept") 1314 1315@then(u'掌上如家有“{district}”、“{circle}”和“{subway}”三个页面')1316def step_impl(context, district, circle, subway):1317 context.testStep.wait_widget(district)1318 context.testStep.wait_widget(circle)1319 context.testStep.wait_widget(subway)1320@then(u'掌上如家跳转到过夜房选择酒店界面')1321def step_impl(context):1322 context.testStep.wait_widget('排序')1323 context.testStep.wait_widget('品牌')1324 context.testStep.wait_widget('筛选')1325 context.testStep.wait_widget('查看地图')1326@then(u'掌上如家跳转到选择时租房酒店界面')1327def step_impl(context):1328 context.testStep.wait_widget('排序')1329 context.testStep.wait_widget('品牌')1330 context.testStep.wait_widget('查看地图')1331@then(u'掌上如家{verb}我的界面')1332def step_impl(context, verb):1333 my_account_widget = context.testStep.has_widget('我的')1334 1335 if my_account_widget.get_attribute('checked')=="true":1336 pass1337 else:1338 assert False1339 1340@then(u'掌上如家“最近选择”有四个城市')1341def step_impl(context):1342 elements = context.testStep.has_widgets('//android.widget.TextView[@text]',\1343 context.testStep._under('最近选择')+context.testStep._above('热门城市'))1344 logging.debug('len(elements):%d', len(elements))1345 for i in range(len(elements)):1346 logging.debug('city:%s', elements[i].text)1347 1348 if len(elements)==4:1349 pass1350 else:1351 assert False1352 1353@then(u'掌上如家“最近选择”少于四个城市')1354def step_impl(context):1355 elements = context.testStep.has_widgets('//android.widget.TextView[@text]',\1356 context.testStep._under('最近选择')+context.testStep._above('热门城市'))1357 1358 if len(elements)<4:1359 pass1360 else:1361 assert False1362 1363@then(u'掌上如家过夜房页面城市条件为“{city}”')1364def step_impl(context, city):1365 city_widget = context.testStep.has_widget('com.ziipin.homeinn:id/n_main_city_text')1366 context.city = city_widget.text1367 assert (context.city==city)1368 1369@then(u'掌上如家出现周边地图')1370def step_impl(context):1371 context.testStep.wait_widget('com.ziipin.homeinn:id/map_view')1372@then(u'掌上如家有周边列表')1373def step_impl(context):1374 context.testStep.wait_widget('com.ziipin.homeinn:id/near_list')1375 1376@then(u'掌上如家“品牌”界面内有')1377def step_impl(context):1378 for row in context.table:1379 logging.debug(row['brand'])1380 context.testStep.wait_widget(row['brand'])1381@then(u'掌上如家“品牌”页面内有')1382def step_impl(context):1383 for row in context.table:1384 logging.debug(row['brand'])1385 context.testStep.wait_widget(row['brand'])1386@then(u'掌上如家“筛选”页面内有')1387def step_impl(context):1388 for row in context.table:1389 logging.debug(row['filter'])1390 context.testStep.wait_widget(row['filter'])1391@then(u'掌上如家“排序”页面内有')1392def step_impl(context):1393 for row in context.table:1394 logging.debug(row['sort'])1395 context.testStep.wait_widget(row['sort'])1396@then(u'掌上如家“行政区”页面内有')1397def step_impl(context):1398 for row in context.table:1399 logging.debug(row['district'])1400 context.testStep.wait_widget(row['district'])1401 1402@then(u'掌上如家“商圈”页面内有')1403def step_impl(context):1404 for row in context.table:1405 logging.debug(row['area'])1406 context.testStep.wait_widget(row['area'])1407@then(u'掌上如家“地铁”页面内有')1408def step_impl(context):1409 for row in context.table:1410 logging.debug(row['subway'])1411 context.testStep.wait_widget(row['subway'])1412@then(u'掌上如家“选择出行目的”页面内有')1413def step_impl(context):1414 for row in context.table:1415 logging.debug(row['target'])1416 context.testStep.wait_widget(row['target'])1417 1418@then(u'掌上如家“分享酒店”页面内有')1419def step_impl(context):1420 for row in context.table:1421 logging.debug(row['share'])1422 context.testStep.wait_widget(row['share'])1423@then(u'掌上如家“过夜房”页面的品牌为')1424def step_impl(context):1425 context.brand = None1426 for row in context.table:1427 logging.debug(row['brand'])1428 context.testStep.wait_widget(row['brand'])1429 if context.brand==None:1430 context.brand = row['brand']1431 else:1432 context.brand = context.brand + ',' + row['brand']1433 1434@then(u'掌上如家城市列表有')1435def step_impl(context):1436 for row in context.table:1437 logging.debug(row['city'])1438 context.testStep.wait_widget(row['city'])1439 1440@then(u'掌上如家“导航”页面内有')1441def step_impl(context):1442 for row in context.table:1443 logging.debug(row['navigation'])1444 context.testStep.wait_widget(row['navigation'])1445 1446@then(u'掌上如家“到店时间”页面内有')1447def step_impl(context):1448 for row in context.table:1449 logging.debug(row['arrival'])1450 context.testStep.wait_widget(row['arrival'])1451 1452@then(u'掌上如家“偏好选择”页面内有')1453def step_impl(context):1454 for row in context.table:1455 logging.debug(row['peference'])1456 context.testStep.wait_widget(row['peference'])1457 1458########################tap_widget#####################################1459@when(u'用户点击城市')1460def step_impl(context):1461 context.testStep.tap_widget("com.ziipin.homeinn:id/n_main_city_text")1462@when(u'用户点击“{widget_text}”')1463def step_impl(context, widget_text):1464 #context.testStep.click_widget(widget_text)1465 context.testStep.tap_widget(widget_text)1466@when(u'用户点击“{widget_text}”页面')1467def step_impl(context, widget_text):1468 context.testStep.tap_widget(widget_text)1469@when(u'用户点击“{widget_text}”按键')1470def step_impl(context, widget_text):1471 widget = context.testStep.has_widget("//android.widget.Button[@text='"+widget_text+"']")1472 context.testStep.tap_widget(widget)1473@when(u'用户点击“{widget_text}”按钮')1474def step_impl(context, widget_text):1475 widget = context.testStep.has_widget("//android.widget.Button[@text='"+widget_text+"']")1476 context.testStep.tap_widget(widget)1477@when(u'用户点击民宿')1478def step_impl(context):1479 context.testStep.tap_widget("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[3]/android.widget.HorizontalScrollView[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]")1480@when(u'用户点击定位城市')1481def step_impl(context):1482 context.testStep.tap_widget("com.ziipin.homeinn:id/top_title")1483@when(u'用户点击左上角返回按钮')1484def step_impl(context):1485 context.testStep.tap_widget("com.ziipin.homeinn:id/back_btn") 1486@when(u'用户点击当前位置')1487def step_impl(context):1488 context.testStep.tap_widget("com.ziipin.homeinn:id/type_layout")1489@when(u'用户点击收藏')1490def step_impl(context):1491 context.testStep.tap_widget("com.ziipin.homeinn:id/favorite_btn")1492@when(u'用户点击酒店详情')1493def step_impl(context):1494 context.testStep.tap_widget("com.ziipin.homeinn:id/detail_info_layout")1495@when(u'用户点击分享酒店')1496def step_impl(context):1497 context.testStep.tap_widget("com.ziipin.homeinn:id/share_btn")1498@when(u'用户点击酒店地址')1499def step_impl(context):1500 context.testStep.tap_widget("com.ziipin.homeinn:id/hotel_address_text")1501@when(u'用户点击电话按钮')1502def step_impl(context):1503 context.testStep.tap_widget("com.ziipin.homeinn:id/tell_btn")1504 1505@when(u'用户点击城市列表中的“{widget_text}”')1506def step_impl(context, widget_text):1507 context.testStep.tap_widget("//android.widget.TextView[@text='"+widget_text+"']")1508 1509@when(u'用户点击城市列表中“{widget_text}”')1510def step_impl(context, widget_text):1511 context.testStep.tap_widget("//android.widget.TextView[@text='"+widget_text+"']")1512@when(u'用户点击搜索列表中“{widget_text}”')1513def step_impl(context, widget_text):1514 context.testStep.tap_widget("//android.widget.TextView[@text='"+widget_text+"']")1515 1516@when(u'用户点击热门城市里的“{widget_text}”')1517def step_impl(context, widget_text):1518 element = context.testStep.has_widget(widget_text, context.testStep._under('热门城市'))1519 context.testStep.tap_widget(element)1520 1521@when(u'用户点击当前位置里的城市')1522def step_impl(context):1523 element = context.testStep.has_widget('//android.widget.TextView[@text]',\1524 context.testStep._under('当前位置')+context.testStep._above('热门城市'))1525 context.testStep.tap_widget(element)1526 1527@when(u'用户点击最近选择里的城市')1528def step_impl(context):1529 element = context.testStep.has_widget('//android.widget.TextView[@text]',\1530 context.testStep._under('最近选择')+context.testStep._above('热门城市'))1531 context.testStep.tap_widget(element)1532 1533@when(u'用户点击电子券')1534def step_impl(context):1535 if not (context.coupon==None):1536 context.testStep.tap_widget("com.ziipin.homeinn:id/coupon_price")1537@when(u'用户点击积分加速计划说明')1538def step_impl(context):1539 context.testStep.tap_widget("com.ziipin.homeinn:id/speed_desp_btn")1540@when(u'用户点击积分加速计划')1541def step_impl(context):1542 context.testStep.tap_widget("com.ziipin.homeinn:id/speed_checker")1543@when(u'用户点击出行目的')1544def step_impl(context):1545 context.testStep.tap_widget("com.ziipin.homeinn:id/commit_aim_layout")1546@when(u'用户点击发票')1547def step_impl(context):1548 context.testStep.tap_widget("com.ziipin.homeinn:id/invoice_input")1549@when(u'用户点击订单详情')1550def step_impl(context):1551 context.testStep.tap_widget("com.ziipin.homeinn:id/right_btn")1552@when(u'用户点击电话')1553def step_impl(context):1554 context.testStep.tap_widget("com.ziipin.homeinn:id/tell_btn")1555 #com.ziipin.homeinn:id/order_taxi_btn1556 #com.ziipin.homeinn:id/order_service_btn1557 #com.ziipin.homeinn:id/cancel_btn1558@when(u'用户点击支付宝支付')1559def step_impl(context):1560 context.testStep.tap_widget("com.ziipin.homeinn:id/type_tab_ali")1561@when(u'用户点击微信支付')1562def step_impl(context):1563 context.testStep.tap_widget("com.ziipin.homeinn:id/type_tab_wechat")1564@when(u'用户点击如家钱包支付')1565def step_impl(context):1566 context.testStep.tap_widget("com.ziipin.homeinn:id/type_tab_wallet")1567@when(u'用户点击银行卡支付')1568def step_impl(context):1569 context.testStep.tap_widget("com.ziipin.homeinn:id/type_tab_union")1570@when(u'用户点击立即支付')1571def step_impl(context):1572 context.testStep.tap_widget("com.ziipin.homeinn:id/order_pay_btn")1573@when(u'用户点击拨打电话')1574def step_impl(context):1575 context.testStep.tap_widget("com.ziipin.homeinn:id/tell_btn")1576@when(u'用户点击第一个酒店')1577def step_impl(context):1578 context.testStep.tap_widget("com.ziipin.homeinn:id/text_hotel_name")1579@when(u'用户点击添加酒店天数')1580def step_impl(context):1581 context.testStep.tap_widget("com.ziipin.homeinn:id/num_add_btn")1582@when(u'用户点击减少酒店天数')1583def step_impl(context):1584 context.testStep.tap_widget("com.ziipin.homeinn:id/num_dec_btn")1585@when(u'用户点击联系人')1586def step_impl(context):1587 context.testStep.tap_widget("com.ziipin.homeinn:id/contact_name")1588@when(u'用户点击商城券说明')1589def step_impl(context):1590 context.testStep.tap_widget("com.ziipin.homeinn:id/product_desp_btn") 1591@when(u'用户点击添加商城券')1592def step_impl(context):1593 context.testStep.tap_widget("com.ziipin.homeinn:id/add_btn") 1594@when(u'用户点击减少商城券')1595def step_impl(context):1596 context.testStep.tap_widget("com.ziipin.homeinn:id/dec_btn") 1597@when(u'用户点击信用住说明')1598def step_impl(context):1599 context.testStep.tap_widget("com.ziipin.homeinn:id/credit_desp_btn")1600@when(u'用户点击信用住')1601def step_impl(context):1602 context.testStep.tap_widget("com.ziipin.homeinn:id/credit_checker")1603@when(u'用户点击图片')1604def step_impl(context):1605 context.testStep.tap_widget("com.ziipin.homeinn:id/detail_photo")1606@when(u'用户点击关闭')1607def step_impl(context):1608 context.testStep.tap_widget("com.ziipin.homeinn:id/close_btn")1609@when(u'用户点击增值服务')1610def step_impl(context):1611 context.testStep.tap_widget("com.ziipin.homeinn:id/detail_service_layout")1612@when(u'用户点击地址')1613def step_impl(context):1614 context.testStep.tap_widget("com.ziipin.homeinn:id/detail_address_layout")1615@when(u'用户点击分享')1616def step_impl(context):1617 context.testStep.tap_widget("com.ziipin.homeinn:id/share_btn") 1618 1619@when(u'用户点击确认选择')1620def step_impl(context):1621 if not (context.coupon == None):1622 context.testStep.tap_widget('确认选择')1623 1624@when(u'用户取消选择已选房号')1625def step_impl(context):1626 context.testStep.tap_widget('com.ziipin.homeinn:id/sel_room_1')1627 1628@when(u'用户点击品牌筛选')1629def step_impl(context):1630 context.testStep.tap_widget('com.ziipin.homeinn:id/n_main_brand_text')1631 1632@when(u'用户点击去选房')1633def step_impl(context):1634 try:1635 if (context.select_room == None):1636 context.testStep.tap_widget('去选房')1637 except:1638 pass1639@when(u'用户选择搜索结果中第一个结果')1640def step_impl(context):1641 context.testStep.tap_widget("com.ziipin.homeinn:id/area_text")1642 1643@when(u'用户点击过夜房页面品牌筛选')1644def step_impl(context):1645 brand_widget = context.testStep.has_widget("com.ziipin.homeinn:id/n_main_brand_text")1646 context.brand = brand_widget.text1647 context.testStep.tap_widget(brand_widget)1648 1649@when(u'用户点击立即预订')1650def step_impl(context):1651 context.city = context.testStep.has_widget('com.ziipin.homeinn:id/n_main_city_text').text1652 context.testStep.tap_widget("com.ziipin.homeinn:id/n_search_start_btn")1653 ...

Full Screen

Full Screen

Steps.py

Source:Steps.py Github

copy

Full Screen

...13##################################################################14########################## - WEB API - ##########################15##################################################################16 @step("Conectamos con el endpoint (.*)")17 def step_impl(self, host):18 self._endpoint = Functions.get_full_host(self, host)19 return self._endpoint20 @when("Realizamos un GET al endpoint")21 def step_impl(self):22 self.response = Functions.get_request(self)23 return self.response24 @then("Mostramos el RESPONSE por pantalla")25 def step_impl(self):26 Functions.print_api_response(self)27 @step("El status code del RESPONSE es (.*)")28 def step_impl(self, code):29 Functions.response_is(self, code)30 @step("El status code del RESPONSE debe ser 200 OK")31 def step_impl(self):32 Functions.response_is_200(self)33 @step("El status code del RESPONSE debe ser 404 NOT FOUND")34 def step_impl(self):35 Functions.response_is_404(self)36 @then("Asignar a la entidad (.*) el valor (.*)")37 def step_impl(self, entity, value):38 Functions.set_body_values(self, entity, value)39 @when("Asignar el body con el JSON (.*)")40 def step_impl(self, file):41 Functions.set_initial_json_body(self, file)42 @when("Realizamos un PUT al endpoint")43 def step_impl(self):44 Functions.put_request(self)45 @when("Realizamos un POST al endpoint")46 def step_impl(self):47 Functions.post_request(self)48 @step("Validamos el JSON RESPONSE de la entidad (.*) con el valor (.*)")49 def step_impl(self, entity, expected_value):50 Functions.assert_json_response_expected(self, entity, expected_value)51 @step("Validamos el JSON RESPONSE en la que la entidad (.*) en el path (.*) con el valor (.*)")52 def step_impl(self, entity, subPath, expected_value):53 Functions.assert_json_response_expected(self, entity, expected_value, subPath)54 @then("Los elementos (.*) muestran los valores (.*)")55 def step_impl(self, entity, expected_value):56 for row in self.table:57 print(row)58 entity = row['Entity']59 value = row['Value']60 Functions.assert_json_response_expected(self, entity, value)61 @step("Comprobamos el elemento (.*) en el path (.*) muestran los valores (.*)")62 def step_impl(self, entity, subPath, expected):63 for row in self.table:64 print(row)65 entity = row['Entity']66 subPath = row['Path']67 value = row['Value']68 Functions.assert_json_response_expected(self, entity, value, subPath)69 @step("Comparar JSON file Response (.*) con Response")70 def step_impl(self, file):71 Functions.expected_results_value(self, file)72 @step("Asignar al sub-body (.*) el valor (.*)")73 def step_impl(self, entity, value):74 Functions.set_sub_body_dict_values(self, entity, value)75 @step("Añadir valores al sub-body (.*)")76 def step_impl(self, key):77 Functions.set_sub_body_dict(self, key)78 @step("Asignar al sub-array el valor (.*)")79 def step_impl(self, value):80 Functions.set_sub_body_array_values(self, value)81 @step("Añadir valores al sub-array (.*)")82 def step_impl(self, key):83 Functions.set_sub_body_array(self, key)84 @then('Hacer esta SQL Query """(.*)"""')85 def step_impl(self, _query):86 self._result = Functions.pyodbc_query(self, _query)87 @then("Asignar la entidad (.*) con el valor (.*)")88 def step_impl(self, entity, value):89 Functions.set_body_values(self, entity, value)90 @step("Login en Twitter con credenciales OAuth 2.0")91 def step_impl(self):92 auth_body = {"grant_type": "client_credentials"}93 94 bearer_response = requests.post(Inicializar.API_hostAddressBase + "oauth2/token",95 auth=(Inicializar.api_key, Inicializar.api_key_secret), data=auth_body)96 97 auth_response = json.loads(bearer_response.text)98 print(json.dumps(auth_response, indent=3))99 Inicializar.API_headers["Authorization"] = "Bearer " + auth_response['access_token']100 @step("Verificar que el RESPONSE de la entidad (.*) tenga el valor (.*)")101 def step_impl(self, entity, expected):102 Functions.new_compare_entity_values(self, entity, expected)103 @step("Verificar que (.*) tenga el valor (.*)")104 def step_impl(self, entity, value):105 for row in self.table:106 print(row)107 entity = row['Entity']108 value = row['Value']...

Full Screen

Full Screen

StepDefinitions.py

Source:StepDefinitions.py Github

copy

Full Screen

...6from home_page_test import *7from Navigation_test import *8from blavity_hp import *9@given('url is launched')10def step_impl(context):11 time.sleep(2)12 environment()13@when('I am on blavity page')14def step_impl(context):15 page_load()16@then('check whether page is loaded')17def step_impl(context):18 post_page_load_pop_up()19@then('verify whether Blavity HP page is as required')20def step_impl(context):21 verify_blavity_hp_page()22@then('check whether arrow element is present')23def step_impl(context):24 verify_presence_of_element_in_page()25@then('verify if ticker section exists')26def step_impl(context):27 verify_if_ticker_exists()28@then('verify ticker count and links')29def step_impl(context):30 verify_ticker_count_and_links()31@then('verify links arrow buttons and read more link work in carousel')32def step_impl(context):33 verify_carousel_read_more_arrows()34@then('verify side bar top stories section and links')35def step_impl(context):36 verify_side_bar_top_stories()37@then('verify load more stories section and links')38def step_impl(context):39 verify_load_more_stories_home_page()40@then('verify subscribe banner section')41def step_impl(context):42 verify_subscribe_banner_section()43@then('verify lunchtable section')44def step_impl(context):45 verify_lunchtable_section()46@then('verify blavity originals section')47def step_impl(context):48 verify_blavity_originals_section()49@then('verify op ed section')50def step_impl(context):51 verify_page_op_ed_section()52@then('verify from our other sites section')53def step_impl(context):54 verify_from_our_other_sites()55@then('verify footer of blavity site')56def step_impl(context):57 verify_blavity_footer()58@then('verify whether nav bar is present and displayed')59def step_impl(context):60 verify_nav_bar_presence()61@then('verify whether all nav bar links are working')62def step_impl(context):63 verify_nav_bar_links()64@then('verify footer section is present and displayed')65def step_impl(context):66 verify_footer_presence()67@then('verifying page activities when "{slug_value}" value is passed')68def step_impl(context, slug_value):69 print("inside steps ", slug_value)70 verify_navigation_slug_and_page_load(slug_value)71@then('verify whether News page is as required')72def step_impl(context):73 print("inside steps News Page")74 verify_news_page()75@then('verify whether Op-Eds page is as required')76def step_impl(context):77 print("inside steps opinion Page")78 verify_opinion_page()79@then('verify whether Lifestyle page is as required')80def step_impl(context):81 print("inside steps Lifestyle Page")82 verify_life_style_page()83@then('verify whether Politics page is as required')84def step_impl(context):85 print("inside steps Politics Page")86 verify_politics_page()87@then('verify whether Culture page is as required')88def step_impl(context):89 print("inside steps Culture Page")90 verify_culture_page()91@then('verify whether BlavityU page is as required')92def step_impl(context):93 print("inside steps Culture Page")94 verify_blavity_u_page()95@then('verify whether number of articles in opinion section are appropriate or not')96def step_impl(context):97 print("inside steps Culture Page")98 verify_op_eds_exhaust()99@then('close the browser')100def step_impl(context):101 print("closing the browser instance")102 driver.quit()103"""""104verify_blavity_footer105close the browser106if text not in context.response:107 fail('%r not in %r' % (text, context.response))...

Full Screen

Full Screen

cart_verification.py

Source:cart_verification.py Github

copy

Full Screen

...3from features.pages.item_page import ItemPage4from features.pages.locators import CommonLocators5from features.pages.shopping_cart_page import ShoppingCartPage6@given(u'that a User is opened nopCommerce app and a user is positioned on the home page')7def step_impl(context):8 context.selenium_driver.get(context.link)9 context.home_page = HomePage(context.selenium_driver)10 context.item_page = ItemPage(context.selenium_driver)11 context.shopping_cart = ShoppingCartPage(context.selenium_driver)12@when(u'a user selects Camera & photo option from the Electronics menu')13def step_impl(context):14 context.home_page.select_nth_dropdown_option_from_nth_top_menu_option(2, 2)15@when(u'a user clicks on the Add to cart option on the first item')16def step_impl(context):17 context.item_page.add_nth_item_in_cart(1)18 context.added_item = context.item_page.return_nth_item_title(1)19@then(u'the message that product is added is shown')20def step_impl(context):21 assert 'The product has been added to your shopping cart' == context.item_page.return_success_notification_msg()22@then(u'the product is shown in the Shopping cart')23def step_impl(context):24 context.item_page.click_on_close_notification_button()25 context.item_page.scroll_element_into_view(CommonLocators.shopping_cart_header_icon)26 context.item_page.click_on_shopping_cart_header_icon()27 assert context.added_item in context.shopping_cart.return_all_added_products()28@when(u'a user adds two same items into cart')29def step_impl(context):30 context.item_page.add_nth_item_in_cart(1)31 context.item_page.click_on_close_notification_button()32 context.item_page.add_nth_item_in_cart(1)33 context.item_page.click_on_close_notification_button()34@then(u'the quantity value in the cart for the added product is set to 2')35def step_impl(context):36 context.item_page.scroll_element_into_view(CommonLocators.shopping_cart_header_icon)37 context.item_page.click_on_shopping_cart_header_icon()38 assert "2" == context.shopping_cart.return_quantity_value_for_first_product()39@when(u'user opens the Cart page')40def step_impl(context):41 context.item_page.click_on_close_notification_button()42 context.item_page.click_on_shopping_cart_header_icon()43@when(u'user click on the remove button')44def step_impl(context):45 context.shopping_cart.remove_nth_product(1)46@then(u'the product is deleted and appropriate message is shown')47def step_impl(context):48 assert 'Your Shopping Cart is empty!' == context.shopping_cart.return_empty_cart_message()49@when(u'User inputs value in the search field')50def step_impl(context):51 context.inputted_search_value = 'Htc one'52 context.home_page.input_search_value(context.inputted_search_value)53@when(u'user click on the search field')54def step_impl(context):55 context.home_page.click_on_search_btn()56@then(u'searched products are shown')57def step_impl(context):58 if context.item_page.return_number_of_visible_products() > 0: # check if there is searched value59 counter = 060 for title in context.item_page.return_all_product_titles():61 if context.inputted_search_value.upper() in title.upper():62 counter += 163 assert counter == len(context.item_page.return_all_product_titles())64 else: # if there is no searched value check "no data" value...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful