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

bichromate.core.sTestHilitePageElementFactory 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.

The newest version!
/*
 * sTestHilitePageElementFactory.java	1.0 2013/01/23
 *
 * 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.core;

import java.io.File;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;



import bichromate.core.sTestOSInformationFactory;
import bichromate.sample.sampleWebDriverFactory;


/**
 * This class Demonstrates sTestHilitePageElementFactory().
 * 
hilite element uses java script to draw a rectangle around the element *
* @author davidwramer * @version 1.0 */ @SuppressWarnings("unused") public class sTestHilitePageElementFactory { private String orignal_style; private static final bichromateConstants bichConstants = new bichromateConstants(); /** * This method Demonstrates unHiLiteElement(). *
unHiLiteElement removes the hilite around the element *
* @param driver webDriver * @param element element to unhilite * @param color - color to unhilite * @see WebDriver * @see WebElement */ public void unHiLiteElement(WebDriver driver, WebElement element, String color) { JavascriptExecutor js = (JavascriptExecutor) driver; if(null != js){ try{ if(orignal_style.isEmpty()){ js.executeScript("arguments[0].style.border='0px'", element); }else{ js.executeScript("arguments[0].setAttribute='"+orignal_style+"'", element); } }catch(Exception e){ System.out.println("sTestHilitePageElementFactory:hiLiteElement did not execute java script for hilite element"); } } }//unHiLiteElement /** * This method Demonstrates hiLiteElement(). *
unHiLiteElement removes the hilite around the element *
* @param driver webDriver * @param element element to unhilite * @param color to hilite use redHilite = "red", yellowHilite = "yellow", greenHilite = "green", blackHilite = "black" * @see WebDriver * @see WebElement */ public void hiLiteElement(WebDriver driver, WebElement element,String color) { orignal_style = element.getAttribute("style"); JavascriptExecutor js = (JavascriptExecutor) driver; if(null != js){ try{ js.executeScript("arguments[0].style.border='3px solid red'", element); }catch(Exception e){ System.out.println("sTestHilitePageElementFactory:hiLiteElement did not execute java script for hilite element"); } } } /** * This method Demonstrates setElementBackground(). *
setElementBackground - changes the elements background color *
* @param driver webDriver * @param element element to unhilite * @param color to hilite use redHilite = "red", yellowHilite = "yellow", greenHilite = "green", blackHilite = "black" * @see WebDriver * @see WebElement */ public void setElementBackground(WebDriver driver, WebElement element,String color) { JavascriptExecutor js = (JavascriptExecutor) driver; if(null != js){ try{ js.executeScript("arguments[0].style.backgroundColor = '"+color+"'", element); }catch(Exception e){ System.out.println("sTestHilitePageElementFactory:setElementBackground failed to set the background color"); } } } // // Inner class for testing on the command line // public static class Test { @SuppressWarnings("static-access") public static void main(final String[] args) { ResourceBundle resources = null; try { resources = ResourceBundle.getBundle("common.Bichromate", Locale.getDefault()); } catch (MissingResourceException mre) { System.out.println("Bichromate.properties not found: "+ mre); System.exit(0); } sTestWebDriverFactory slwd = new sampleWebDriverFactory(resources); WebDriver driver = slwd.createBrowserWebDriver(bichConstants.localWebDriver, "",Platform.WINDOWS,"7", bichConstants.firefox,"sTest Self Test - local FireFix web driver"); // // Test the landing page code // sTestScrollIntoViewFactory siv = new sTestScrollIntoViewFactory(); sTestHilitePageElementFactory helem = new sTestHilitePageElementFactory(); driver.get("http://www.google.com"); // // Will only wait 2 minutes if the page takes that long to load. If the page // loads in 5 seconds then the wait continues // driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); // // This is the API Center link at the bottom of the page // WebElement element = driver.findElement(By.id("lst-ib")); String bgcolor = element.getCssValue("backgroundColor"); if(element !=null){ if(siv.scrollVerticalElementIntoView(driver, element)){ helem.hiLiteElement(driver, element,bichConstants.redHilite); System.out.println("highlight Test Passed"); }else{ System.out.println("highlight Test Failed"); } } try { Thread.sleep(6000); } catch (InterruptedException e) { e.printStackTrace(); } // // set the background back // helem.unHiLiteElement(driver, element,bgcolor); try { Thread.sleep(6000); } catch (InterruptedException e) { e.printStackTrace(); } driver.close(); driver.quit(); }// main }// Test } //eTestHilitePageElementFactory




© 2015 - 2024 Weber Informatics LLC | Privacy Policy