All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bichromate.baseObjectTypes.sTestTableObject Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 3.13
Show newest version
/*
 * 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
	
	@SuppressWarnings("unused")
	/**
	 * This method demonstrates parseTheTable
	 * 
verify the data is in the table *
* @param String - rowToFind of data to find in the table * @author dramer * @version 3 */ public void parseTheTable(String rowToFind){ List tableRows = null; try{ WebElement table = element; if(null == table){ myPOMLogger.enterSevereLog("sTestTableObject:pasrseTheTable never found the table"); return; } try{ tableRows = table.findElements(By.xpath("thead")); }catch(Exception e){ // Table might not have a header but just all rows } if(null == tableRows){ myPOMLogger.enterSevereLog("sTestTableObject:pasrseTheTable table has no Rows"); return; } 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 = 1; cnt < tableRows.size();cnt++) { WebElement trElement = tableRows.get(cnt); List td_collection = trElement.findElements(By.tagName("td")); int rowCnt = 0; for(WebElement tdElement : td_collection){ } } }catch(Exception e){ } }// parseTheTable public boolean findTableData(String dataToFind){ return true; } public boolean clickCell(String dataToFind){ return true; } public boolean clickCell(int row, int column){ return true; } /** * 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 /** * This method Demonstrates verifyTableContent(). This method searches the * columns in a given list of data. * * @param searchFor * - the string to find in the table * @param tr_collection * - the rows of data * @param colElements * - column element * @param matchType * - EXACT/CONTAINS * @return true of searchFor was found, false otherwise * @see WebDriver * @see WebElement * */ public boolean verifyTableContent(String searchFor, List tr_collection, String colElements, String matchType) { myPOMLogger.enterInfoLog("NUMBER OF ROWS IN THIS TABLE = " + tr_collection.size()); int row_num, col_num; row_num = 1; for (WebElement trElement : tr_collection) { List td_collection = trElement.findElements(By.xpath(colElements)); myPOMLogger.enterInfoLog("NUMBER OF COLUMNS=" + td_collection.size()); col_num = 1; for (WebElement tdElement : td_collection) { myPOMLogger.enterInfoLog("row # " + row_num + ", col # " + col_num + "text=" + tdElement.getText()); if (matchType.equals("CONTAINS")) { if (tdElement.getText().contains(searchFor)) { myPOMLogger.enterInfoLog("====FOUND CONTAINING MATCHING TEXT======"); return true; } } else { if (tdElement.getText().equals(searchFor)) { myPOMLogger.enterSevereLog("====FOUND EXACT MATCHING TEXT======"); return true; } } col_num++; } row_num++; } return false; }// verifyTableContent }//sTestTableObject




© 2015 - 2024 Weber Informatics LLC | Privacy Policy