Skip to content

Instantly share code, notes, and snippets.

@alb-i986
alb-i986 / SeleniumCommandIssue.java
Created June 10, 2020 21:21
A test showing an issue with Selenium's Keys.COMMAND.
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.junit.WireMockClassRule;
import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.util.List;
import java.util.stream.Collectors;
@alb-i986
alb-i986 / SelfRefDebuggerTest
Last active August 29, 2015 14:23
Debuggers. Inspecting variables with self references
package debugger.test;
import org.junit.Test;
/**
* To show a "weird" behavior of Intellij IDEA and Eclipse debuggers.
*
* Here we have the class SelfObj that has a field that is a self reference.
*
* Set the breakpoint at the line shown, and inspect the variable selfObj.
@alb-i986
alb-i986 / TearDownResourcesJUnit.java
Last active August 29, 2015 14:21
Tear down resources with TestNG (naive solution)
/**
* With JUnit's @Rule, any exception thrown while closing a resource
* is automatically caught, so that all of the resource-closers can be executed.
*
* Set two breakpoints, where indicated, to see it yourself.
* If the execution stops twice, that means that all of the resource-closers have been executed,
* despite the fact the first threw an exception.
*/
public class TearDownResourcesJUnit {
@alb-i986
alb-i986 / bug_git_stash_untracked.sh
Last active August 29, 2015 14:07
Script showing a bug in git: `stash save --untracked` makes an empty stash; it *looks* empty but it's not
#!/bin/bash
# Test bug in git
# if you stash untracked files only
# then the stash looks empty by `stash show -p`
# but actually `stash apply` restores the empty files.
#
REPO_DIR=/tmp/test-git-stash-bug-$( date +%F_%H%M%S )
@alb-i986
alb-i986 / ImplicitVsExplicitWaitTest.java
Created September 29, 2014 17:29
Shows a possible bug in selenium-java: looks like there exists a weird inter-dependency between explicit and implicit wait
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
@alb-i986
alb-i986 / selenium-webdriver-helper-sendKeys.java
Last active August 29, 2015 13:57
Helper method that makes sure sendKeys enters the given text fully.
/**
* Enter the text with {@link WebElement#sendKeys(CharSequence...)} and loop
* (max 50 attempts) until the text is found to have been actually fully entered.
* Needed when for some reason (maybe some JS making WebDriver lose focus from the field)
* {@link WebElement#sendKeys(CharSequence...)} does not do its job and does not send all the
* characters it was asked to.
*
* @param text the text to enter in the text field
* @param textField a text field
* @param driver
@alb-i986
alb-i986 / base.conf
Last active December 18, 2015 02:19
uWSGI conf for Django apps with virtualenv. Designed for uWSGI Emperor, for a multi-app hosting server, with separate Dev/Test/Prod machines. Following the DRY principle, the directives are split in 3 files: - /etc/uwsgi/templates/base.conf - /etc/uwsgi/templates/include/vars.ini - /etc/uwsgi/templates/include/vars_shared.ini Then, in /etc/uwsgi…
[uwsgi]
proj_name = %n
# load variables
ini = /var/local/django/%n/uwsgi/vars.ini
ini = /etc/uwsgi/templates/include/vars.ini
ini = /etc/uwsgi/templates/include/vars-shared.ini
@alb-i986
alb-i986 / supervisord conf for uWSGI Emperor + FastRouter
Last active April 24, 2018 21:51
My supervisord config for uWSGI Emperor + Fast Router. Please notice that the priority for the FastRouter must be greater than the one for the Emperor.
[program:uwsgi-emperor]
command=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites-enabled/ --pidfile /var/run/uwsgi/uwsgi-emperor.pid --auto-procname --emperor-stats-server /var/run/uwsgi/uwsgi-emperor-stats.sock
stdout_logfile=/var/log/uwsgi/%(program_name)s.log
redirect_stderr=true ; redirect proc stderr to stdout (default false)
autostart=true ; start at supervisord start (default: true)
autorestart=unexpected ; whether/when to restart (default: unexpected)
priority=998 ; the relative start priority (default 999)