def choose_theme(self, number): """ Choose theme by number [1..4] :param number: Ordinal number of shown themes :type number: int [1..4] """ self.log.info( "Execute method choose_theme with parameter number={}".format( number)) wait_until(lambda: check_if_elem_exist(self.btnChangeTheme), timeout=10) scroll_element_to_center(self.driver, self.log, self.btnChangeTheme()) time.sleep(3) self.btnChangeTheme().click() wait_until( lambda: check_if_elem_exist(lambda: self.imgThemeToSelect(number)), timeout=30) newTheme = self.imgThemeToSelect(number) themeSrc = newTheme.find_element_by_tag_name("img").get_attribute( "src") newTheme.click() wait_until(lambda: "selected" in self.imgThemeToSelect(number). get_attribute("class"), timeout=5) self.log.screenshot("Theme is selected") self.btnSelectTheme().click() wait_until( lambda: self.btnChangeTheme().get_attribute("src") == themeSrc, timeout=20) self.log.screenshot("Theme is updated")
def log_in(self, username, password): wait_until(lambda: check_if_elem_exist(self.inpUsename), timeout=120) send_text(self.inpUsename(), username) send_text(self.inpPassword(), password) self.btnLogIn().click() wait_until(lambda: check_if_elem_exist( lambda: self.driver.find_element_by_id("header-navigation")))
def set_download_image(self, upload=False): self.log.info("Execute method set_download_image") found = False firstTry = True while (not found): self.aDownloadImage().click() self.log.screenshot("kliknuto") #self.aUploadImage().click() #self.btnSelectFiles().click() #upload_scenes_windows(self.driver, DriverData.driverName, self.log, r"C:\Users\radlo\PycharmProjects\FromGitTemasek\Images\temasekproperties", "Webpr") if firstTry: self.select_first_image() time.sleep(2) self.log.screenshot("selektovan prvi") wait_until(lambda: check_if_elem_exist( lambda: self.driver.find_element_by_css_selector( "span[class='spinner']")), timeout=180) self.log.screenshot("Images are shown") self.btnSetDownloadImage().click() try: wait_until(lambda: check_if_elem_exist( lambda: self.driver.find_element_by_css_selector( "img[class='attachment-post-thumbnail size-post-thumbnail']" )), timeout=600) print("Pronasao") found = True except Exception as ex: pass firstTry = False
def view_edit_tour(self): """ Click on view edit tour """ self.log.info("Go to view/edit tour") wait_until(lambda: check_if_elem_exist(self.btnViewEditTour), timeout=30) # self.driver.execute_script("arguments[0].scrollIntoView();", self.btnViewEditTour()) # time.sleep(5) # self.btnViewEditTour().click() self.driver.execute_script("arguments[0].click();", self.btnViewEditTour()) wait_until(lambda: not check_if_elem_exist(self.btnViewEditTour), timeout=30)
def create_new_tour(self): """ Click on create new tour """ self.log.info("Execute method create_new_tour") wait_until(lambda: check_if_elem_exist(self.btnCreateNewTour), timeout=30) scroll_element_to_center(self.driver, self.log, self.btnCreateNewTour()) wait_until(lambda: check_if_elem_exist(self.btnCreateNewTour)) time.sleep(5) self.btnCreateNewTour().click() self.log.info("Create new tour button clicked") wait_until(lambda: check_if_elem_exist(BasicInformationTour(self.driver).inpTitle), timeout=30, errorMessage="Create new tour not opened")
def choose_floor(self, floor): try: time.sleep(5) wait_until(lambda: check_if_elem_exist(self.btnFloor), timeout=60) self.btnFloor().click() wait_until(lambda: check_if_elem_exist(self.ddlistFloor), timeout=10) self.lstFloor().find_element_by_css_selector( "div[data-index='{}']".format(floor - 1)).click() wait_until(lambda: not check_if_elem_exist(self.ddlistFloor), timeout=10) return True except Exception as ex: return False
def delete_uploaded_scene(self, title): """ Delete uploaded scenes with title. :param title: Title of scene to delete :type title: str """ self.log.info( "Execute method delete_uploaded_scene with parameter={}".format( title)) numberOfScenesBeforeDelete = len(self.get_uploaded_scenes()) uploadedScenes = self.driver.find_elements_by_css_selector( "div[class^='scence-image col-lg-12']") foundScene = False for scene in uploadedScenes: current_title = scene.find_element_by_css_selector( "input[id*='scence-title']").get_attribute("value") if current_title == title: self.log.info("Delete scene with title={}".format(title)) scroll_element_to_center( self.driver, self.log, scene.find_element_by_css_selector( "div[class='icon-delete']")) scene.find_element_by_css_selector( "div[class='icon-delete']").click() wait_until(lambda: check_if_elem_exist(self.btnDeleteSceneOk), timeout=10) wait_until(expected_conditions.alert_is_present, timeout=10) self.btnDeleteSceneOk() self.btnDeleteSceneOk().click() try: wait_until( lambda: not check_if_elem_exist(self.btnDeleteSceneOk), timeout=10) except Exception as ex: self.btnDeleteSceneOk().click() wait_until( lambda: numberOfScenesBeforeDelete - 1 == len( self.get_uploaded_scenes()), 30) wait_until(lambda: check_if_elem_exist( UploadScenesTour(self.driver).btnUpload), timeout=30, period=2) self.log.screenshot("Scene {} deleted".format(title)) foundScene = True break if not foundScene: raise Exception("Scene with title {} not found".format(title))
def open_menu_hotSpotOrInfo_on_view(self): """ Open menu of button in center of tour """ time.sleep(5) hotSpotFound = None for hotSpot in get_hotSpots(self.log, self.driver): try: hotSpotLocation = hotSpot.get_attribute("style") translate = hotSpotLocation.split("translate(")[1].split( "px")[0] hotSpotLocationWidth = int(translate.split(".")[0]) size = hotSpot.size tourSceneSize = self.tourImage().size["width"] self.log.info( "Check if hotspot with x location={} is on view={}".format( hotSpotLocationWidth, tourSceneSize)) limit = 50 if hotSpotLocationWidth >= 0 and hotSpotLocationWidth <= tourSceneSize: self.log.screenshot("Hotspot is on view") hotSpotFound = hotSpot hotSpot.click() except Exception as ex: self.log.info(str(ex)) if hotSpotFound is None: raise Exception("HotSpot is not in center") wait_until(lambda: check_if_elem_exist(self.btnDeleteHotSpot), timeout=10) self.log.screenshot("Clicked on hotspot")
def play(self): self.driver.switch_to.frame(self.driver.find_element_by_id("frame_me")) time.sleep(5) wait_until(lambda: check_if_elem_exist(lambda: self.driver. find_element_by_css_selector( "a[id='button-play']")), timeout=60) interractable = True while (interractable): try: self.aPlay().click() interractable = False except Exception as ex: #print(str(ex)) if "element not interactable" in str(ex): pass interractable = False # ac = ActionChains(self.driver) # ac.click(self.aPlay()) # ac.perform() #self.driver.execute_script("arguments[0].click();", self.aPlay()) wait_until(lambda: "display: none;" in self.driver.find_element_by_id( "gui-loading").get_attribute("style"), timeout=60) time.sleep(20) self.driver.find_element_by_tag_name("body").click()
def insert_scenes_title(self, scenes): """ Insert scene title and click on next button. :param scenes: For given list of scenes go through each and insert title :type scenes: list[Scene] """ self.log.info( "Execute method insert_scenes_title with parameter scenes={}". format(''.join(scenes.__repr__()))) foundScenes = self.driver.find_elements_by_css_selector( "div[class*='scence-image ']") for picture in scenes: for scene in foundScenes: if scene.find_element_by_tag_name( "p").text == picture.fileName: #inputTitle = scene.find_element_by_id("scence-title") inputTitle = scene.find_element_by_css_selector( "input[id*='scence-title']") inputTitle.send_keys(picture.title) time.sleep(1) break time.sleep(1) self.btnNext().click() wait_until(lambda: check_if_elem_exist( ConnectScenesTour(self.driver).btnHotSpot), timeout=30, period=2) self.log.screenshot("Button next executed")
def open_menu_hotSpotOrInfo_center(self): """ Open menu of button in center of tour """ time.sleep(5) self.get_hotspot_from_center().click() wait_until(lambda: check_if_elem_exist(self.btnDeleteHotSpot), timeout=10) self.log.screenshot("Clicked on hotspot")
def wait_scene_load(self): """ When scene is chosen wait for it to load """ self.driver.set_page_load_timeout(30) time.sleep(3) wait_until(lambda: check_if_elem_exist( lambda: self.driver.find_element_by_class_name( "pnlm-render-container").find_element_by_tag_name("canvas")), timeout=60) wait_until(lambda: check_if_elem_exist( lambda: self.driver.find_element_by_css_selector( "div[class='pnlm-load-box']")), timeout=30) wait_until( lambda: "inline" not in self.driver.find_element_by_css_selector( "div[class='pnlm-load-box']").get_attribute('style'), timeout=60)
def rotate(self, right, clickNumber, useArrows): """ Rotate scene to right or left clickNumber of times. :param right: True for moving to right, False for moving to left :type right: bool :param clickNumber: Number of times to click on arrow :type clickNumber: int """ wait_until(self.btnLeftRotate) self.log.info( "Execute method rotate with parameters right={}, clickNumber={}". format(right, clickNumber)) if clickNumber != 0: if not useArrows: if DriverData.driverName == "Chrome" and DriverData.mobile is False: for i in range(clickNumber): time.sleep(5) # move_to_element_chrome(self.driver, self.tourImage(), 100) pyautogui.mouseDown() #moveFor = int(int(self.tourImage().size["width"]) / 58) moveFor = int(int(self.tourImage().size["width"]) / 8) if right: pyautogui.moveRel(moveFor * -1, 0, 1) else: pyautogui.moveRel(moveFor, 0, 1) pyautogui.mouseUp() time.sleep(5) else: for i in range(clickNumber): time.sleep(5) ac = ActionChains(self.driver) ac.move_to_element(self.tourImage()) ac.click_and_hold() #moveFor = int(int(self.tourImage().size["width"])/58) moveFor = int(int(self.tourImage().size["width"]) / 8) if right: ac.move_by_offset(moveFor * -1, 0) else: ac.move_by_offset(moveFor, 0) ac.release() ac.perform() time.sleep(5) else: if right: button = self.btnRighRotate else: button = self.btnLeftRotate for i in range(clickNumber): time.sleep(1.5) wait_until(lambda: check_if_elem_exist(button), timeout=10) button().click() time.sleep(1.5) self.log.screenshot("Rotate is done")
def open_basic_panotour(self): """ Click on button Select for membership Trial with 1 Panotour. """ self.log.info("Execute method open_basic_panotour") wait_until(lambda: check_if_elem_exist(self.btnBasicPanotour), timeout=20) if not self.btnBasicPanotour().is_displayed(): self.btnBasicPanotourMobile().click() else: self.btnBasicPanotour().click() self.is_opened_right_page("Basic")
def check_if_exist(self, listingName, bookDate): wait_until(lambda: check_if_elem_exist(self.tblBooked)) all_booked = self.tblBooked().find_element_by_tag_name( "tbody").find_elements_by_tag_name("tr") for booked in all_booked: sections = booked.find_elements_by_tag_name("td") if bookDate in sections[0].text and listingName in sections[1].text: self.log.screenshot("Exists") return True self.log.screenshot("Does not exist!!!") return False
def sign_up(self, firstName, lastname, CEA, mobile): self.log.info("Execute method sign_up with parameters" " firstName={}, lastName={}, CEA={}, mobile={}".format( firstName, lastname, CEA, mobile)) send_text(self.inpFirstName(), firstName) send_text(self.inpLastName(), lastname) send_text(self.inpCEA(), CEA) send_text(self.inpMobileNumber(), mobile) self.log.screenshot("Entered info") self.btnNext().click() wait_until(lambda: not check_if_elem_exist(self.inpFirstName))
def go_to_listings(self): wait_until(lambda: check_if_elem_exist( lambda: self.driver.find_element_by_css_selector( "nav[id='header-navigation']"))) if DriverData.mobile: self.spnExpandMenu().click() start_elem = self.driver.find_element_by_css_selector( "nav[class='sh-header-mobile-dropdown']") else: start_elem = self.driver.find_element_by_id("header-navigation") start_elem.find_elements_by_css_selector( "a[href='https://temasekproperties.com/listings/']")[0].click()
def wait_scenes_uploaded(self, timeout): """ Wait for scenes to be uploaded. :param timeout: Maximum timeout to wait for uploading scenes :type timeout: int """ self.log.info("Execute method wait_scenes_uploaded with parameters" " timeout={}".format(timeout)) wait_until( lambda: check_if_elem_exist(lambda: self.driver. find_element_by_css_selector( "h3[id='toplimit']")), timeout)
def remove_tour_by_name(self, name): """ Remove scene with name. If there is multiple tours with same name, first tour will be removed. :param name: Name of tour :type name: str """ self.log.info( "Execute method remove_tour_by_name with parameter name={}".format( name)) scenesNumber = self.get_number_of_scenes() scene = self.find_scene_by_name(name) if scene: self.log.info("Click on delete button") time.sleep(3) scene.find_element_by_css_selector( "a[class='scene_remove']").find_element_by_tag_name( "i").click() wait_until(lambda: check_if_elem_exist(self.btnDeleteOk), timeout=30) try: self.btnDeleteOk().click() if not scenesNumber == 1: wait_until( lambda: self.get_number_of_scenes() + 1 == scenesNumber, 10) else: wait_until(lambda: check_if_elem_exist( BasicInformationTour(self.driver).inpTitle), timeout=30) except: self.btnDeleteOk().click() wait_until( lambda: self.get_number_of_scenes() + 1 == scenesNumber, 10) self.log.screenshot("Scene is deleted")
def pay_pal(self, payPalEmail, payPalPassword, timeout): self.wait_paypal_opened(timeout) self.log.info("Add PayPal credentials") time.sleep(5) wait_until(lambda: check_if_elem_exist(self.btnLogInPayPal), timeout=timeout) self.btnLogInPayPal().click() wait_until(lambda: check_if_elem_exist(self.inpPayPalEmail), timeout=timeout) wait_until(lambda: check_if_elem_exist(self.btnContinuePayPal), timeout=timeout) send_text(self.inpPayPalEmail(), payPalEmail, mode="update") self.log.screenshot("Credentials for PayPal are entered") self.log.info("Click on continue") self.btnContinuePayPal().click() time.sleep(5) wait_until(lambda: check_if_elem_exist(self.inpPayPalPass), timeout=timeout) send_text(self.inpPayPalPass(), payPalPassword, mode="update") # wait_until(lambda: click_on_element_intercepted(self.btnContinuePayPal), timeout=timeout) # wait_until(lambda: check_if_elem_exist(self.btnPayNow), timeout=timeout) self.log.screenshot("Click on pay now") self.btnLogInPayPal2().click() self.log.screenshot("Paid")
def go_to_log_in(self): """ Click on log in """ self.log.info("Go to log in page") if not self.btnLogIn().is_displayed(): time.sleep(2) self.btnOpenMenu().click() wait_until(lambda: check_if_elem_exist(self.btnLogInMobile), timeout=20) scroll_element_to_center(self.driver, self.log, self.btnLogInMobile()) self.btnLogInMobile().click() else: self.btnLogIn().click() time.sleep(1)
def set_basic_info(self, title, address, description, watermark="", publicAccess=True, mode="set"): """ Insert basic info for creating new tour :param title: Title of tour :type title: str :param address: Tour address :type address: str :param description: Tour description :type description: str :param watermark: Watermark :type watermark: str :param publicAccess: Choose radio button for public access :type publicAccess: bool :param mode: Possible values are set or update :type mode: str """ self.log.info( "Execute method set_basic_info with parameters title={}, address={}, description={}," " watermark={}, publicAccess={}, mode={}".format( title, address, description, watermark, publicAccess, mode)) if title: wait_until(lambda: check_if_elem_exist(self.inpTitle), timeout=30) send_text(self.inpTitle(), title, mode=mode) if address: send_text(self.inpAddress(), address, mode=mode) if watermark: send_text(self.inpWatermarkText(), watermark, mode="update") if publicAccess: self.rbtnPublicAccess("Yes").click() else: self.rbtnPublicAccess("No").click() if description: send_text(self.txtDescription(), description, mode=mode) self.log.screenshot("Data entered. Click on button submit") self.btnSubmit().click() wait = WebDriverWait(self.driver, 60) wait.until( expected_conditions.visibility_of_element_located( (By.CSS_SELECTOR, "div[class*='qq-upload-button']"))) self.log.info("Submit done")
def purchase_listing(self, payment, email, firstName, lastName, payPalEmail, payPalPassword): self.log.info("Execute method purchase_listing") time.sleep(5) wait_page_load(self.driver) wait_until(lambda: check_if_elem_exist( lambda: self.driver.find_element_by_css_selector( "div[class='edd_price_options edd_single_mode']"))) #formElement = self.driver.find_element_by_css_selector("form[id='edd_purchase_9273']") #edd_download_purchase_form edd_purchase_9273 formElement = self.driver.find_element_by_css_selector( "div[class='edd_price_options edd_single_mode']") purchases = formElement.find_elements_by_css_selector( "span[class='edd_price_option_name']") for purchase in purchases: if purchase.text == payment: purchase.find_element_by_xpath('..').click() time.sleep(1) self.log.screenshot("Selected payment={}".format(payment)) break self.aPurchase().click() time.sleep(5) self.aCheckout().click() send_text(self.inpEmail(), email, mode="update") send_text(self.inpFirstName(), firstName, mode="update") send_text(self.inpLastName(), lastName, mode="update") self.log.screenshot("Inserted email, firstname, lastname") self.btnFinalPurchase().click() wait_until(lambda: check_if_elem_exist(self.btnPayPal), 30) time.sleep(10) self.btnPayPal().click() wait_until(lambda: check_if_elem_exist( lambda: self.driver.find_element_by_id("payment_type_paypal")), timeout=60) self.driver.find_element_by_id("payment_type_paypal").click() self.driver.find_element_by_css_selector( "input[name='unified_login.x']").click() #paypal window is opened self.log.info("Add PayPal credentials") wait_until(lambda: check_if_elem_exist(self.inpPayPalEmail), timeout=60) send_text(self.inpPayPalEmail(), payPalEmail, mode="update") send_text(self.inpPayPalPass(), payPalPassword, mode="update") self.log.screenshot("Credentials for PayPal are entered") self.btnLogInPayPal().click() wait_until(lambda: check_if_elem_exist(lambda: self.driver. find_element_by_css_selector( "input[name='submit.x']"))) self.driver.find_element_by_css_selector( "input[name='submit.x']").click() wait_until(lambda: check_if_elem_exist( lambda: self.driver.find_element_by_xpath( "//h1[contains(text(),'{}')]".format( "Your purchase was successful")))) self.log.screenshot("Listing purchased")
def log_in(self, username, password): """ Insert log in parameters and click on log in :param username: :param password: """ self.log.info("Execute method log_in with parameters: {}, {}".format( username, password)) wait_until(lambda: check_if_elem_exist(self.inpUsername), timeout=20) wait_until(lambda: self.inpUsername().is_displayed, timeout=20) time.sleep(3) self.inpUsername().send_keys(username) self.inpPassword().send_keys(password) self.log.info("Click on log in button") self.btnLogIn().click() time.sleep(2)
def go_to_resources_booking(self): if DriverData.mobile: self.spnExpandMenu().click() start_elem = self.driver.find_element_by_css_selector( "ul[class='sh-nav-mobile']") else: start_elem = self.driver.find_element_by_id( "header-navigation") # for mobile: header-navigation-mobile start_elem.find_element_by_id("menu-item-9408").click() time.sleep(2) wait_until( lambda: "block" in start_elem.find_element_by_id("menu-item-9408"). find_element_by_tag_name("ul").get_attribute("style")) start_elem.find_element_by_id("menu-item-9409").click() time.sleep(3) wait_until(lambda: check_if_elem_exist( lambda: self.driver.find_element_by_css_selector( "div[class='bookly-progress-tracker bookly-table']"))) # wait_until(lambda: "none" in self.driver.find_element_by_id("DataTables_Table_0_processing").get_attribute("style")) self.log.screenshot("resource booking opened")
def go_to_resources_booked(self): if DriverData.mobile: self.spnExpandMenu().click() start_elem = self.driver.find_element_by_id( "header-navigation-mobile") else: start_elem = self.driver.find_element_by_id( "header-navigation") # for mobile: header-navigation-mobile start_elem.find_element_by_id("menu-item-9408").click() time.sleep(2) wait_until(lambda: "block" in self.driver.find_element_by_id( "header-navigation").find_element_by_id("menu-item-9408"). find_element_by_tag_name("ul").get_attribute("style")) self.driver.find_element_by_id("header-navigation").find_element_by_id( "menu-item-9434").click() time.sleep(3) wait_until( lambda: check_if_elem_exist(lambda: self.driver.find_element_by_id( "DataTables_Table_0_processing"))) wait_until(lambda: "none" in self.driver.find_element_by_id( "DataTables_Table_0_processing").get_attribute("style")) self.log.screenshot("resource booked opened")
def log_in_social_media(self, email, password): """ Log in with facebook account :param email: Email :param password: Password """ self.log.info( "Execute method log_in_social_media with parameters email={}, password={}" .format(email, password)) self.cbxSocialID().click() time.sleep(1) self.btnLoginWithFacebook().click() wait_until(lambda: len(self.driver.window_handles) == 2, timeout=10) self.driver.switch_to.window(self.driver.window_handles[-1]) wait_until(lambda: check_if_elem_exist(self.inpFacebookEmail), timeout=30) self.log.info("Facebook login page opened") send_text(self.inpFacebookEmail(), email, mode="update") send_text(self.inpFacebookPass(), password, mode="update") self.btnLogInToFacebook().click() time.sleep(10) self.log.screenshot("Should be logged on facebook")
def booking_steps(self): if DriverData.mobile: self.driver.find_element_by_css_selector( "button[class='bookly-right bookly-mobile-next-step bookly-js-mobile-next-step bookly-btn bookly-none ladda-button']" ).click() else: self.btnNext().click() wait_until(lambda: check_if_elem_exist(lambda: self.driver. find_element_by_css_selector( "div[class='bookly-box']"))) wait_until(lambda: "Below you can find a list of available time slots" in self.driver.find_element_by_css_selector( "div[class='bookly-box']").text) self.log.screenshot("Opened 'Time'") if not DriverData.mobile: self.driver.find_element_by_css_selector("div[class='bookly-column bookly-js-first-column']")\ .find_element_by_css_selector("button[class='bookly-hour']").click() else: self.driver.find_element_by_css_selector( "button[class='bookly-next-step bookly-js-next-step bookly-btn ladda-button']" ) #wait_until(lambda: "Details" in self.active_booking_step()) wait_until(lambda: self.active_booking_step("Details")) self.log.screenshot("'Details' opened") booking = self.driver.find_element_by_css_selector( "div[class='bookly-box']").find_elements_by_tag_name("b") bookDate = booking[3].text bookTime = booking[2].text bookedFor = bookDate + " " + bookTime self.driver.find_element_by_css_selector( "button[class='bookly-next-step bookly-js-next-step bookly-btn ladda-button']" ).click() #wait_until(lambda: "Done" in self.active_booking_step()) wait_until(lambda: self.active_booking_step("Done")) self.log.screenshot("Booking is done") self.log.info("booked for {}".format(bookedFor)) return bookedFor
def btnDeleteHotSpot(self): wait_until(lambda: check_if_elem_exist(self.divHotSpotMenu), timeout=10) return self.divHotSpotMenu().find_element_by_css_selector( "a[id*='hotSpotDelete']")
createDriver = DriverData() driver = createDriver.get_driver() driver.get("https://sgpano.com/") hp = HomePage(driver) time.sleep(2) hp.go_to_log_in() time.sleep(2) lp = LogIn(driver) lp.log_in(cl.get("usernameTrial"), cl.get("passwordTrial")) db = Dashboard(driver) time.sleep(5) db.view_edit_tour() es = EditScenes(driver) es.edit_tour(cl.get("tourName")) bi = BasicInformationTour(driver) wait_until(lambda: check_if_elem_exist(bi.btnSubmit), timeout=10) bi.btnSubmit().click() uss = UploadedScenesTour(driver) wait_until(lambda: check_if_elem_exist(uss.btnNext), timeout=10) uss.btnNext().click() csp = ConnectScenesTour(driver) csp.choose_theme(3) csp.insert_hotSpots(scenes) csp.publish()