Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.cengage.mindtap.keywords; import com.qait.automation.utils.PropFileHandler; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.List; //import static com.qait.automation.utils.PropFileHandler.writeProperty; /** * * @author QAI */ public class MessageCenterPageActions extends BasePageActions { List<WebElement> distinctActivityList_Size; int distinctActivity_Size; boolean flag = true; String posturgentmessagekey = "posturgentmessage"; String postMaxWordmessagekey = "postMaxWordMessage"; String postmessagekey = "postmessage"; WebElement element; public MessageCenterPageActions(WebDriver driver) { super(driver, "MessageCenterPage"); } public void PostTheMessage() { switchToMessageFameNewCourse(); sendMessageToAllStudents(); } public void postTheUrgentMessage() { switchToMessageFameNewCourse(); sendUrgentMessageToAllStudents(); } public void PostTheMessageSeeMore() { switchToMessageFameNewCourse(); sendMessageToAllStudentsSeeMore(); } public void switchToMessageFameNewCourse() { switchToDefaultContent(); switchToFrame(element("Frame_MessageCenter").getAttribute("id")); } /** * Send message to all students. */ public void sendMessageToAllStudents() { element("TextArea_MessageBox").isDisplayed(); element("TextArea_MessageBox").click(); element("TextArea_MessageBox").clear(); Calendar calendar = Calendar.getInstance(); SimpleDateFormat formater = new SimpleDateFormat("ddMMyyyyhhmmss"); String message = "Automation Test Message: " + formater.format(calendar.getTime()); element("TextArea_MessageBox").sendKeys(message); element("btn_messageSubmit").click(); PropFileHandler.writeProperty(postmessagekey, message); } public void sendMessageToAllStudentsSeeMore() { element("TextArea_MessageBox").isDisplayed(); element("TextArea_MessageBox").click(); element("TextArea_MessageBox").clear(); Calendar calendar = Calendar.getInstance(); SimpleDateFormat formater = new SimpleDateFormat("ddMMyyyyhhmmss"); String message = "Message from Automation Script : This is the autogenerated message from Automation Script Message from Automation Script : This is the autogenerated message from Automation Script Message from Automation Script " + formater.format(calendar.getTime()); element("TextArea_MessageBox").sendKeys(message); element("btn_messageSubmit").click(); PropFileHandler.writeProperty(postMaxWordmessagekey, message); } /** * Send urgent message to all students. */ public void sendUrgentMessageToAllStudents() { element("TextArea_MessageBox").isDisplayed(); element("TextArea_MessageBox").click(); element("TextArea_MessageBox").clear(); Calendar calendar = Calendar.getInstance(); SimpleDateFormat formater = new SimpleDateFormat("ddMMyyyyhhmmss"); String message = "Automation Test Message: " + formater.format(calendar.getTime()); element("TextArea_MessageBox").sendKeys(message); element("urgentCheckbox").click(); element("btn_messageSubmit").click(); PropFileHandler.writeProperty(posturgentmessagekey, message); waitTOSync(); } /** * Verify message post and display in panel. */ public boolean verifyMessagePostAndDisplayInPanel() { return element("btn_PostedMessage", PropFileHandler.readProperty(postmessagekey)).isDisplayed(); } /** * Verify urgent message post and display in panel. */ public boolean verifyUrgentMessagePostAndDisplayInPanel() { boolean flag1 = false, flag2 = false; flag1 = element("btn_PostedMessage", PropFileHandler.readProperty(posturgentmessagekey)).isDisplayed(); flag2 = elements("UrgentIcon").get(0).isDisplayed(); if (flag1 == true && flag2 == true) return true; else return false; } /** * Verify see more button is present after writing 200 words in field . */ public boolean verifyUrgentMessagePostAndDisplayButton() { System.out.println(PropFileHandler.readProperty(postMaxWordmessagekey).split(":")[0]); return element("postedMessage_seemore", PropFileHandler.readProperty(postMaxWordmessagekey).split(":")[0]) .isDisplayed(); } /** * Verify message display in panel at student. */ public boolean verifyMessageDisplayInPanelAtStudent() { switchToMessageFameNewCourse(); return (verifyMessageInList()); } /** * Verify urgent message display in panel at student. */ public boolean verifyUrgnetMessageDisplayInPanelAtStudent() { waitTOSync(); boolean flag1 = false, flag2 = false; flag1 = verifyMessageInList(); flag2 = elements("UrgentIcon").get(0).isDisplayed(); if (flag1 == true && flag2 == true) return true; else return false; } /** * Verify message in list. * * @return true, if successful */ private boolean verifyMessageInList() { String message = PropFileHandler.readProperty(postmessagekey); System.out.println("message :" + message); for (WebElement ele : elements("btn_PostedMessage")) { System.out.println(ele.getText()); if (ele.getText().equals(message)) { return true; } } return false; } public void addEmailAddress(String data) { element("SettingOptionsbtn").click(); element("email_textfld").click(); element("email_textfld").clear(); Calendar calendar = Calendar.getInstance(); SimpleDateFormat formater = new SimpleDateFormat("ddMMyyyyhhmmss"); String email = data + formater.format(calendar.getTime()) + "@qai.com"; element("email_textfld").sendKeys(email); element("Addbtn").click(); } public boolean verifyAddEmailAddress() { boolean flag = element("success_message").isDisplayed(); element("SettingOptionsbtn").click(); return flag; } public void deleteEmailAddress() { element("SettingOptionsbtn").click(); element("deleteEmailbtn").click(); handleAlert(); element("SettingOptionsbtn").click(); } }