def videoCard(self, videoPath, timeToUploadVideo): print "Click on (+) icon" driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div/span" ).click() #Clicking on Video card driver.find_element_by_xpath( "html/body/div/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[3]/div[1]" ).click() #Uploading Video print "Uploading Video" driver.find_element_by_css_selector('input[type="file"]').send_keys( videoPath) WebDriverWait(driver, timeToUploadVideo).until( EC.visibility_of_element_located(( By.XPATH, "html/body/div[1]/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/button" ))) videoContainerlocator_afterupload = driver.find_element_by_xpath( "html/body/div[1]/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/button" ) if (videoContainerlocator_afterupload.is_displayed()): print "Successfully uploaded the Video file" else: print "Failed to upload the Video file" raise Exception
def docCard(self, documentPath): print "Document" print "Click on (+) icon" driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div/span" ).click() #Clicking on Document card driver.find_element_by_xpath( "html/body/div/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[4]/div[1]/div" ).click() #Uploading Document print "Uploading Document" driver.find_element_by_css_selector('input[type="file"]').send_keys( documentPath) WebDriverWait(driver, 150).until( EC.visibility_of_element_located(( By.XPATH, ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[2]/div/label" ))) documentContainerlocator_afterupload = driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[2]/div/label" ) if (documentContainerlocator_afterupload.is_displayed()): print "Successfully uploaded the Video file" else: print "Failed to upload the Document file" raise Exception
def imageCard(self, Imagefilepath1): print "\nUploading Image" wait = WebDriverWait(driver, 60) print "Click on (+) icon" driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div/span" ).click() #Clicking on Image card driver.find_element_by_xpath( "html/body/div/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[2]/div[1]" ).click() #Uploading image driver.find_element_by_css_selector('input[type="file"]').send_keys( Imagefilepath1) wait.until( EC.visibility_of_element_located(( By.XPATH, ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img" ))) imageContainerlocator_after1upload = driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img" ) if (imageContainerlocator_after1upload.is_displayed()): print 'Successfully uploaded the image1 file' else: print "Failed to upload the image1 file" raise Exception
def addVideoCardforedit(self,time): wait=WebDriverWait(driver, time) wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div"))) driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div").click() print "Clicking on Add card + icon" driver.find_element_by_xpath("html/body/div/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[3]/div[1]").click() book=xlrd.open_workbook(os.path.join('TestData.xlsx')) first_sheet = book.sheet_by_name('MultiCardLesson') cell7= first_sheet.cell(1,8) videoName = cell7.value #Uploading Video print "Uploading Video" driver.find_element_by_css_selector('input[type="file"]').send_keys(videoName) wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div[1]/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/button"))) videoContainerlocator_afterupload= driver.find_element_by_xpath("html/body/div[1]/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/button") if(videoContainerlocator_afterupload.is_displayed()): print 'Successfully uploaded the Video file' else: print "Failed to upload the Video file" raise Exception driver.find_element_by_xpath("html/body/div[1]/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/button").click() wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div")))
def addDocumentCardforedit(self,time): wait=WebDriverWait(driver, time) driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div").click() print "Clicking on Add card + icon" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[4]/div[1]/div").click() print "Selecting the Document card" book=xlrd.open_workbook(os.path.join('TestData.xlsx')) first_sheet = book.sheet_by_name('MultiCardLesson') cell8= first_sheet.cell(1,9) document1Path = cell8.value driver.find_element_by_css_selector('input[type="file"]').send_keys(document1Path) print "Uploading document file" #wait till minimize button is displayed wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/div[1]/button[1]"))) downloadButtonLocator= driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[2]/div/div/div[1]/div/a") if (downloadButtonLocator.is_displayed()): print "The file has been uploaded successfully" else: print "Failed to upload the file" raise Exception
def addDocumentCard(self, document1Path, time): wait = WebDriverWait(driver, time) driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div" ).click() print "Clicking on Add card + icon" driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[4]/div[1]/div" ).click() print "Selecting the Document card" driver.find_element_by_css_selector('input[type="file"]').send_keys( document1Path) print "Uploading document file" #wait till minimize button is displayed wait.until( EC.visibility_of_element_located(( By.XPATH, ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/div[1]/button[1]" ))) downloadButtonLocator = driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[2]/div/div/div[1]/div/a") if (downloadButtonLocator.is_displayed()): print "The file has been uploaded successfully" else: print "Failed to upload the file" raise Exception
def addImageCardforedit(self,time): wait=WebDriverWait(driver, time) driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div").click() print "Clicking on Add card + icon" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[2]/div[1]/div").click() print "Image card selected" wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div/div[1]/h4/div[1]/span[2]/div"))) #driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div/div[1]/h4/div[1]/span[2]/div").click() #print "Clicking on browse for your file link" wait.until(EC.visibility_of_element_located((By.XPATH,"//span[@class='lesson-editor-status' and .='Saving...']"))) wait.until(EC.visibility_of_element_located((By.XPATH,"//span[@class='lesson-editor-status' and .='Saved']"))) book=xlrd.open_workbook(os.path.join('TestData.xlsx')) first_sheet = book.sheet_by_name('MultiCardLesson') cell6= first_sheet.cell(1,5) Imagefilepath1 = cell6.value print "Going to upload the image file" driver.find_element_by_css_selector('input[type="file"]').send_keys(Imagefilepath1) wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img"))) imageContainerlocator_after1upload= driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img") if(imageContainerlocator_after1upload.is_displayed()): print 'Successfully uploaded the image1 file' else: print "Failed to upload the image1 file" raise Exception
def addVideoCard(self, videoName, time): wait = WebDriverWait(driver, time) wait.until( EC.visibility_of_element_located(( By.XPATH, ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div" ))) driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div" ).click() print "Clicking on Add card + icon" driver.find_element_by_xpath( "html/body/div/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[3]/div[1]" ).click() #Uploading Video print "Uploading Video" driver.find_element_by_css_selector('input[type="file"]').send_keys( videoName) wait.until( EC.visibility_of_element_located(( By.XPATH, "html/body/div[1]/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/button" ))) videoContainerlocator_afterupload = driver.find_element_by_xpath( "html/body/div[1]/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/button" ) if (videoContainerlocator_afterupload.is_displayed()): print 'Successfully uploaded the Video file' else: print "Failed to upload the Video file" raise Exception driver.find_element_by_xpath( "html/body/div[1]/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/button" ).click() wait.until( EC.visibility_of_element_located(( By.XPATH, ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div" )))
def addImageCard(self, Imagefilepath1, linkname, Imagefilepath2, time): wait = WebDriverWait(driver, time) driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div" ).click() print "Clicking on Add card + icon" driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[2]/div[1]/div" ).click() print "Image card selected" wait.until( EC.visibility_of_element_located(( By.XPATH, ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div/div[1]/h4/div[1]/span[2]/div" ))) #driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div/div[1]/h4/div[1]/span[2]/div").click() #print "Clicking on browse for your file link" wait.until( EC.visibility_of_element_located( (By.XPATH, "//span[@class='lesson-editor-status' and .='Saving...']"))) wait.until( EC.visibility_of_element_located( (By.XPATH, "//span[@class='lesson-editor-status' and .='Saved']"))) print "Going to upload the image file" driver.find_element_by_css_selector('input[type="file"]').send_keys( Imagefilepath1) wait.until( EC.visibility_of_element_located(( By.XPATH, ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img" ))) imageContainerlocator_after1upload = driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img" ) if (imageContainerlocator_after1upload.is_displayed()): print 'Successfully uploaded the image1 file' else: print "Failed to upload the image1 file" raise Exception
def createTrack(self,titleOfTrack,Imagefilepath,description,tagName,lessonname,expectedSuccessText): print "Creating track with one lesson contains Text Card" wait=WebDriverWait(driver, 60) wait.until(EC.visibility_of_element_located((By.XPATH,"//a[@href='/create/lessons']"))) print "Clicking on Lessons button from side menu" driver.find_element_by_xpath("//a[@href='/create/lessons']").click() wait.until(EC.visibility_of_element_located((By.XPATH,"//a[@href='/create/tracks']"))) print "Clicking on Track button from side menu" driver.find_element_by_xpath("//a[@href='/create/tracks']").click() createTrackbutton=wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div[3]/div[2]/div/header/div/a"))) createTrackbutton.click() print "Entering title" titlefield=wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='title']"))) titlefield.send_keys(titleOfTrack) print "Title entered ::"+titleOfTrack driver.find_element_by_css_selector('input[type="file"]').send_keys(Imagefilepath) print "waiting to upload image" wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div[3]/div[2]/div/div/div[2]/div[1]/div[2]/div/div/div/div/div[1]/img"))) print "Image uploaded" print "Entering Description" driver.find_element_by_xpath(".//*[@id='description']").send_keys(description) print "Description entered ::"+description print "Adding tag" addTags=driver.find_element_by_xpath("//div[@class='Select-placeholder']") webdriver.ActionChains(driver).move_to_element(addTags).click().send_keys(tagName).perform() option=wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='react-select-2--option-0']"))) webdriver.ActionChains(driver).move_to_element(option).click(option).perform() driver.find_element_by_xpath(".//*[@id='description']").send_keys(" ") print "Adding created lesson" print "Clicking on Add lessons button" driver.execute_script("window.scrollTo(0, 0);") addlessonbutton=driver.find_element_by_xpath(".//*[@id='content']/div/div[3]/div[2]/div/div/div[2]/div[2]/div[1]/div/div/div/button") addlessonbutton.click() wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div[2]/div/div/div[2]/div[2]/div/ul/li[1]/div[1]/div"))) print "Searching for lesson in Add lessons pop up" driver.find_element_by_xpath(".//*[@id='search-lessons-in-modal']").send_keys(lessonname) searchedLesson=wait.until(EC.visibility_of_element_located((By.XPATH,"//li/div[2]/h4[.='"+lessonname+"']/../../div[1]/div"))) searchedLesson.click() print "Lesson '"+lessonname+"' selected" print "Adding to Track" driver.find_element_by_xpath("html/body/div[2]/div/div/div[2]/div[3]/button[1]").click() wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div[3]/div[2]/div/div/div[2]/div[2]/div[1]/div/ul/li/div[2]/div/h4/div"))) print "Checking added lesson is selected lesson from Pop up" lessonTextAddedToGrid=driver.find_element_by_xpath(".//*[@id='content']/div/div[3]/div[2]/div/div/div[2]/div[2]/div[1]/div/ul/li/div[2]/div/h4/div").text if lessonTextAddedToGrid==lessonname: print "Selected Lesson is displayed in grid of tracks page" else: print "Lesson is not displayed" raise Exception print "Clicking on Publish Track button" driver.find_element_by_xpath(".//*[@id='content']/div/div[3]/div[2]/div/div/div[2]/div[2]/div[3]/button").click() print "Verifying Success message is displaying" wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div[2]/div/div/span"))) actualSuccessText=driver.find_element_by_xpath(".//*[@id='content']/div/div[2]/div/div/span").text if actualSuccessText==expectedSuccessText: print "Success message '"+actualSuccessText+"' is displayed" else: print "failed to display expected success message" raise Exception print "Verifying Creates track '"+titleOfTrack+"' is displayed in Tracks grid" driver.find_element_by_xpath(".//*[@id='content']/div/div[3]/div[1]/div/nav/div/div[2]/div[3]/div/ul/li[2]/a").click() wait.until(EC.visibility_of_element_located((By.XPATH,"//tbody/tr/td[2]/a[.='"+titleOfTrack+"']"))) trackInGrid=driver.find_element_by_xpath("//tbody/tr/td[2]/a[.='"+titleOfTrack+"']").text if trackInGrid==titleOfTrack: print "Track '"+trackInGrid+"' is displayed in grid" else: print "Track is not displayed in grid" raise Exception driver.find_element_by_xpath(".//*[@id='content']/div/div[3]/div[1]/div/nav/div/div[4]").click()
def lessonWithImage(self,lessonName,Imagefilepath1): wait=WebDriverWait(driver, 60) wait.until(EC.visibility_of_element_located((By.XPATH,"//a[@href='/create/lessons']"))) print "Clicking on Lessons button from side menu" driver.find_element_by_xpath("//a[@href='/create/lessons']").click() wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div[3]/div[2]/div/header/div/button"))) print "Click on Create lesson button" driver.find_element_by_xpath(".//*[@id='content']/div/div[3]/div[2]/div/header/div/button").click() print "Verifying Create new lesson tab is displayed" #assert "Create a new lesson"==driver.find_element_by_xpath("/html/body/div[2]/div/div/div[1]/h3").text if driver.find_element_by_xpath("/html/body/div[2]/div/div/div[1]/h3").text == "Create a new lesson": print("Create a new lesson tab is displayed") else: print "" raise Exception # self.assertEqual("Create a new lesson", driver.find_element_by_xpath("/html/body/div[2]/div/div/div[1]/h3").text) wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div[2]/div/div/div[2]/div[2]/div"))) print "Clicked on Blank lesson" driver.find_element_by_xpath("html/body/div[2]/div/div/div[2]/div[2]/div").click() print "Creating New lesson With one Text card" wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/h1/textarea"))) driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/h1/textarea").send_keys(lessonName) wait.until(EC.visibility_of_element_located((By.XPATH,"//span[@class='lesson-editor-status' and .='Saving...']"))) wait.until(EC.visibility_of_element_located((By.XPATH,"//span[@class='lesson-editor-status' and .='Saved']"))) print "Entered lesson name ::"+lessonName print "Click on (+) icon" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div/span").click() #Clicking on Image card driver.find_element_by_xpath("html/body/div/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[2]/div[1]").click() #Uploading image driver.find_element_by_css_selector('input[type="file"]').send_keys(Imagefilepath1) wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img"))) imageContainerlocator_after1upload= driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img") if(imageContainerlocator_after1upload.is_displayed()): print 'Successfully uploaded the image1 file' else: print "Failed to upload the image1 file" raise Exception publishbutton=wait.until(EC.element_to_be_clickable((By.XPATH,"html/body/div/div/div/div[3]/div[3]/div[1]/div[3]/div[3]/button"))) driver.execute_script("arguments[0].click();",publishbutton) wait.until(EC.element_to_be_clickable((By.XPATH,"html/body/div/div/div/div[3]/div[3]/div[1]/div[3]/div[3]/div/div[1]/section[3]/div/button[1]"))) driver.find_element_by_xpath("html/body/div/div/div/div[3]/div[3]/div[1]/div[3]/div[3]/div/div[1]/section[3]/div/button[1]").click() print "Clicked on publish button" # verifying success message print "Verifying Success message" wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[2]/div/div/span[2]"))) headerText=driver.find_element_by_xpath(".//*[@id='content']/div/div/div[2]/div/div/span[2]").text print "Message '"+headerText+"' is displayed" if "You have successfully published" in headerText: print("Create a new lesson tab is displayed") else: print "Success message is not displayed" raise Exception print "Lesson published" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[1]/a").click() #Verifying created lesson is displayed in list wait.until(EC.visibility_of_element_located((By.XPATH,"(//tbody/tr/td[2]/a[.='"+lessonName+"'])[1]"))) if driver.find_element_by_xpath("(//tbody/tr/td[2]/a[.='"+lessonName+"'])[1]").is_displayed(): print "Lesson is displayed in Grid ::"+lessonName else: print "Lesson not displaying in grid" raise Exception driver.find_element_by_xpath(".//*[@id='content']/div/div[3]/div[1]/div/nav/div/div[4]").click()
def clickEdit(self): wait=WebDriverWait(driver, 80) # Going to click on edit for the created lesson wait.until(EC.visibility_of_element_located((By.XPATH,"//table/tbody/tr/td[.='Published']/../td[2]/a[.='"+lesson_title+"']"))) driver.find_element_by_xpath("//table/tbody/tr/td[.='Published']/../td[2]/a[.='"+lesson_title+"']/../../td[4]/a[.='Edit']").click() print "Clicking on edit link for the created lesson"+ " "+lesson_title wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[1]/a"))) # Going to verify the lesson title actuale_lesson_title = driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/h1/textarea").text if (actuale_lesson_title == lesson_title): print "The edit page is displaying for the published lesson" else: print "Failed to open the edit page for published lesson" raise Exception # Going to clear the lesson title print "Going to edit the lesson title" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/h1/textarea").clear() print "Cleared the lesson title" new_lesson_title = "Edited_title"+" "+lesson_title driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/h1/textarea").send_keys(new_lesson_title) print "Re-entered the lesson title" wait.until(EC.visibility_of_element_located((By.XPATH,"//span[@class='lesson-editor-status' and .='Saving...']"))) wait.until(EC.visibility_of_element_located((By.XPATH,"//span[@class='lesson-editor-status' and .='Saved']"))) driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[1]/div/div/div/div[2]/div/div[1]").click() print "Selecting the Text card" #Going to clear the content print "Going to clear the content in text card" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div/div/div[2]/div/div/div/div/div/div").clear() book=xlrd.open_workbook(os.path.join('TestData.xlsx')) first_sheet = book.sheet_by_name('MultiCardLesson') cell9= first_sheet.cell(59,3) editedText = cell9.value textElement = driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div") webdriver.ActionChains(driver).move_to_element(textElement).click().send_keys(editedText).perform() wait.until(EC.visibility_of_element_located((By.XPATH,"//span[@class='lesson-editor-status' and .='Saving...']"))) wait.until(EC.visibility_of_element_located((By.XPATH,"//span[@class='lesson-editor-status' and .='Saved']"))) driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[1]/div/div/div/div[3]/div/div[1]").click() print "Selecting the Question Card" cell10= first_sheet.cell(59,4) questionAfterEdit = cell10.value print "Entering question" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/p/textarea").send_keys(questionAfterEdit) cell11= first_sheet.cell(59,5) firstAnswerAfterEdit = cell11.value print "Entering first answer" driver.find_element_by_xpath(".//*[@id='question-answer-input-0']").send_keys(firstAnswerAfterEdit) cell12= first_sheet.cell(59,6) secondAnswerAfterEdit = cell12.value print "Entering Second answer" driver.find_element_by_xpath(".//*[@id='question-answer-input-1']").send_keys(secondAnswerAfterEdit) wait.until(EC.visibility_of_element_located((By.XPATH,"//span[@class='lesson-editor-status' and .='Saving...']"))) wait.until(EC.visibility_of_element_located((By.XPATH,"//span[@class='lesson-editor-status' and .='Saved']"))) # Clicking on Image card driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[1]/div/div/div/div[4]/div/div[1]").click() print "Selecting the Image card" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[2]/button").click() print "Clicking on Delete button" print "Going to upload the image file" cell13= first_sheet.cell(1,5) Imagefilepath2 = cell13.value wait=WebDriverWait(driver,600) driver.find_element_by_css_selector('input[type="file"]').send_keys(Imagefilepath2) wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img"))) imageContainerlocator_after1upload= driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img") if(imageContainerlocator_after1upload.is_displayed()): print 'Successfully uploaded the image2 file' else: print "Failed to upload the image2 file" raise Exception # Clicking on Video card driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[1]/div/div/div/div[5]/div/div[1]").click() print "Selecting the Video card" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[2]/button").click() print "Clicking on Delete button" cell14= first_sheet.cell(1,8) videoName1 = cell14.value #Uploading Video print "Uploading new Video" driver.find_element_by_css_selector('input[type="file"]').send_keys(videoName1) wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div[1]/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/button"))) videoContainerlocator_afterupload= driver.find_element_by_xpath("html/body/div[1]/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/button") if(videoContainerlocator_afterupload.is_displayed()): print 'Successfully uploaded the Video file' else: print "Failed to upload the Video file" raise Exception driver.find_element_by_xpath("html/body/div[1]/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/button").click() wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div"))) # Clicking on Document card driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[1]/div/div/div/div[6]/div/div[1]").click() print "Selecting the Document card" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[2]/button").click() print "Clicking on Delete button" cell15= first_sheet.cell(1,9) document2Path = cell15.value driver.find_element_by_css_selector('input[type="file"]').send_keys(document2Path) print "Uploading new document file" #wait till minimize button is displayed wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/div[1]/div[1]/button[1]"))) downloadButtonLocator= driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[2]/div/div/div[1]/div/a") if (downloadButtonLocator.is_displayed()): print "The new file has been uploaded successfully" else: print "Failed to upload the file" raise Exception wait.until(EC.element_to_be_clickable((By.XPATH,".//*[@id='content']/div/div/div[3]/div[3]/div[1]/div[3]/div[3]/button"))) driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[1]/div[3]/div[3]/button").click() print "Clicking on READY TO PUBLISH button" wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[3]/div[1]/div[3]/div[3]/div/div[1]/section[3]/div/button[1]"))) driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[3]/div[1]/div[3]/div[3]/div/div[1]/section[3]/div/button[1]").click() print "Clicking on PUBLISH button" """ print "Validating the success message after publish" wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[2]/div/div/span[2]"))) actual_success_message= driver.find_element_by_xpath(".//*[@id='content']/div/div/div[2]/div/div/span[2]").text expected_success_message= "You have successfully published \"" + lesson_title + "\""; if(expected_success_message==actual_success_message): print "The success message is displaying as"+ " "+expected_success_message else: print "The success message is not displaying as expected" """ # wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[2]/div/div/span[2]"))) time.sleep(6) driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[1]/a").click() print "Clicking on EXIT button" print "Verifying lesson displayed in Grid" wait.until(EC.visibility_of_element_located((By.XPATH,"(//tbody/tr/td[2]/a[.='"+new_lesson_title+"'])[1]"))) if driver.find_element_by_xpath("(//tbody/tr/td[2]/a[.='"+new_lesson_title+"'])[1]").is_displayed(): print "Lesson is displayed in Grid ::"+new_lesson_title else: print "Lesson not displaying in grid" raise Exception
def addImageCard(self, Imagefilepath1, linkname, Imagefilepath2, time): wait = WebDriverWait(driver, time) driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div" ).click() print "Clicking on Add card + icon" driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[2]/div[1]/div" ).click() print "Image card selected" wait.until( EC.visibility_of_element_located(( By.XPATH, ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div/div[1]/h4/div[1]/span[2]/div" ))) #driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div/div[1]/h4/div[1]/span[2]/div").click() #print "Clicking on browse for your file link" wait.until( EC.visibility_of_element_located( (By.XPATH, "//span[@class='lesson-editor-status' and .='Saving...']"))) wait.until( EC.visibility_of_element_located( (By.XPATH, "//span[@class='lesson-editor-status' and .='Saved']"))) print "Going to upload the image file" driver.find_element_by_css_selector('input[type="file"]').send_keys( Imagefilepath1) wait.until( EC.visibility_of_element_located(( By.XPATH, ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img" ))) imageContainerlocator_after1upload = driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img" ) if (imageContainerlocator_after1upload.is_displayed()): print 'Successfully uploaded the image1 file' else: print "Failed to upload the image1 file" raise Exception ''' print "Going to delete the image1" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[2]/button").click() browseforyourlink= driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div/div[1]/h4/div[1]/span[2]") if(browseforyourlink.is_displayed() and browseforyourlink.text==linkname): print 'Successfully deleted the image1 file' else: print "Failed to delete the image file" raise Exception print "Going to upload second image file" driver.find_element_by_css_selector('input[type="file"]').send_keys(Imagefilepath2) wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img"))) imageContainerlocator_after2upload= driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]/img") if(imageContainerlocator_after2upload.is_displayed()): print 'Successfully uploaded the image2 file' else: print "Failed to upload the image2 file" raise Exception print "Going to delete the uploaded image2 and inserting an animated GIF" driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[2]/button").click() wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div/div[1]/h4/div[2]/span[2]"))) driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div/div[1]/h4/div[2]/span[2]").click() print "Clicking on insert animated GIF link" wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div[2]/div/div/div[2]/div[2]/div/ul/li[1]/div"))) driver.find_element_by_xpath("html/body/div[2]/div/div/div[2]/div[2]/div/ul/li[1]/div").click() print "Selecting the first GIF from"+" "+"Search all the GIFs pop up" wait.until(EC.element_to_be_clickable((By.XPATH,"html/body/div[2]/div/div/div[2]/div[3]/button[1]"))) driver.find_element_by_xpath("html/body/div[2]/div/div/div[2]/div[3]/button[1]").click() print "Clicking on SAVE button" wait.until(EC.visibility_of_element_located((By.XPATH,".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]"))) GifLocator= driver.find_element_by_xpath(".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/div/div/div[1]") if(GifLocator.is_displayed()): print "The GIF added successfully" else: print "Failed to add GIF" raise Exception ''' '''
def lessonWithDocument(self, lessonname, documentPath, timeToUploaddocument, textCard): print "This is lesson with document" wait = WebDriverWait(driver, timeToUploaddocument) wait.until( EC.visibility_of_element_located( (By.XPATH, "//a[@href='/create/lessons']"))) print "Clicking on Lessons button from side menu" driver.find_element_by_xpath("//a[@href='/create/lessons']").click() wait.until( EC.visibility_of_element_located( (By.XPATH, ".//*[@id='content']/div/div[3]/div[2]/div/header/div/button" ))) print "Click on Create lesson button" driver.find_element_by_xpath( ".//*[@id='content']/div/div[3]/div[2]/div/header/div/button" ).click() print "Verifying Create new lesson tab is displayed" #assert "Create a new lesson"==driver.find_element_by_xpath("/html/body/div[2]/div/div/div[1]/h3").text if driver.find_element_by_xpath("/html/body/div[2]/div/div/div[1]/h3" ).text == "Create a new lesson": print("Create a new lesson tab is displayed") else: print "" raise Exception # self.assertEqual("Create a new lesson", driver.find_element_by_xpath("/html/body/div[2]/div/div/div[1]/h3").text) wait.until( EC.visibility_of_element_located( (By.XPATH, "html/body/div[2]/div/div/div[2]/div[2]/div"))) print "Clicked on Blank lesson" driver.find_element_by_xpath( "html/body/div[2]/div/div/div[2]/div[2]/div").click() print "Creating New lesson With one Text card" wait.until( EC.visibility_of_element_located(( By.XPATH, ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/h1/textarea" ))) driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/h1/textarea" ).send_keys(lessonname) wait.until( EC.visibility_of_element_located( (By.XPATH, "//span[@class='lesson-editor-status' and .='Saving...']"))) wait.until( EC.visibility_of_element_located( (By.XPATH, "//span[@class='lesson-editor-status' and .='Saved']"))) print "Entered lesson name ::" + lessonname print "Click on (+) icon" driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[3]/div[2]/div[2]/div/div/span" ).click() #Clicking on Document card driver.find_element_by_xpath( "html/body/div/div/div/div[3]/div[3]/div[2]/div[2]/div/div[2]/div[1]/div[4]/div[1]/div" ).click() #Uploading Document print "Uploading Document" driver.find_element_by_css_selector('input[type="file"]').send_keys( documentPath) wait.until( EC.visibility_of_element_located( (By.XPATH, "//label[@class='u-block card-media-upload-label']"))) documentContainerlocator_afterupload = driver.find_element_by_xpath( "//label[@class='u-block card-media-upload-label']") if (documentContainerlocator_afterupload.is_displayed()): print "Successfully uploaded the Document file" else: print "Failed to upload the Document file" raise Exception o = CreateCampaignForDocumentLesson() o.textCard(textCard) '''driver.find_element_by_xpath("//div[@class='card-delete']/button").click() wait.until(EC.visibility_of_element_located((By.XPATH,"//span[@class='lesson-editor-status' and .='Saved']"))) ''' print "Publishing lesson" publishbutton = wait.until( EC.element_to_be_clickable(( By.XPATH, "html/body/div/div/div/div[3]/div[3]/div[1]/div[3]/div[3]/button" ))) driver.execute_script("arguments[0].click();", publishbutton) wait.until( EC.element_to_be_clickable(( By.XPATH, "html/body/div/div/div/div[3]/div[3]/div[1]/div[3]/div[3]/div/div[1]/section[3]/div/button[1]" ))) driver.find_element_by_xpath( "html/body/div/div/div/div[3]/div[3]/div[1]/div[3]/div[3]/div/div[1]/section[3]/div/button[1]" ).click() print "Clicked on publish button" # verifying success message print "Verifying Success message" wait.until( EC.visibility_of_element_located( (By.XPATH, ".//*[@id='content']/div/div/div[2]/div/div/span[2]"))) headerText = driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[2]/div/div/span[2]").text print "Message '" + headerText + "' is displayed" if "You have successfully published" in headerText: print("Create a new lesson tab is displayed") else: print "Success message is not displayed" raise Exception print "Lesson published" driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[1]/a" ).click() #Verifying created lesson is displayed in list wait.until( EC.visibility_of_element_located( (By.XPATH, "(//tbody/tr/td[2]/a[.='" + lessonname + "'])[1]"))) if driver.find_element_by_xpath("(//tbody/tr/td[2]/a[.='" + lessonname + "'])[1]").is_displayed(): print "Lesson is displayed in Grid ::" + lessonname else: print "Lesson not displaying in grid" raise Exception driver.find_element_by_xpath( ".//*[@id='content']/div/div[3]/div[1]/div/nav/div/div[4]").click( )
def uploadscormAndPowerpoint(self): wait = WebDriverWait(driver, 60) wait.until( EC.visibility_of_element_located( (By.XPATH, "//a[@href='/create/lessons']"))) print "Clicking on Lessons button from side menu" driver.find_element_by_xpath("//a[@href='/create/lessons']").click() wait = WebDriverWait(driver, 60) wait.until( EC.visibility_of_element_located( (By.XPATH, ".//*[@id='content']/div/div[3]/div[2]/div/header/div/button" ))) print "Clicking on Create Lesson button from lessons page" driver.find_element_by_xpath( ".//*[@id='content']/div/div[3]/div[2]/div/header/div/button" ).click() # wait for Power Point icon wait.until( EC.visibility_of_element_located(( By.XPATH, "html/body/div[2]/div/div/div[2]/div[7]/div/div/div/span[2]"))) book = xlrd.open_workbook(os.path.join('TestData.xlsx')) first_sheet = book.sheet_by_name('MultiCardLesson') cell1 = first_sheet.cell(56, 0) ScormOrImageFilePath = cell1.value print "Going to upload the SCORM or POWER POINT file" driver.find_element_by_css_selector('input[type="file"]').send_keys( ScormOrImageFilePath) wait = WebDriverWait(driver, 600) wait.until( EC.visibility_of_element_located(( By.XPATH, ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[1]/a" ))) print "Successfully uploaded the SCORM or POWER POINT file" print "Going to verify the title of Uploaded SCORM or POWER POINT file" global actual_titleof_scormlesson actual_titleof_scormlesson = driver.find_element_by_xpath( ".//*[@id='content']/div/div/div[3]/div[1]/div/div[2]/div[2]/div/div/div/h1/textarea" ).text cell2 = first_sheet.cell(57, 0) expected_titleof_scormlesson = cell2.value if (expected_titleof_scormlesson == actual_titleof_scormlesson): print "Successfully verified the title of Uploaded Scorm or Powerpoint lesson" else: print "Failed to verify the title of Uploaded Scorm or Powerpoint lesson" raise Exception