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

bichromate.dataStore.sTestCronData 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
package bichromate.dataStore;

import java.awt.Color;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;

import org.testng.IResultMap;
import org.testng.ITestContext;
import org.testng.TestListenerAdapter;
import org.testng.TestNG;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;

import bichromate.core.sTestOSInformationFactory;

@SuppressWarnings("unused")
public class sTestCronData extends TestListenerAdapter{

	public String title;
	public String description;
	public String test;
	public String day;  // Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, All, Weekend, MWF,
	public String timeToRun; // hh:mm:ss
	public boolean testRunning = false;
	public boolean runToday = false;
	public boolean hasFailures = false;
	public IResultMap results = null;
	private JTextPane  testOutput = null;
	private sTestOSInformationFactory path = null;
	
	private TestNG testng = null;
	
	public sTestCronData() {
		
		title = new String("");
		description  = new String("");
		test  = new String("");
		day  = new String("");
		timeToRun  = new String("");
		testng = new TestNG();
		
		path = new sTestOSInformationFactory();
	}
	public sTestCronData(String title, String description, String test) {
		
		this.title = new String(title);
		this.description  = new String(description);
		this.test  = new String(test);
		testng = new TestNG();
	}
	 /**
	 * This method sTestCronData().
	 * 
This method creates cron data from the input data *
*
* @param outputPanel to show status on the U/I * @param title of the test * @param description of the test * @param test test to execute something like X.Y.test * @author davidwramer * @version 1.0 */ public sTestCronData(JTextPane outputPanel,String title, String description, String test) { this.testOutput = outputPanel; this.title = new String(title); this.description = new String(description); this.test = new String(test); testng = new TestNG(); } /** * This method executeTest(). *
This method executes the test class *
*
* @author davidwramer * @version 1.0 */ public void executeTest(){ @SuppressWarnings("rawtypes") Class sTestTest; //try{ // sTestTest = Class.forName(test); sTestTest = buildTheTestClass(test); testng.setTestClasses(new Class[] {/* com.test.visitorSite.releaseNightTest */sTestTest}); testng.addListener(this); System.out.println("testNG running test: "+ test); testng.run(); // } catch (ClassNotFoundException e) { // e.printStackTrace(); //if(testOutput != null) appendToPane(testOutput,"sTestCronData : executeTest Failed: "+ test, Color.RED); //} }// executeTest /** * This method executeFromXLS(). *
This method executes the test from a XML file *
*
*
suite name="TmpSuite" *
test name="TmpTest" *
classes *
class name="test.failures.Child" *
classes *
test *
suite *
* @param suiteName - name of the test * @param testName - class to execute * @param testClass - test class to execute * @author davidwramer * @version 1.0 */ public void executeFromXLS(String suiteName, String testName, String testClass){ XmlSuite suite = new XmlSuite(); suite.setName(suiteName); XmlTest test = new XmlTest(suite); test.setName(testName); List classes = new ArrayList(); classes.add(new XmlClass(testClass)); test.setXmlClasses(classes) ; List suites = new ArrayList(); suites.add(suite); TestNG tng = new TestNG(); tng.addListener(this); tng.setXmlSuites(suites); tng.run(); }// executeFromXLS /** * This method onStart(). *
Listner for the testNG test *
*
* @param testContext - testing results * @author davidwramer * @version 1.0 */ public void onStart(ITestContext testContext){ System.out.println("TestStarting: "+ test); if(testOutput != null) appendToPane(testOutput,"TestStarting: "+ test, Color.GREEN); testRunning = true; results = null; hasFailures = false; runToday = true; } /** * This method onFinish(). *
Listner for the testNG test *
*
* @param testContext - testing results * @author davidwramer * @version 1.0 */ public void onFinish(ITestContext testContext){ System.out.println("TestCompleted: "+ test); if(testOutput != null) appendToPane(testOutput,"TestCompleted: "+ test, Color.GREEN); runToday = true; testRunning = false; results = testContext.getFailedTests(); if(testOutput != null) appendToPane(testOutput,results.toString(), Color.GREEN); hasFailures = testng.hasFailure(); if(testOutput != null) { if(hasFailures){ appendToPane(testOutput,test +": FAILED", Color.RED); }else{ appendToPane(testOutput,test +": PASSED", Color.GREEN); } } } private Class buildTheTestClass(String test){ File file = new File(path.getTestClassDirectory()); Class testClass = null; ClassLoader cl = null; try { // Convert File to a URL URL url = file.toURI().toURL();// file:/c:/myclasses/ URL[] urls = new URL[]{url}; // Create a new class loader with the directory cl = new URLClassLoader(urls); // Load in the class; MyClass.class should be located in // the directory file:/c:/myclasses/com/mycompany testClass = cl.loadClass(test); } catch (MalformedURLException e) { e.printStackTrace(); if(testOutput != null) appendToPane(testOutput,"buildTheTestClass : failed to find test class: "+ test, Color.RED); } catch (ClassNotFoundException e) { e.printStackTrace(); if(testOutput != null) appendToPane(testOutput,"buildTheTestClass : Failed to find test class: "+ test, Color.RED); } return testClass; }// buildTheTestClass /** * This function appendToPane(). *
This function appends text, and text color to the JTextPane *
*
* @param tp * @param msg * @param c * @return None. * @exception None. * @author davidwramer * @version 1.0 */ private void appendToPane(JTextPane tp, String msg, Color c) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED); int len = tp.getDocument().getLength(); tp.setCaretPosition(len); tp.setCharacterAttributes(aset, false); tp.replaceSelection("\n"+msg); } }// sTestCronData




© 2015 - 2024 Weber Informatics LLC | Privacy Policy