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

bichromate.tools.sTestDOMParser 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
/*
 * sTestDOMParser.java	1.0 2018/07/05
 *
 * 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.
 * 
 * http://www.tutorialspoint.com/java_xml/java_dom_parse_document.htm
 * 
 * 
 */



package bichromate.tools;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Scanner;

import javax.swing.JFileChooser;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.jsoup.Jsoup;
import org.jsoup.select.Elements;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
//import org.w3c.dom.*;
//import org.xml.sax.SAXException;
import org.xml.sax.SAXException;

import bichromate.core.sTestOSInformationFactory;
import bichromate.dataStore.sTestDOMElementStore;
import bichromate.dataStore.sTestDOMObjects;


//import javax.swing.JFileChooser;
//import javax.xml.parsers.*;
//import java.io.*;



public class sTestDOMParser {
	
	private List elementList = new ArrayList();
	private String pageURL = null;
	private String pageTitle = null;
	private sTestOSInformationFactory path = null;
	private String pomFileDirectory = null;
	private static ResourceBundle resources;	
	private String fullDate;
	int aCount = 1;
	int tabLinkCount = 1;
	int selectCount = 1;
	int tableCount = 1;
	int textAreaCount = 1;
	int checkboxCount = 1;
	int buttonCount = 1;
	int rangeCount = 1;
	int radioButtonCount = 1;
	 static
	 {
			try
			{
				resources = ResourceBundle.getBundle("tools.sTestPOMFactory",Locale.getDefault());
			} catch (MissingResourceException mre) {
				System.out.println("sTestPOMFactory.properties not found: "+mre);
				System.exit(0);
			}
	 }
	
	public sTestDOMParser(){
		
		fullDate = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(Calendar.getInstance().getTime());

		
		
		path = new sTestOSInformationFactory();
		
		//
		// POM file directory
		//
		pomFileDirectory = new String(resources.getString("sTestPOMFactory.pomFileDirectory"));
	}
	/**
     * This method Demonstrates findDOMFile().
     * This method returns the File handle the the DOM file to parse
     * @return File
     * @author dramer
     * @version 1.0
     */
	@SuppressWarnings("unused")
	private File findDOMFile(){
		/*
		// a jframe here isn't strictly necessary, but it makes the example a little more real
	    JFrame frame = new JFrame("InputDialog Example #1");

	    // prompt the user to enter their name
	    String name = JOptionPane.showInputDialog(frame, "Properties File Name, no extension!!!");
	    */
		JFileChooser fileChooser = new JFileChooser();
		if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
		  File file = fileChooser.getSelectedFile();
		  String name = new String(file.getName());
		  System.out.println("DOM file to parse: "+name );
		  return file;
		} else{
			return null;
		}
	}//findDOMFile
	@SuppressWarnings("unused")
	private void readXMLFile(File theXMLFile) throws ParserConfigurationException, SAXException, IOException{
		
		 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
         Document doc = dBuilder.parse(theXMLFile);
         doc.getDocumentElement().normalize();
         System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
         NodeList nList = doc.getElementsByTagName("student");
         System.out.println("----------------------------");
         
         for (int temp = 0; temp < nList.getLength(); temp++) {
            Node nNode = nList.item(temp);
            System.out.println("\nCurrent Element :" + nNode.getNodeName());
         }
	}
	public void selfTest(){
		
		String webPage = "http://www.bichromate.org/seleniumTestPage.html";
		pageURL = new String(webPage);
		try {
			URL url = new URL(webPage);
			parseURL(url);
		} catch (MalformedURLException e) {
			
			
		}
		//
		// JSoup does not find all elements on the page
		//
		//pasrseURL("http://www.bichromate.org/tableTest.html");
		//
		// Build the properties file
		//
		//buildPropertiesFile();
	}
	// 
	private String extractMinValue(String line){
		String minValue = "";
		if(line.contains("min=")){
			char quote = line.charAt( line.indexOf("min=")+4);
			boolean quoted = false;
			if(quote == "\"".charAt(0)){
				quoted = true;
			}
			if(quoted){
				int min = line.indexOf("min=")+5;
				String subString = new String(line.substring(min));
				int lastQuote = subString.indexOf("\"")+1;
				minValue = new String(subString.substring(0, lastQuote));
			}else{
				int min = line.indexOf("min=")+4;
				String subString = new String(line.substring(min));
				int lastQuote = subString.indexOf(" ");
				if(lastQuote == -1){
					lastQuote = subString.indexOf(">");
				}
				if(lastQuote > 1)
					minValue = new String(subString.substring(0, lastQuote));
			}
		}
		return minValue;
	}
	private String extractMaxValue(String line){
		String maxValue = "";
		if(line.contains("max=")){
			char quote = line.charAt( line.indexOf("max=")+4);
			boolean quoted = false;
			if(quote == "\"".charAt(0)){
				quoted = true;
			}
			if(quoted){
				int max = line.indexOf("max=")+5;
				String subString = new String(line.substring(max));
				int lastQuote = subString.indexOf("\"")+1;
				maxValue = new String(subString.substring(0, lastQuote));
			}else{
				int max = line.indexOf("max=")+4;
				String subString = new String(line.substring(max));
				int lastQuote = subString.indexOf(" ");
				if(lastQuote == -1){
					lastQuote = subString.indexOf(">");
				}
				if(lastQuote > 1)
					maxValue = new String(subString.substring(0, lastQuote));
			}
		}
		return maxValue;
	}
	// 
	private String extractValue(String line){
		
		String value = "";
		if(line.contains("value=")){
			char quote = line.charAt( line.indexOf("value=")+5);
			boolean quoted = false;
			if(quote == "\"".charAt(0)){
				quoted = true;
			}
			if(quoted){
				int max = line.indexOf("value=")+6;
				String subString = new String(line.substring(max));
				int lastQuote = subString.indexOf("\"")+1;
				value = new String(subString.substring(0, lastQuote));
			}else{
				int max = line.indexOf("value=")+5;
				String subString = new String(line.substring(max));
				int lastQuote = subString.indexOf(" ");
				if(lastQuote == -1){
					lastQuote = subString.indexOf(">");
				}
				if(lastQuote > 1)
					value = new String(subString.substring(0, lastQuote));
			}
		}
		
		return value;
	}
	//