Skip to content

Instantly share code, notes, and snippets.

View nmschorr's full-sized avatar
🏠
Working from home

Nancy Schorr nmschorr

🏠
Working from home
View GitHub Profile
@nmschorr
nmschorr / DismissFireFoxCrashAlert
Last active September 26, 2015 04:05
Dismiss FireFox crash alert brought on by Selenium.using JNA.
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinUser;
.......
protected static void dismissFirefoxCrashAlert() {
bLogger.info("Inside dismissFirefoxCrashAlert");
HWND hwnd = User32.INSTANCE.FindWindow (null, "Firefox"); // window title
if (hwnd == null) {
class AlertThread extends Thread { // Dismiss the Firefox crash alert
public AlertThread (String tname) {
super(tname);
}
@Override
public void run(){
System.out.println("Inside run() of AlertThread method.");
try {
Thread.currentThread();
protected WebDriver createDriver(Logger myLogger) throws AWTException, InterruptedException {
// the following 2 lines will dismiss the Windows crash alert dialog
AlertThread tAlertThread = new AlertThread("tAlertThread");
tAlertThread.start();
WebDriver localDriver = new FirefoxDriver(); // using this to see if bug goes away
localDriver.manage().timeouts().implicitlyWait(WAIT_TIME, TimeUnit.SECONDS); //for the entire test run
return localDriver;
}
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
</dependency>
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout
pattern="[%-5level] %d{yyyyMMdd-HHmmss} [%t] %M- %msg%n" />
</Console>
<RollingFile name="rollingfile" fileName="C:\Users\user\git2\SMedia\logs\smtrace.log"
filePattern="C:\Users\user\git2\SMedia\logs\smtrace-%d{yyyyMMddHHmmss}.log">
<PatternLayout>
@nmschorr
nmschorr / Imports
Last active October 23, 2015 03:19
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public static Logger createLogger() {
Logger aLogger = LogManager.getRootLogger();
aLogger.debug("\n" + "Inside createLogger - Logger is being set up. New test setup beginning.");
verificationErrors = new StringBuffer();
aLogger.info("Logger has been set up.");
return aLogger;
}
protected static void createLogFile (FirefoxProfile fp) throws Exception {
File outfile = new File(outfileName);
@BeforeClass //run once before each testsuite
public static void setUpClass() throws Exception {
gLogger = createLogger();
}
@Test
public void testDemo() throws Exception {
gLogger.info("Starting the actual new testDemo. Waiting a few seconds.");
shortTest();
}
OFF No logging
FATAL Severe errors
ERROR non-fatal errors
WARN misc warnings
INFO runtime events
DEBUG Detailed info
TRACE Most detailed
/* JavaTestFive by Nancy Schorr, 2017
Demonstrates use of apis to read a json formatted text file and store it as a JSON object for further manipulation.
Also goes to url http://jsonplaceholder.typicode.com/albums and reads the data and store it in various objects.
Thanks to https://www.java2novice.com/restful-web-services/java-client-net-url/ for some ideas in this code.
*/
package com.nmschorr;
import static java.lang.System.out;
import java.io.*;
import java.net.*;