Skip to content

Instantly share code, notes, and snippets.

View djangofan's full-sized avatar

Jon Austen djangofan

View GitHub Profile
@djangofan
djangofan / gist:9137336
Created February 21, 2014 16:22
PropertyFileHandler.bat
@echo off &SETLOCAL ENABLEDELAYEDEXPANSION
:: Functions for updating property files
ECHO Args to script: %1 %2 %3
::---------------------------------------------------
:: Create test file if it doesn't exist
::---------------------------------------------------
IF NOT EXIST test.properties (
ECHO Key1=Value1>test.properties
ECHO #Key2=Value2>>test.properties
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
LINUX:
To run in IDE:
- open terminal window and run
./jetty-server.sh
- open terminal window and run
./selenium-server.sh
- run stories in IDE
WINDOWS:
@djangofan
djangofan / dataProvider.xml
Created December 22, 2013 01:08
A .xml input file for TestNG to be parsed by XStream with Java
<suite>
<suiteName>Suite 1</suiteName>
<sauceURL>http://username-string:access-key-string@ondemand.saucelabs.com:80/wd/hub</sauceURL>
<tests>
<test>
<enabled type="java.lang.Boolean">true</enabled>
<testname type="java.lang.String">Test 1</testname>
<environment type="java.lang.String">portal1</environment>
<testlocale type="java.lang.String">Grid</testlocale>
<browser type="java.lang.String">Firefox</browser>
@djangofan
djangofan / gist:8043595
Created December 19, 2013 18:07
Run Selenium grid on XVFB
export DISPLAY=:0.0
xvfb-run --auto-servernum --server-num=0 java -jar selenium-server-standalone-2.32.0.jar >
@djangofan
djangofan / Test.java
Last active May 19, 2016 08:35
My ideas for a method to inject jQuery.js into a page for Selenium testing.
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
@djangofan
djangofan / selenium_element_exists.java
Created November 15, 2013 18:10
Example of elementExists method in Selenium Java
public boolean elementExists( By locator ) {
WebElement foo = null;
try {
foo = this.getElementByLocator( locator, 10 );
} catch ( TimeoutException te) {
System.out.println("There was a timeout looking for element: " + locator.toString() );
//Swallow exception: ExceptionUtils.getMessage(te);
return false;
} catch ( ElementNotVisibleException env ) {
System.out.println("The element was found but is invisible: " + locator.toString() );
@djangofan
djangofan / ideas.java
Last active December 28, 2015 08:59
Selenium ideas
Example, JQuery in Selenium, by injection into driver:
https://github.com/Nthalk/SeleniumJQuery/blob/master/example/com/anteambulo/SeleniumJQuery/example/Example.java
HtmlUnitDriver drv = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);
drv.setJavascriptEnabled(true);
try {
jQueryFactory jq = new jQueryFactory();
@djangofan
djangofan / CSVDataProvider.java
Last active December 25, 2015 19:29
CSV DataProvider for TestNG in Java
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.Converter;
import au.com.bytecode.opencsv.CSVReader;
public class CsvDataProvider implements Iterator {
/**
* @testng.data-provider name="CsvDataProvider"
* @param method the method the TestNg passes to you
@djangofan
djangofan / StringSimilarityScore.java
Last active December 25, 2015 17:59
String similarity score using Java
public List<char[]> bigram(String input) {
ArrayList<char[]> bigram = new ArrayList<char[]>();
for (int i = 0; i < input.length() - 1; i++) {
char[] chars = new char[2];
chars[0] = input.charAt(i);
chars[1] = input.charAt(i+1);
bigram.add(chars);
}
return bigram;
}