Skip to content

Instantly share code, notes, and snippets.

View krmahadevan's full-sized avatar
☠️
Threading ain't hard… Locking is!

Krishnan Mahadevan krmahadevan

☠️
Threading ain't hard… Locking is!
View GitHub Profile
##
## Bundle of CA Root Certificates
##
## Certificate data from Mozilla as of: Fri Apr 29 06:21:56 2016
##
## This is a bundle of X.509 certificates of public Certificate Authorities
## (CA). These were automatically extracted from Mozilla's root certificates
## file (certdata.txt). This file can be found in the mozilla source tree:
## http://hg.mozilla.org/releases/mozilla-release/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt
##
@krmahadevan
krmahadevan / GroupPrinter.java
Last active July 2, 2016 08:41
A Sample Suite Listener which can retrieve the names of all methods that are part of a group.
public static class GroupPrinter implements ISuiteListener {
@Override
public void onStart(ISuite suite) {
String groupName = System.getProperty("groupName", "all");
List<ITestNGMethod> allMethods = suite.getAllMethods();
List<ITestNGMethod> filteredMethods = new ArrayList<>();
for (ITestNGMethod method : allMethods) {
if (Arrays.asList(method.getGroups()).contains(groupName)) {
filteredMethods.add(method);
@krmahadevan
krmahadevan / Output.json
Created April 9, 2016 14:06
Sample BMP Output
{
"log":{
"version":"1.2",
"creator":{
"name":"BrowserMob Proxy",
"version":"2.1.0-beta-4-littleproxy",
"comment":""
},
"browser":{
"name":"Chrome",
@krmahadevan
krmahadevan / AddingElementsRuntimeViaJavaScript.java
Created March 4, 2016 04:37
A sample that shows how to weave a html page in runtime using Javascript and view it on a browser. This technique can be used in cases where one has to open a saved page in a remote execution environment (such as SauceLabs)
package organized.chaos.webdriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.IOException;
@krmahadevan
krmahadevan / SuiteLevelWebdriverSample
Created October 25, 2015 05:34
This example shows how to work with web driver instances that were created at suite level
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.ISuite;
import org.testng.ISuiteListener;
import org.testng.Reporter;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
@krmahadevan
krmahadevan / SkipRestOfTheTestsIfFailuresAreSeen.java
Created September 26, 2015 04:59
This example shows how to leverage a TestNG listener and trigger test skips if one of the test failed.
@Listeners (SkipRestOfTheTestsIfFailuresAreSeen.AbortRemainingTestsListener.class)
public class SkipRestOfTheTestsIfFailuresAreSeen {
@Test
public void testMethod1() {
Reporter.log("testMethod1() being executed", true);
}
@Test
public void testMethod2() {
@krmahadevan
krmahadevan / MethodInterceptorDemo.java
Created February 25, 2013 10:25
This is a sample that shows how to use "IMethodInterceptor" in TestNG to order your tests. In this example I am ordering the tests based on their method names.
package org.rationale.emotions;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.testng.IMethodInstance;
import org.testng.IMethodInterceptor;
import org.testng.ITestContext;
import org.testng.annotations.Listeners;
@krmahadevan
krmahadevan / NodeShutDownServlet.java
Created January 27, 2013 18:43
A simple servlet which basically issues a System.exit() when invoked. This servlet would have to be injected into the node [not the Grid] so that it can help in terminating the node.
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* A simple servlet which basically issues a System.exit() when invoked.
* This servlet would have to be injected into the node [not the Grid] so that it can help in terminating the node.
@krmahadevan
krmahadevan / MyRemoteProxy.java
Created January 27, 2013 18:27
This is a custom Proxy. This proxy when injected into the Grid, starts counting unique test sessions. After "n" test sessions, the proxy unhooks the node gracefully from the grid and self terminates gracefully. The number of unique sessions is controlled via a properties file : "mygrid.properties".
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.internal.Registry;
@krmahadevan
krmahadevan / JarSpawner.java
Last active September 23, 2017 16:11
This is a standalone java application that can continuously monitor a another JVM and if the JVM crashes or exits it can re-spawn it again.
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecuteResultHandler;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteException;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.exec.ShutdownHookProcessDestroyer;