Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 83 additions & 21 deletions src/main/java/com/orasi/bluesource/Accounts.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
package com.orasi.bluesource;

import java.lang.reflect.UndeclaredThrowableException;
import java.util.List;

import javax.lang.model.util.Elements;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.orasi.utils.Randomness;
import com.orasi.utils.TestReporter;
import com.orasi.web.OrasiDriver;
import com.orasi.web.PageLoaded;
import com.orasi.web.webelements.Button;
import com.orasi.web.webelements.Element;
import com.orasi.web.webelements.Link;
import com.orasi.web.webelements.Listbox;
import com.orasi.web.webelements.Textbox;
import com.orasi.web.webelements.Webtable;
import com.orasi.web.webelements.*;
import com.orasi.web.webelements.impl.internal.ElementFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.support.FindBy;

import java.lang.reflect.UndeclaredThrowableException;
import java.util.List;

public class Accounts {
private OrasiDriver driver = null;
Expand All @@ -46,6 +32,11 @@ public class Accounts {
@FindBy(css = "div.btn.btn-secondary.btn-xs.quick-nav") private Button btnQuickNav;
@FindBy(xpath = "//a[contains(@ng-bind, 'n + 1')]") private List<Button> btnPages;
@FindBy(xpath = "//*[@id=\"project-list\"]/div/div[1]/div") private Button btnCloseQuickNav;
@FindBy(xpath = "//h4[@class='panel-title' and contains(text(),'Project Info')]") private Element elmProjectInfoPanelHeader;
@FindBy(xpath = "//h4[@class='panel-title'and contains(text(),'Documents')]/../button") private Button btnProjectAddDocument;
@FindBy(xpath = "//th[contains(text(),'Document')]/../../..") private Webtable tblDocuments;



/**Constructor**/
public Accounts(OrasiDriver driver){
Expand All @@ -55,6 +46,77 @@ public Accounts(OrasiDriver driver){

/**Page Interactions**/

/**
* This method provides standard checks that an element can be interacted with
* @author David Grayson
* @param element {@link Element} Element to check
* @return {@link Boolean} Returns <code>true</code> if the element is enabled and visible, <code>false</code> otherwise
*/
private boolean canInteract(Element element) {
return element.syncEnabled(5) && element.syncVisible(5);
}

/**
* @author David Grayson
* @param document {@link String} the name of the document to find
* @return {@link Boolean} Returns true if a document of the name provided exists in the documents table
*/
public boolean verifyDocumentExists(String document){
return tblDocuments.getRowWithCellText(document) > 0;
}

/**
* Clicks the add document button in Account or Project pages
* @author David Grayson
*/
public void clickAddDocument(){
if (canInteract(btnProjectAddDocument))
btnProjectAddDocument.click();
}


/**
* would use the {@link #verifyProjectLink(String)} but it doesn't do what it's name implies
* @author David Grayson
* @param project {@link String} name of Project
* @return {@link Boolean} Returns <code>true</code> if the link is clickable within 5 seconds, <code>false</code> otherwise.
*/
public boolean verifyProjectLinkValid(String project){
return driver.findLink(By.linkText(project)).syncEnabled(5,false) &&
driver.findLink(By.linkText(project)).syncVisible(5,false);
}

/**
* @author David Grayson
* @param strAccount {@link String} name of Projects parent account
* @param strProject {@link String} name of project
* @return {@link Boolean} Returns <code>true</code> if the provided Projects page is loaded, <code>false</code> otherwise.
*/
public boolean verifyProjectPageIsLoaded(String strAccount, String strProject){
return PageLoaded.isElementLoaded(this.getClass(),driver, elmProjectInfoPanelHeader,5)
&& driver.findElement(By.xpath("//div[@class='breadcrumbs']")).getText()
.equals("Accounts - " + strAccount + " - " + strProject);
}

/**
* @author David Grayson
* @param strAccount {@link String} name of Account
* @return {@link Boolean} Returns <code>true</code> if the provided Accounts page is loaded, <code>false</code> otherwise.
*/
public boolean verifyAccountPageIsLoaded(String strAccount){
String xpath = "//div[@class='breadcrumbs']/a[contains(text(),'" + strAccount + "')]";
return PageLoaded.isElementLoaded(this.getClass(),driver,tblProjects,5)
&& driver.findLink(By.xpath(xpath)).syncVisible(5,false);
}

/**
* @author David Grayson
* @return {@link Boolean} Returns <code>true</code> if the Accounts table is loaded, <code>false</code> otherwise.
*/
public boolean verifyAccountsPageIsLoaded(){
return PageLoaded.isElementLoaded(this.getClass(),driver,tblAccounts,5);
}

/*
* Click on accounts tab
* Make sure that the correct page loads
Expand Down
100 changes: 100 additions & 0 deletions src/main/java/com/orasi/bluesource/AddDocumentForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.orasi.bluesource;

import com.orasi.web.OrasiDriver;
import com.orasi.web.PageLoaded;
import com.orasi.web.webelements.Checkbox;
import com.orasi.web.webelements.Element;
import com.orasi.web.webelements.Textbox;
import com.orasi.web.webelements.impl.internal.ElementFactory;
import org.openqa.selenium.support.FindBy;

import java.text.DecimalFormat;
import java.util.List;

public class AddDocumentForm {
private OrasiDriver driver = null;

/**Page Elements**/
@FindBy(xpath = "//form[@id='new_document']") private Element elmAddDocumentForm;
@FindBy(xpath = "//input[@name='document[file]']") private Element elmDocumentFile;
@FindBy(xpath = "//span[@class='select2-results']/ul/li") private List<Element> elmDocumentTypeOptions;
@FindBy(xpath = "//input[@id='document_budget']") private Textbox txtTotalBudget;
@FindBy(xpath = "//input[@id='document_hours']") private Textbox txtTotalHours;
@FindBy(xpath = "//input[@id='document_signed']") private Checkbox chkSigned;
@FindBy(xpath = "//input[@value='Create Document']") private Element elmCreateDocument;
@FindBy(xpath = "//form[@id='new_document']//span[@role='combobox']") private Element elmDocumentType;
@FindBy(xpath = "//input[@id='document_name']") private Textbox txtDocumentName;

/**
* Constructor
**/
public AddDocumentForm(OrasiDriver driver) {
this.driver = driver;
ElementFactory.initElements(driver, this);
}

/**Page Interactions**/

public boolean verifyFormLoaded(){
return PageLoaded.isElementLoaded(this.getClass(),driver,elmAddDocumentForm,5);
}

/**
* @author David Grayson
* @param filePath {@link String} the complete path for the file to be uploaded
*/
public void setFile(String filePath){
if (canInteract(elmDocumentFile))
elmDocumentFile.sendKeys(filePath);
}

public String getDocumentName(){
return txtDocumentName.getText();
}

public void clickCreateDocument(){
if (canInteract(elmCreateDocument))
elmCreateDocument.click();
}

public void selectDocumentType(String type){
if (canInteract(elmDocumentType)){
elmDocumentType.click();
for (Element elm:elmDocumentTypeOptions){
if (elm.getText().equals(type)){
elm.click();
break;
}
}
}
}

public void setTotalHours(double hours){
if (canInteract(txtTotalHours)){
txtTotalHours.clear();
txtTotalHours.sendKeys(new DecimalFormat("####.00").format(hours));
}
}

public void setTotalBudget(int budget){
if (canInteract(txtTotalBudget)){
txtTotalBudget.clear();
txtTotalBudget.sendKeys(String.valueOf(budget));
}
}

public void clickSignedCheckbox(){
if (canInteract(chkSigned))
chkSigned.toggle();
}

/**
* This method provides standard checks that an element can be interacted with
* @author David Grayson
* @param elm {@link Element} Element to check
* @return {@link Boolean} Returns <code>true</code> if the element is enabled and visible, <code>false</code> otherwise
*/
private boolean canInteract(Element elm){
return elm.syncEnabled(5) && elm.syncVisible(5);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.bluesource.accounts;

import com.orasi.bluesource.Accounts;
import com.orasi.bluesource.AddDocumentForm;
import com.orasi.bluesource.Header;
import com.orasi.bluesource.LoginPage;
import com.orasi.utils.TestReporter;
import com.orasi.web.WebBaseTest;
import org.testng.ITestContext;
import org.testng.annotations.*;

public class SupportMsgFileAttachmentInDocumentsAccounts extends WebBaseTest {
@BeforeMethod
@Parameters({ "runLocation", "browserUnderTest", "browserVersion",
"operatingSystem", "environment" })
public void setup(@Optional String runLocation, String browserUnderTest,
String browserVersion, String operatingSystem, String environment) {
setApplicationUnderTest("BLUESOURCE");
setBrowserUnderTest(browserUnderTest);
setBrowserVersion(browserVersion);
setOperatingSystem(operatingSystem);
setRunLocation(runLocation);
setEnvironment(environment);
setThreadDriver(true);
testStart("");
}

@AfterMethod
public void close(ITestContext testResults){
endTest("TestAlert", testResults);
}

@Test
public void supportMsgFileAttachmentInDocumentsAccounts(){
//Test variables
String strAccount = "Account1";
String strProject = "Project1";
String strMsgFilePath = "C:\\Users\\david.grayson\\Documents\\test msg.msg";
String fileName = strMsgFilePath.split("\\\\")[strMsgFilePath.split("\\\\").length-1];
int budget = 10000;
double hours = 10000.00;
String documentType = "SOW";
String documentName;

//Page Models
LoginPage loginPage = new LoginPage(getDriver());
Header header = new Header(getDriver());
Accounts accounts = new Accounts(getDriver());
AddDocumentForm addDocumentForm = new AddDocumentForm(getDriver());

TestReporter.assertTrue(loginPage.verifyPageIsLoaded(),"Verifying BlueSource login page is loaded");

TestReporter.logStep("Logging in as Admin");
loginPage.AdminLogin();

TestReporter.logStep("Navigating to Accounts");
header.navigateAccounts();

TestReporter.assertTrue(accounts.verifyAccountsPageIsLoaded(), "Verifying Accounts page is loaded");
TestReporter.assertTrue(accounts.verifyAccountLink(strAccount), "Verifying account ["+strAccount+"] link");

TestReporter.logStep("Clicking [" + strAccount + "] link");
accounts.clickAccountLink(strAccount);

TestReporter.assertTrue(accounts.verifyAccountPageIsLoaded(strAccount),"Verifying account ["+strAccount+"] page is loaded");
TestReporter.assertTrue(accounts.verifyProjectLinkValid(strProject),"Verifying Project ["+strProject+"] link");

TestReporter.logStep("Clicking [" + strProject + "] link");
accounts.clickProjectLink(strProject);

TestReporter.assertTrue(accounts.verifyProjectPageIsLoaded(strAccount,strProject),"Verifying Project ["+strProject+"] page is loaded");

TestReporter.logStep("Clicking Add Document button");
accounts.clickAddDocument();

TestReporter.assertTrue(addDocumentForm.verifyFormLoaded(),"Verifying Add Document form loaded");

TestReporter.logStep("Setting file path to ["+strMsgFilePath+"]");
addDocumentForm.setFile(strMsgFilePath);

TestReporter.logStep("Selecting ["+documentType+"] as Document type");
addDocumentForm.selectDocumentType(documentType);

TestReporter.logStep("Getting document name");
documentName = addDocumentForm.getDocumentName();

TestReporter.logStep("Setting Total Budget field to ["+budget+"]");
addDocumentForm.setTotalBudget(budget);

TestReporter.logStep("Setting Total Hours field to ["+hours+"]");
addDocumentForm.setTotalHours(hours);

TestReporter.logStep("Clicking Signed checkbox");
addDocumentForm.clickSignedCheckbox();

TestReporter.logStep("Clicking Create Document button");
addDocumentForm.clickCreateDocument();

TestReporter.assertTrue(accounts.verifyDocumentExists(documentName),"Verifying Document was created");
}
}