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

bichromate.baseObjectTypes.sTestBaseObjectType 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
/*
 * sTestBaseObjectType.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.MissingResourceException;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Point;
//import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

import bichromate.core.pageObjectModelLogFactory;
import bichromate.core.sTestHilitePageElementFactory;
import bichromate.core.sTestScrollIntoViewFactory;


public class sTestBaseObjectType {
	protected WebDriver myDriver = null;
	protected pageObjectModelLogFactory myPOMLogger = null;
	protected WebElement element = null;
	protected String pageObjectName = null;
	private sTestScrollIntoViewFactory  scrollIntoView = null;
	private sTestHilitePageElementFactory hiliteElement = null;
	private String bgcolor;
	private String hiliteColor = "ff0008";
	
	public sTestBaseObjectType(){ 
		scrollIntoView = new sTestScrollIntoViewFactory();
		hiliteElement = new sTestHilitePageElementFactory();
		
		
	}
	/**
	 * This method demonstrates isElementVisibleOnThePage()
	 * 
Returns the Point of the element on the page *
* @return boolean * @author dramer * @version 3.0 */ public boolean isElementVisibleOnThePage(){ try{ Point coordinate = element.getLocation(); Long scrollYValue = 0L,scrollXValue = 0L; Dimension d = myDriver.manage().window().getSize(); JavascriptExecutor executor = (JavascriptExecutor) myDriver; scrollYValue = (Long) executor.executeScript("return window.pageYOffset;"); scrollXValue = (Long) executor.executeScript("return window.pageXOffset;"); int xcordi = coordinate.getX(); int ycordi = coordinate.getY(); if((d.height + scrollYValue)< ycordi) return false; if((d.width + scrollXValue) < xcordi) return false; return true; }catch(Exception e){ myPOMLogger.enterSevereLog("sTestBaseObjectType:isElementVisibleOnThePage failed to get scroll position"); } return false; } /** * This method demonstrates getCoordinatesOfElement() *
Returns the Point of the element on the page *
* @return Point * @author dramer * @version 3.0 */ public Point getCoordinatesOfElement(){ Point coordinate = element.getLocation(); return coordinate; //int xcordi = coordinate.getX(); //int ycordi = coordinate.getY(); } public void setHiliteColor(String color){ hiliteColor = new String(color); } /** * This method demonstrates hiliteElement(). *
Hilite the element *
* @author dramer * @version 3.0 */ public void hiliteElement(){ bgcolor = element.getCssValue("backgroundColor"); hiliteElement.hiLiteElement(myDriver, element, hiliteColor); }//hiliteElement /** * This method demonstrates unHiliteElement(). *
Hilite the element *
* @author dramer * @version 3.0 */ public void unHiliteElement(){ hiliteElement.unHiLiteElement(myDriver, element, bgcolor); }//unHiliteElement public void setElementBackground(String color){ bgcolor = element.getCssValue("backgroundColor"); hiliteElement.setElementBackground(myDriver, element, color); }//hiliteElement /** * This method demonstrates resetElementBackground(). *
Hilite the element *
* @author dramer * @version 3.0 */ public void resetElementBackground(){ hiliteElement.setElementBackground(myDriver, element, bgcolor); }//hiliteElement /** * This method demonstrates srollIntoView(). *
scrolls the element into view *
* @author dramer * @version 3.0 */ public void srollIntoView(){ int count = 0; boolean didNotScroll = true; while(!isElementVisibleOnThePage() || !(++count < 20)){ scrollIntoView.scrollVerticalElementIntoView(myDriver, element); didNotScroll = false; } // // Could not scroll element into view, click the element // if(didNotScroll){ click(); // will bring into focus }else{ scrollIntoView.scrollVerticalElementIntoView(myDriver, element); } }//srollIntoView /** * This method demonstrates isEnabled(). *
verify the search button is enabled *
* @return boolean - true if element is enabled * @author dramer * @version 3.0 */ public boolean IsEnabled(){ try{ if(null != element){ if(element.isEnabled()){ return true; }else{ return false; } }else{ myPOMLogger.enterSevereLog(pageObjectName +" : IsEnabled element not found "); } }catch (Exception e){ myPOMLogger.enterSevereLog(pageObjectName +" : IsEnabled element not found "); } return false; }//sTestButtonObjectEnabled /** * This method demonstrates IsDisplayed(). *
verify the Object is displayed and not hidden *
* @return boolean - true if element is displayed * @author davidwramer * @version 3.0 */ public boolean IsDisplayed() { try{ if(null != element){ if(element.isDisplayed()){ return true; }else{ return false; } }else{ myPOMLogger.enterSevereLog(pageObjectName +" : IsDisplayed element not found "); } }catch (Exception e){ myPOMLogger.enterSevereLog(pageObjectName +" : IsDisplayed element not found "); } return false; }//IsDisplayed /** * This method demonstrates IsSelected(). *
verify the search button is displayed *
* @return boolean - true if element is selected * @author dramer * @version 3.0 */ public boolean IsSelected() { try{ if(null != element){ if(element.isSelected()){ return true; }else{ return false; } }else{ myPOMLogger.enterSevereLog(pageObjectName +" : IsSelected element not found "); } }catch (Exception e){ myPOMLogger.enterSevereLog(pageObjectName +" : IsSelected element not found "); } return false; }//IsSelected /** * This method demonstrates GetTagName(). *
return the tagName of the element *
* @return String tagName * @author dramer * @version 3.0 */ public String GetTagName() { String tagName = null; try{ if(null != element){ tagName = new String(element.getTagName()); }else{ myPOMLogger.enterSevereLog(pageObjectName +" : IsSelected element not found "); } }catch (Exception e){ myPOMLogger.enterSevereLog(pageObjectName +" : IsSelected element not found "); } return tagName; }//GetTagName /** * This method demonstrates getText(). *
return the text of the element *
* @return String - textName * @author davidwramer * @version 3.0 */ public String getText() { String text = null; try{ if(null != element){ text = new String(element.getText()); }else{ myPOMLogger.enterSevereLog(pageObjectName +" : IsSelected element not found "); } }catch (Exception e){ myPOMLogger.enterSevereLog(pageObjectName +" : IsSelected element not found "); } // // Strip all new lines and returns // String finalText = new String(text.replaceAll("\r", "")); finalText = new String (finalText.replaceAll("\n", "")); return finalText; }//GetText /** * moveToElement() *
What ever has the current focus move the focus to this element * @see RemoteWebDriver * @author DRamer * @version 3.0 */ public void moveToElement(){ if(null != myDriver){ Actions action = new Actions(myDriver); action.moveToElement(element).perform(); } }//moveToElement /** * waitUnitlVisible() *
This function waits until the visibility of an element * @param time - time in seconds to wait * @see RemoteWebDriver * @author DRamer * @version 1.0 */ public void waitUntilVisible(int time){ WebDriverWait wait; wait = new WebDriverWait(myDriver, time); wait.until(ExpectedConditions.visibilityOf(element)); }//waitUntilVisible /** * fluentWait() *
This function is used to track AJAX functions that build pages, and you have to wait for the element to be visible * @param polling - time in seconds * @param timeOut - time in seconds * @see RemoteWebDriver */ public void fluentWait(int polling,int timeOut ){ @SuppressWarnings("deprecation") Wait wait = new FluentWait(myDriver) .withTimeout(polling, TimeUnit.SECONDS) .pollingEvery(timeOut, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class); if(null != wait){ wait.until(ExpectedConditions.visibilityOf(element)); }else{ myPOMLogger.enterSevereLog(pageObjectName +" : fluentWait failed to initialize "); } }//fluentWait /** * waitUntilPrecenseOfElementLocated() *
This function waits until the presence Of Element Located * @param time - wait time * @see RemoteWebDriver * @author DRamer * @version 1.0 */ public void waitUntilPrecenseOfElementClickable(int time){ WebDriverWait wait; wait = new WebDriverWait(myDriver, time); wait.until(ExpectedConditions.elementToBeClickable(element)); }//waitUntilPrecenseOfElementLocated /** * method dragAndDrop() * Drag and drop using Selenium Actions * @param from = web element * @param to = web element * @see Actions */ public void dragAndDrop(WebElement from, WebElement to){ (new Actions(myDriver)).dragAndDrop(from, to).perform(); }//dragAndDrop /** * This method demonstrates click(). *
Click the element *
* @return boolean - true if clicked * @author dramer * @version 3.0 */ public boolean click() { try{ if(null != element){ element.click(); return true; }else{ myPOMLogger.enterSevereLog(pageObjectName +": click element not found "); } }catch (Exception e){ myPOMLogger.enterSevereLog(pageObjectName +": click element not found "); } return false; }//click /** * This method demonstrates doubleClick(). *
Click the element *
* @author dramer * @version 3.0 */ public void doubleClick() { if(null != myDriver){ Actions action = new Actions(myDriver); action.doubleClick(element).perform(); } }//click /** * This method demonstrates rightClick(). *
Click the element *
* @author dramer * @version 3.0 */ public void rightClick() { Actions action = null; if(null != myDriver){ action = new Actions(myDriver); action.contextClick(element).perform(); } }//rightClick }//sTestBaseObjectType




© 2015 - 2024 Weber Informatics LLC | Privacy Policy