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 open_scene(self, name): """ Change current scene to scene with name=name :param name: Name of scene to open :type name: str """ cst = ConnectScenesTour(self.driver) cst.wait_scene_load() self.log.info( "Execute method open_scene with parameter={}".format(name)) try: wait_until(lambda: not self.paneGallery().is_displayed, timeout=10) except Exception as ex: pass if not self.driver.find_element_by_css_selector( "div[id='gallerypane']").is_displayed(): self.log.info("Click on button show all scenes") #self.btnShowAllScenes().click() self.driver.execute_script("arguments[0].click();", self.btnShowAllScenes()) time.sleep(2) wait_until(lambda: self.paneGallery().is_displayed, timeout=30) self.log.screenshot("Gallery is displayed") self.driver.find_element_by_xpath( "//h5[contains(text(),'{}')]".format(name)).click() cst.wait_scene_load() cst.rotate(True, 1, True) cst.rotate(False, 1, True) #self.tourImage().click() self.btnShowAllScenes().click()
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 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 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 wait_page_load(driver): """ Wait page to load """ wait_until(lambda: driver.execute_script("return document.readyState;") == "complete", timeout=30)
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 select_first_image(self): wait_until(lambda: len( self.driver.find_elements_by_css_selector( "div[class='attachment-preview js--select-attachment type-image subtype-gif landscape']" )) > 0) self.driver.find_elements_by_css_selector( "div[class='attachment-preview js--select-attachment type-image subtype-gif landscape']" )[0].click()
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 is_opened_right_page(self, membership): """ Check whether right page is opened :param membership: Trial, Basic... :type membership: str """ wait_until(lambda: membership in self.driver.find_element_by_css_selector("div[class='pmpro_checkout-fields']").text, timeout=30, errorMessage="Not right page opened") self.log.info("Page for memebership {} is opened".format(membership))
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 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 add_button_to_center(self, hotSpot=True): time.sleep(1) wait_until(lambda: "none" in self.driver.find_element_by_id( "themeLabelHide").get_attribute("style"), timeout=30) if DriverData.driverName == "Firefox": self._add_button_to_center_firefox(hotSpot) elif DriverData.driverName == "Chrome": self._add_button_to_center_chrome(hotSpot) elif DriverData.driverName == "Safari": self._add_button_to_center_safari(hotSpot)
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 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 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 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 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 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 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 sign_up_trial(self, username, password, mail, timeout=30): """ Input credentials and sign up :param username: Username :param password: Password :param mail: Email :param timeout: Timeout to wait, after submit, for new page to open """ self.log.info("Execute method _input_signup_info with parameters username={}, password={}, " "mail={}, timeout={}".format(username, password, mail, timeout)) self._input_signup_info(username, password, mail) self.log.info("Click on submit") self.btnSubmit().click() wait_until(lambda: self.driver.find_element_by_css_selector("div[class='titlebar-title sh-table-cell']").find_element_by_tag_name("h2") .text == "Membership Confirmation", timeout=timeout, period=2, errorMessage="Problem with sign up. Check log screenshots") self.log.screenshot("Sign up is successful")
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 check_number_of_uploaded_scenes(self, numberBeforeUpload, numberToUpload): """ Checks if number of uploaded scenes before uploading new scenes are increased by numberToUpload. Raise exception if scenes number=numberToUpload is not uploaded. :param numberBeforeUpload: Number of uploaded scenes before upload :type numberBeforeUpload: int :param numberToUpload: Uploaded scenes :type numberToUpload: int """ self.log.info( "Execute method check_number_of_uploaded_scenes with parameters " "numberBeforeUpload={}, numberToUpload={}".format( numberBeforeUpload, numberToUpload)) wait_until( lambda: numberBeforeUpload + numberToUpload == self. get_number_uploaded_scenes(), 30, errorMessage="Number of files that should be loaded={} are not the " "same as actual uploaded scenes".format(numberToUpload))
def view_tour_by_name(self, name): """ Click on view for tour with name. :param name: Name of tour to view :type name: str """ self.log.info( "Execute method view_tour_by_name with parameter name={}".format( name)) scene = self.find_scene_by_name(name) if DriverData.DriverData.mobile: link = scene.find_element_by_css_selector( "a[title='View']").get_attribute("href") self.driver.get(link) else: tab_number_before = len(self.driver.window_handles) self.log.info( "Number of tabs currently open={}".format(tab_number_before)) if scene: scene.find_element_by_css_selector( "a[title='View']").find_element_by_tag_name("i").click() self.log.info("Check if view is opened in new tab") wait_until( lambda: len(self.driver.window_handles) == tab_number_before + 1, 30) self.log.info("View is opened in new tab") for handle in self.driver.window_handles: self.driver.switch_to.window(handle) try: wait_until( lambda: name in self.driver.title, timeout=10, errorMessage= "Wrong tour is opened= {}. Tour= {} should be opened". format(self.driver.title, name)) break except: pass self.driver.refresh()
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 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