bichromate.baseObjectTypes.sTestTableObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Bichromate Show documentation
Show all versions of Bichromate Show documentation
Java, Selenium, Appium, Winium, Extend, and TestNG automated testing framework. Bichromate integrates the best of these frameworks and takes automation to the next level. With Bichromate there is one function call that builds any type of Web,IOS Mobile, Android, and Windows App driver on any platform (Windows, Mac, Linux). From Local web drivers, to SauceLabs, Browserstack, and Selenium grid. Build data driven tests is never easier.
Bichromate also gives you built in Factories that, access DBs, Video Capture, FTP, POM Generation, Hilite element.
/*
* sTestTableObject.java 1.0 2017/06/01
*
* Copyright (c) 2001 by David Ramer, Inc. All Rights Reserved.
*
* David Ramer grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to David Ramer.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. David Ramer AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL David Ramer OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF DRamer HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
package bichromate.baseObjectTypes;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import bichromate.core.pageObjectModelLogFactory;
public class sTestTableObject extends sTestBaseObjectType {
public sTestTableObject(WebDriver driver,WebElement element, String PageObject,pageObjectModelLogFactory myLogger){
myDriver = driver;
this.element = element;
pageObjectName = new String(PageObject);
myPOMLogger = myLogger;
}//sTestButtonObject
public boolean findTableData(String dataToFind){
boolean foundElement = false;
List tableRows = null;
try{
WebElement table = element;
if(null == table){
myPOMLogger.enterSevereLog("findTableData:pasrseTheTable never found the table");
return foundElement;
}
try{
tableRows = table.findElements(By.xpath("tbody/tr"));
}catch(Exception e){ // Table might not have a header but just all rows
return foundElement;
}
if(null == tableRows){
myPOMLogger.enterSevereLog("findTableData:pasrseTheTable table has no Rows");
return foundElement;
}
myPOMLogger.enterInfoLog("NUMBER OF ROWS IN THIS TABLE = "+tableRows.size());
//
// Invoice table has 2 thead elements we start at the second one
//
for(int cnt = 0; cnt < tableRows.size();cnt++) {
WebElement trElement = tableRows.get(cnt);
List td_collection = trElement.findElements(By.xpath("td"));
for(WebElement tdElement : td_collection){
String cellText = new String(tdElement.getText());
if(cellText.equalsIgnoreCase(dataToFind)){
return true;
}
}
}
}catch(Exception e){
myPOMLogger.enterInfoLog("findTableData:pasrseTheTabl Failed to parse the table");
}
return foundElement;
}
public boolean clickCell(String dataToFind){
boolean foundElement = false;
List tableRows = null;
try{
WebElement table = element;
if(null == table){
myPOMLogger.enterSevereLog("findTableData:pasrseTheTable never found the table");
return foundElement;
}
try{
tableRows = table.findElements(By.xpath("tbody/tr"));
}catch(Exception e){ // Table might not have a header but just all rows
return foundElement;
}
if(null == tableRows){
myPOMLogger.enterSevereLog("findTableData:pasrseTheTable table has no Rows");
return foundElement;
}
myPOMLogger.enterInfoLog("NUMBER OF ROWS IN THIS TABLE = "+tableRows.size());
//
// Invoice table has 2 thead elements we start at the second one
//
for(int cnt = 0; cnt < tableRows.size();cnt++) {
WebElement trElement = tableRows.get(cnt);
List td_collection = trElement.findElements(By.xpath("td"));
for(WebElement tdElement : td_collection){
String cellText = new String(tdElement.getText());
if(cellText.equalsIgnoreCase(dataToFind)){
tdElement.click();
return true;
}
}
}
}catch(Exception e){
myPOMLogger.enterInfoLog("findTableData:pasrseTheTabl Failed to parse the table");
}
return foundElement;
}
public boolean clickCell(int row, int column){
boolean foundElement = false;
List tableRows = null;
try{
WebElement table = element;
if(null == table){
myPOMLogger.enterSevereLog("findTableData:pasrseTheTable never found the table");
return foundElement;
}
try{
tableRows = table.findElements(By.xpath("tbody/tr"));
}catch(Exception e){ // Table might not have a header but just all rows
return foundElement;
}
if(null == tableRows){
myPOMLogger.enterSevereLog("findTableData:pasrseTheTable table has no Rows");
return foundElement;
}
myPOMLogger.enterInfoLog("NUMBER OF ROWS IN THIS TABLE = "+tableRows.size());
//
// Invoice table has 2 thead elements we start at the second one
//
for(int cnt = 0; cnt < tableRows.size();cnt++) {
WebElement trElement = tableRows.get(cnt);
List td_collection = trElement.findElements(By.xpath("td"));
int ColCount = 0;
for(WebElement tdElement : td_collection){
String cellText = new String(tdElement.getText());
if(row == cnt && column == ColCount){
tdElement.click();
return true;
}
ColCount++;
}
}
}catch(Exception e){
myPOMLogger.enterInfoLog("findTableData:pasrseTheTabl Failed to parse the table");
}
return foundElement;
}
/**
* This method demonstrates coudoesTableHaveAHeaderntRows
*
verify if the table has a header
*
* @return boolean - true if table has a header
* @author dramer
* @version 3.0
*/
public boolean doesTableHaveAHeader(){
if(null == element){
myPOMLogger.enterSevereLog("sTestTableObject:countRows never found the table");
return false;
}
try{
WebElement header = element.findElement(By.xpath("thead/tr"));
if(null != header)
return true;
else
return false;
}catch(Exception e){
myPOMLogger.enterSevereLog("sTestTableObject:countColumns table has no header element");
}
return false;
}//DoesTableHaveAHeader
/**
* This method demonstrates doesTableHaveAFooter
*
verify if the table has a header
*
* @return boolean - true if table has a footer
* @author dramer
* @version 3.0
*/
public boolean doesTableHaveAFooter(){
if(null == element){
myPOMLogger.enterSevereLog("sTestTableObject:doesTableHaveAFooter never found the table");
return false;
}
try{
WebElement header = element.findElement(By.xpath("tfooter/tr"));
if(null != header)
return true;
else
return false;
}catch(Exception e){
myPOMLogger.enterSevereLog("sTestTableObject:doesTableHaveAFooter table has no footer element");
}
return false;
}//doesTableHaveAFooter
/**
* This method demonstrates countRows
*
verify the search button is enabled
*
* @return int - number of rows
* @author dramer
* @version 3.0
*/
public int countRows(){
if(null == element){
myPOMLogger.enterSevereLog("sTestTableObject:countRows never found the table");
return 0;
}
List rows = element.findElements(By.xpath("tbody/tr"));
if(null == rows){
myPOMLogger.enterSevereLog("sTestTableObject:countRows never found the row element");
return 0;
}
return(rows.size());
}//CountRows
public int getColumnIDByName(String columnName){
if(null == element){
myPOMLogger.enterSevereLog("sTestTableObject:getColumnIDByName never found the table");
return 0;
}
int column_num =0;
WebElement header = element.findElement(By.xpath("thead/tr"));
List columnNames = header.findElements(By.xpath("th"));
for (WebElement column : columnNames) {
//System.out.println(column.getText());
if(column.getText().contains(columnName)){
return column_num;
}
column_num++;
}
return -1;
}//CountRows
/**
* This method demonstrates CountColumns
*
counts the number of columns in the table
*
* @return int - number of columns
* @author dramer
* @version 3.0
*/
public int countColumns(){
WebElement header = null;
if(null == element){
myPOMLogger.enterSevereLog("sTestTableObject:countColumns never found the table");
return 0;
}
try{
header = element.findElement(By.xpath("thead/tr"));
}catch(Exception e){
myPOMLogger.enterSevereLog("sTestTableObject:countColumns table has no header element");
}
//
// It is possible that the table did not define a thead or a tfoot.
// Take the first row and count that as the header and count the coulmns
//
if(null == header){
try{
header = element.findElement(By.xpath("tbody/tr"));
}catch(Exception e){
myPOMLogger.enterSevereLog("sTestTableObject:countColumns table has no rows");
return 0;
}
}
if(null == header){
myPOMLogger.enterSevereLog("sTestTableObject:countColumns never found a header or any columns in the table");
}else{
try{
List columns = header.findElements(By.xpath("th"));
return(columns.size());
}catch(Exception e){
myPOMLogger.enterSevereLog("sTestTableObject:countColumns never found the column element");
return 0;
}
}
return 0;
}//CountRows
}//sTestTableObject