Skip to content

Instantly share code, notes, and snippets.

View azakordonets's full-sized avatar

Andrew Zakordonets azakordonets

View GitHub Profile
@azakordonets
azakordonets / createFileInDirectory.java
Created May 22, 2014 09:23
This method allow you to create file in specific folder under your project root. If you want to to save it somewhere on your computer, you can use "user.home" instead of "user.dir"
// get System properties :
Properties properties = System.getProperties();
// get Operating System home directory
String home = properties.get("user.dir").toString();
// get Operating System separator
String separator = properties.get("file.separator").toString();
// your directory name
String directoryName = "directoryName";
// your file name
String fileName = "filename";
@azakordonets
azakordonets / RetryStrategy.md
Last active August 29, 2015 14:01
Class for proper handling of retrying things to do

This class gives you nice way of retrying some action several times to make sure that either works or not. Here's an example of the code where this class can be used :

/**
	 * Get value of an element using id
	 * 
	 * @param id				the location of the element
	 * @param attribute			name of an attribute
	 * @return attribute value	value that was in attribute
	 */
	public String getValueFromId(String id, String attribute) throws Exception {
@azakordonets
azakordonets / WaitForPageToLoad.java
Created June 2, 2014 10:17
This method allows you to properly wait for page in load with WebDriver
public void waitForPageToLoad() {
Wait<WebDriver> wait = new WebDriverWait(manager.getDriver(), 30);
wait.until(new Function<WebDriver, Boolean>() {
public Boolean apply(WebDriver driver) {
System.out.println("Current Window State : "
+ String.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState")));
return String
.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState"))
.equals("complete");
}
public int randomIntGenerator(int minimum, int maximum) {
Random rn = new Random();
return rn.nextInt(maximum - minimum) + minimum;
}
public void selectFromDropDownWithHover(String menuTitle, String menuItem, String locatorType) throws Exception {
Actions actions = new Actions(manager.getDriver());
//first we find the menu title on which we will hover mouse cursor
WebElement menuHoverLink = findElementByLocator(locatorType, menuTitle);
//now we hover it with mouse
actions.moveToElement(menuHoverLink).perform();
//let's find our menu item
WebElement menuItemElement = findElementByLocator(locatorType, menuItem);
actions.moveToElement(menuItemElement);
actions.click().build().perform();
/**
* A convenience method that performs click-and-hold at the location of the source element, moves by a given offset, then releases the mouse.
* @param slider webElement
* @param xOffset - horizontal move offset. Positive value means moving to the right, negative - to the left
* @param yOffset - vertical move offset. Positive value means moving up, negative - down
* @throws Exception
*/
public void dragAndDrop(WebElement slider, int xOffset, int yOffset) throws Exception {
Actions moveSlider = new Actions(driver);
Action action = moveSlider.clickAndHold(slider)
public void dragAndDrop2(WebElement element, int xOffset, int yOffset) throws Exception {
Actions builder = new Actions(driver;
Action dragAndDrop = builder.dragAndDropBy(element, xOffset, yOffset) .build();
dragAndDrop.perform();
}
@azakordonets
azakordonets / getJiraFieldsList.py
Created September 22, 2014 10:05
This scrip allows you easily to get full list of all your JIRA instance fields
import urllib
import urllib2
import cookielib
import json
jira_serverurl = "{url to your jira environment}"
creds = { "username" : "admin", "password" : "test" }
authurl = jira_serverurl + "/rest/auth/latest/session"
# Get the authentication cookie using the REST API
private def isValidBSN(candidate: Int): Boolean = {
var bsn = candidate
if (bsn <= 9999999 || bsn > 999999999) {
return false;
}
var sum: Int = -1 * bsn % 10;
for (multiplier <- 2 to 1000 ; if bsn > 0) {
bsn = bsn / 10
var value = bsn % 10
@azakordonets
azakordonets / randomString.py
Last active January 7, 2016 12:37
Generate random string in python
import string
import random
print ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(3000))
print len("A5WMMLXE5DBAQMFGRF8OSEB6K5MW972PORMU4ENBC4VDBEDWB5WEFYG2ECXAJ7YSWXE9P0TUSKCD3LZMPGG9VKKLTS04R0101OS02XTKAG9VI3T69YHK56NXORO8A9GI095422I3RSFY1QJDXZONXBKHEA9HB9JB0DPG56XNYTNDLG64ITAWEKB6PEY46OW391WQCBRPPDS2VDKY748S38P0FZURELCPTDDMWI301I6I0RP7FHT20DWTWHJUH2X0ECJ9VJM108IAAZWM058HXKQJ9W6R4A3QZFM17HVB4ZPB666RANSS0TVQ4B0FYKWAJP5XYV4820H8KRPQ7OHXU85KFUUFG45MFU67JC2RE05I02YFCS720S4IVXGGY6YQE47PKXMXMZJC160WKRU2OJS7KTONBOUXA4M6RCAZYVFJCIUQE5AKCYKCLMAYB1AMC2LUEE5T21OHXKAD54QAS68FU1M3BED8QH6UAO2XYCXO8R62O48RFVK8LSX7KTZYBV15U8LGGPINTF4XTXUWDU9LI39ES404YEZRHD5RLLX8WX8ND7R2RRQ9HBFH8OY4LFIJFD38CEQ95PAEW3TW7AJTMUXS27MP7FN2FXHY7F8FB7UFHTESBU3X6GDNZN6PIJNUXFBQHUM9BCD9FYXI6CY5NPIAQJKC98BHOUFBJOC3SLNCK0LARF0W0019YB8EETF6BT8PKUNIN3B0BHFIOQEARX1IDKVF00WNH0JIO9LEHPKINLZFHOZ2FXV48SM76B84NTDGIM24XMKDA2A4RQ7J4UCLBZTQJWCWTXBY6MQMX8BXIBJV5ZHB3EYM0CXFECN6H7XLE899FW2ADGMRDYRFH19TX9LXQ4MNQLS2ZC194N5M