How to use alert_click method in Airtest

Best Python code snippet using Airtest

Pages.py

Source:Pages.py Github

copy

Full Screen

...49 def move_element_to(self,locator):50 hover = self.driver.find_element_by_xpath(locator)51 self.action.move_to_element(hover).perform()52 # Fungsi Click JS Alert53 def alert_click(self, locator):54 self.driver.find_element_by_xpath(locator).click()55 self.driver.switch_to.alert.accept()56class HomePage(BasePage):57 def __init__(self, driver):58 super().__init__(driver)59 self.driver.get(TestData.BASE_URL)60 def signin(self):61 # Fungsi untuk klik tombol Sign In di Home Page62 self.click(Locators.SIGN_IN_BUTTON)63 self.is_visible(Locators.REG_EMAIL_FIELD)64 def logo(self):65 self.click(Locators.LOGO_URL)66 def add_from_home(self):67 self.move_element_to(Locators.PRODUCT_CARD_DRESS)68 self.click(Locators.ADD_TO_CART_BUTTON)69 self.is_visible(Locators.ADD_FROM_HOME_STATUS)70 def category(self):71 self.click(Locators.CATEGORIES_WOMEN_BUTTON)72 def add_from_category(self):73 self.move_element_to(Locators.CATEGORY_PRODUCT_CARD)74 self.click(Locators.CATEGORY_ADD_TO_CART_BUTTON)75 self.is_visible(Locators.CATEGORY_ADD_TO_CART_STATUS)76 def add_from_details(self):77 self.move_element_to(Locators.PRODUCT_CARD)78 self.click(Locators.MORE_BUTTON)79 self.click(Locators.DETAIL_ADD_TO_CART_BUTTON)80 self.is_visible(Locators.DETAIL_PRODUCT_STATUS)81 def add_from_search(self):82 self.enter_text(Locators.SEARCH_FIELD, TestData.SEARCH_VALUE)83 self.click(Locators.SEARCH_SUBMIT)84 self.move_element_to(Locators.SEARCH_PRODUCT_CARD)85 self.click(Locators.SEARCH_ADD_TO_CART_BUTTON)86 self.is_visible(Locators.SEARCH_PRODUCT_STATUS)87 # CHECKOUT88 def checkout_success_bankwire(self):89 # Hover to product90 self.move_element_to(Locators.PRODUCT_CARD_DRESS)91 # Click Add to Cart92 self.click(Locators.ADD_TO_CART_BUTTON)93 # Click Proceed to checkout94 self.click(Locators.PROCEED_TO_CHECKOUT_BTN_POP)95 # Click Proceed to checkout96 self.click(Locators.PROCEED_TO_CHECKOUT_BTN_SUMMARY)97 # Click Proceed to checkout98 self.click(Locators.PROCEED_TO_CHECKOUT_BTN_ADDRESS)99 # Click Checkbox & Proceed to checkout100 self.click(Locators.CHECKOUT_AGREE_CHECK)101 self.click(Locators.PROCEED_TO_CHECKOUT_BTN_SHIPPING)102 # Click Payment Type103 self.click(Locators.CHECKOUT_BY_BANKWIRE)104 # Click Confirm Order105 self.click(Locators.CHECKOUT_CONFIRM_ORDER_BTN)106 # Wait for status107 self.is_visible(Locators.CHECKOUT_STATUS_BANKWIRE)108 def checkout_success_check(self):109 # Hover to product110 self.move_element_to(Locators.PRODUCT_CARD_DRESS)111 # Click Add to Cart112 self.click(Locators.ADD_TO_CART_BUTTON)113 # Click Proceed to checkout114 self.click(Locators.PROCEED_TO_CHECKOUT_BTN_POP)115 # Click Proceed to checkout116 self.click(Locators.PROCEED_TO_CHECKOUT_BTN_SUMMARY)117 # Click Proceed to checkout118 self.click(Locators.PROCEED_TO_CHECKOUT_BTN_ADDRESS)119 # Click Checkbox & Proceed to checkout120 self.click(Locators.CHECKOUT_AGREE_CHECK)121 self.click(Locators.PROCEED_TO_CHECKOUT_BTN_SHIPPING)122 # Click Payment Type123 self.click(Locators.CHECKOUT_BY_CHECK)124 # Click Confirm Order125 self.click(Locators.CHECKOUT_CONFIRM_ORDER_BTN)126 # Wait for status127 self.is_visible(Locators.CHECKOUT_STATUS_BY_CHECK)128class AuthPage(BasePage):129 def __init__(self, driver):130 super().__init__(driver)131 def sign_in_success(self):132 # Type Email133 self.enter_text(Locators.SIGN_IN_EMAIL_FIELD, TestData.SIGN_IN_EMAIL)134 # Type Password135 self.enter_text(Locators.SIGN_IN_PASSWORD_FIELD, TestData.SIGN_IN_PASSWORD)136 # Click Sign In Button137 self.click(Locators.SUBMIT_SIGN_IN)138 def register_success(self):139 # Type Email140 self.enter_text(Locators.REG_EMAIL_FIELD, TestData.SIGN_UP_VALID_EMAIL)141 # Click Create an account button142 self.click(Locators.SUBMIT_CREATE_ACCOUNT)143 # Select Gender144 self.click(Locators.REG_RADIO_GENDER_1)145 # Type First Name146 self.enter_text(Locators.REG_FIRST_NAME, TestData.SIGN_UP_VALID_FIRST_NAME)147 # Type Last Name148 self.enter_text(Locators.REG_LAST_NAME, TestData.SIGN_UP_VALID_LAST_NAME)149 # Type Password150 self.enter_text(Locators.REG_PASSWORD, TestData.SIGN_UP_VALID_PASSWORD)151 # Select Date of Birth152 self.select_dropdown_by_value(Locators.REG_DROP_DAYS, TestData.DROP_DAYS_VALUE)153 self.select_dropdown_by_value(Locators.REG_DROP_MONTHS, TestData.DROP_MONTHS_VALUE)154 self.select_dropdown_by_value(Locators.REG_DROP_YEARS, TestData.DROP_YEARS_VALUE)155 # Type Company156 self.enter_text(Locators.REG_COMPANY, TestData.SIGN_UP_VALID_COMPANY)157 # Type Address158 self.enter_text(Locators.REG_ADDRESS1, TestData.SIGN_UP_VALID_ADDRESS)159 # Type City160 self.enter_text(Locators.REG_CITY, TestData.SIGN_UP_VALID_CITY)161 # Select State162 self.select_dropdown_by_visible_text(Locators.REG_STATE, TestData.SIGN_UP_VALID_STATE)163 # Type Post Code164 self.enter_text(Locators.REG_POSTAL_CODE, TestData.SIGN_UP_VALID_POSTAL_CODE)165 # Select Country166 self.select_dropdown_by_visible_text(Locators.REG_COUNTRY, TestData.SIGN_UP_VALID_COUNTRY)167 # Type Additional Info168 self.enter_text(Locators.REG_ADDITIONAL_INFO, TestData.SIGN_UP_VALID_ADDITIONAL_INFO)169 # Type Mobile Phone170 self.enter_text(Locators.REG_MOBILE_PHONE, TestData.SIGN_UP_VALID_MOBILE_PHONE)171 # Type Address Alias172 self.clear_text(Locators.REG_ADDRESS_ALIAS)173 self.enter_text(Locators.REG_ADDRESS_ALIAS, TestData.SIGN_UP_VALID_ADDRESS_ALIAS)174 # Click Register Button175 self.click(Locators.REG_SUBMIT_REGISTER)176 def register_failed(self):177 # Type Email178 self.enter_text(Locators.REG_EMAIL_FIELD, TestData.SIGN_UP_VALID_EMAIL)179 # Click Create an account button180 self.click(Locators.SUBMIT_CREATE_ACCOUNT)181 # Select Gender182 self.click(Locators.REG_RADIO_GENDER_1)183 # Type First Name184 self.enter_text(Locators.REG_FIRST_NAME, TestData.SIGN_UP_INVALID_FIRST_NAME)185 # Type Last Name186 self.enter_text(Locators.REG_LAST_NAME, TestData.SIGN_UP_INVALID_LAST_NAME)187 # Type Password188 self.enter_text(Locators.REG_PASSWORD, TestData.SIGN_UP_INVALID_PASSWORD)189 # Select Date of Birth190 self.select_dropdown_by_value(Locators.REG_DROP_DAYS, TestData.DROP_DAYS_INVALID_VALUE)191 self.select_dropdown_by_value(Locators.REG_DROP_MONTHS, TestData.DROP_MONTHS_INVALID_VALUE)192 self.select_dropdown_by_value(Locators.REG_DROP_YEARS, TestData.DROP_YEARS_INVALID_VALUE)193 # Type Company194 self.enter_text(Locators.REG_COMPANY, TestData.SIGN_UP_INVALID_COMPANY)195 # Type Address196 self.enter_text(Locators.REG_ADDRESS1, TestData.SIGN_UP_INVALID_ADDRESS)197 # Type City198 self.enter_text(Locators.REG_CITY, TestData.SIGN_UP_INVALID_CITY)199 # Select State200 self.select_dropdown_by_visible_text(Locators.REG_STATE, TestData.SIGN_UP_VALID_STATE)201 # Type Post Code202 self.enter_text(Locators.REG_POSTAL_CODE, TestData.SIGN_UP_INVALID_POSTAL_CODE)203 # Select Country204 self.select_dropdown_by_visible_text(Locators.REG_COUNTRY, TestData.SIGN_UP_VALID_COUNTRY)205 # Type Additional Info206 self.enter_text(Locators.REG_ADDITIONAL_INFO, TestData.SIGN_UP_INVALID_ADDITIONAL_INFO)207 # Type Mobile Phone208 self.enter_text(Locators.REG_MOBILE_PHONE, TestData.SIGN_UP_INVALID_MOBILE_PHONE)209 # Type Address Alias210 self.clear_text(Locators.REG_ADDRESS_ALIAS)211 self.enter_text(Locators.REG_ADDRESS_ALIAS, TestData.SIGN_UP_INVALID_ADDRESS_ALIAS)212 # Click Register Button213 self.click(Locators.REG_SUBMIT_REGISTER)214 def register_failed_already_registered(self):215 # Type Email216 self.enter_text(Locators.REG_EMAIL_FIELD, TestData.EMAIL_ALREADY_REGISTERED)217 # Click Create an account button218 self.click(Locators.SUBMIT_CREATE_ACCOUNT)219class MyAccountPage(BasePage):220 def reorder(self):221 # Click My Order222 self.click(Locators.MY_ORDER_BUTTON)223 # Click Reorder224 self.click(Locators.REORDER_BTN)225 # Click Proceed to Checkout226 self.click(Locators.PROCEED_TO_CHECKOUT_BTN_SUMMARY)227 # Click Proceed to Checkout228 self.click(Locators.PROCEED_TO_CHECKOUT_BTN_ADDRESS)229 # Click Checkbox Proceed to Checkout230 self.click(Locators.CHECKOUT_AGREE_CHECK)231 self.click(Locators.PROCEED_TO_CHECKOUT_BTN_SHIPPING)232 # Click Payment Type233 self.click(Locators.CHECKOUT_BY_CHECK)234 # Click Confirm Order235 self.click(Locators.CHECKOUT_CONFIRM_ORDER_BTN)236 # Wait for visible element237 self.is_visible(Locators.CHECKOUT_STATUS_BY_CHECK)238 def add_new_address(self):239 # Click My Address Button240 self.click(Locators.MY_ADDRESSES_BUTTON)241 # Click Add New Adress Button242 self.click(Locators.ADDRESS_ADD_NEW_BUTTON)243 # Type Address244 self.enter_text(Locators.ADDRESS_ADDRESS1_FIELD, TestData.NEW_ADDRESS_VALUE)245 # Type City246 self.enter_text(Locators.ADDRESS_CITY_FIELD, TestData.NEW_CITY_VALUE)247 # Select State248 self.select_dropdown_by_visible_text(Locators.ADDRESS_STATE_FIELD, TestData.NEW_STATE_VALUE)249 # Type Zip / Postal Code250 self.enter_text(Locators.ADDRESS_POSTCODE_FIELD, TestData.NEW_POST_CODE_VALUE)251 # Type Mobile Phone252 self.enter_text(Locators.ADDRESS_MOBILE_PHONE_FIELD, TestData.NEW_MOBILE_PHONE_VALUE)253 # Type New Additional Info254 self.enter_text(Locators.ADDRESS_ADDITIONAL_INFO, TestData.NEW_ADDITIONAL_INFO_VALUE)255 # Type Address Alias256 self.clear_text(Locators.ADDRESS_ALIAS_FIELD)257 self.enter_text(Locators.ADDRESS_ALIAS_FIELD, TestData.NEW_ADDRESS_ALIAS_VALUE)258 # Click Save Address259 self.click(Locators.ADDRESS_SAVE_BUTTON)260 # Wait for Status261 self.is_visible(Locators.ADDRESS_INFO)262 def remove_address(self):263 # Click My Address Button264 self.click(Locators.MY_ADDRESSES_BUTTON)265 # Click Delete Button266 self.alert_click(Locators.ADDRESS_DELETE_BUTTON)267 # Wait for268 self.is_visible(Locators.LOGO_URL)269 def remove_wishlist(self):270 # Hover to element271 self.move_element_to(Locators.PRODUCT_CARD)272 # Click More Button273 self.click(Locators.MORE_BUTTON)274 # Click Add to wishlist275 self.click(Locators.WISHLIST_BUTTON)276 # Click close button277 self.click(Locators.WISHLIST_CLOSE_BTN)278 # Click My Account (Account Name)279 self.click(Locators.MY_ACCOUNT)280 # Click My Wishlist281 self.click(Locators.MY_WISHLISTS_BUTTON)282 # Click Delete Wishlist Button283 self.alert_click(Locators.WISHLIST_DELETE_BTN)284 # Wait for...

Full Screen

Full Screen

test_uploadimgLabel.py

Source:test_uploadimgLabel.py Github

copy

Full Screen

...62 """63 判断标题是否存在64 :return:65 """66 self.alert_click(inspect.stack()[0][3])67 box_title = self.photo.financial[self.photo.bi.yaml_box_title()]68 box_title = self.photo.vac.is_visible_css_selectop(self.photo.driver, box_title)69 assert box_title, "%s---没有读取到标题" % (self.photo.FUNCTION_NAME)70 pass71 def test_survivalImg(self):72 """73 判断图片是否存在74 :return:75 """76 self.alert_click(inspect.stack()[0][3])77 photo = self.photo.financial[self.photo.bi.yaml_img()]78 photo = self.photo.vac.is_visible_id(self.photo.driver, photo)79 assert photo, "%s---没有找到图片" % (self.photo.FUNCTION_NAME)80 # photo = photo.get_attribute("src")81 pass82 def test_survivalSave(self):83 """84 判断按钮是否存在85 :return:86 """87 self.alert_click(inspect.stack()[0][3])88 img_save = self.photo.financial[self.photo.bi.yaml_img_save()]89 img_save = self.photo.vac.is_visible_id(self.photo.driver, img_save)90 assert img_save, "%s---提交按钮不见了" % (self.photo.FUNCTION_NAME)91 pass92 def alert_click(self, fun_name):93 """94 当提示flash没安装时,点击alert上面的确认按钮95 :param fun_name:96 :return:97 """98 dialog_box = self.photo.driver.switch_to_alert()99 dialog_box.accept()100 self.photo.setFunctionName(fun_name)101 self.photo.ti.dormancy_time(2)102if __name__ == '__main__':...

Full Screen

Full Screen

alerts_n_frames.py

Source:alerts_n_frames.py Github

copy

Full Screen

1from selenium import webdriver2from selenium.webdriver.common.by import By3import time45driver = webdriver.Firefox(executable_path=r"D:\Next\Automation\Drivers\geckodriver.exe")6url = "https://softwaretestingbootcamp.blogspot.com/p/automation.html"7driver.get(url)8driver.maximize_window()9#driver.implicitly_wait(30)10time.sleep(10)11alert_click = driver.find_element_by_xpath("//button[@onclick='myFunction()']").click()12time.sleep(5)13driver.switch_to_alert().accept()14time.sleep(5)15#driver.quit()16driver.get("https://softwaretestingbootcamp.blogspot.com/p/automation-testing-model.html")17xpath = "/html/body/div[1]/div/div/main/div/div[1]/div/div/div/div[2]/div[2]/div/div/table/tbody/tr/td/button"18driver.find_element_by_xpath(xpath).click()19time.sleep(5)20driver.find_element_by_xpath("/html/body/div[1]/div/div/main/div/div[1]/div/div/div/div[2]/div[2]/div/div/table/tbody/tr/td/div/form/div/div/button[1]").click()21time.sleep(5)22driver.quit()2324 ...

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 Airtest 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