Skip to content

Instantly share code, notes, and snippets.

View automationhacks's full-sized avatar

Gaurav Singh automationhacks

View GitHub Profile
@automationhacks
automationhacks / people_test.py
Created November 27, 2020 09:07
Tests new person can be added and asserts using Get API
def test_new_person_can_be_added():
unique_last_name = create_new_person()
# After user is created, we read all the users and then use list comprehension to find if the
# created user is present in the response list
peoples = requests.get(BASE_URI).json()
is_new_user_created = search_created_user_in(peoples, unique_last_name)
assert_that(is_new_user_created).is_not_empty()
def create_new_person():
@automationhacks
automationhacks / logback.xml
Created September 25, 2020 01:35
Logback logging framework configuration file with console, file and report portal appenders as the possible destination spots
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
@automationhacks
automationhacks / GenericWait.kt
Created August 8, 2020 03:05
Kotlin function to wait till a passed in lambda evaluates to true or times out
package experiments
import org.joda.time.DateTime
import org.testng.annotations.Test
object Wait {
fun until(function: () -> Boolean, timeout: Int = 30, retryAfter: Int = 2): Boolean {
val endAt = DateTime.now().plus(timeout.toLong() * 1000)
@automationhacks
automationhacks / bug_template.md
Last active April 12, 2024 07:47
Bug template to help in writing clear bug reports

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Expected behavior

A clear and concise description of what you expected to happen.

Priority

What is the impact of this bug on the user, how critical is to fix? P0, P1 .. P4

@automationhacks
automationhacks / IsPrime.kt
Created July 18, 2020 15:06
A Simple function to determine if a no is prime in Kotlin
import org.testng.Assert
import org.testng.annotations.Test
fun isPrime(num: Int): Boolean {
val end = kotlin.math.sqrt(num.toDouble()).toInt()
var i = 2
while (i < end) {
if (num % i == 0) {
return false
@automationhacks
automationhacks / RedisHandler.kt
Created May 30, 2020 01:55
Simple Kotlin file with an abstraction over jedis (JVM support library for redis)
import core.logging.Logger
import redis.clients.jedis.Jedis
class RedisHandler(val host: String = "127.0.0.1", private val port: Int = 6379) {
private var jedis = Jedis(host, port)
private fun refreshConnection() {
jedis = Jedis(host, port)
}
@automationhacks
automationhacks / sierpinski.py
Created May 4, 2020 02:48
A recursive implementation of sierpinski triangle using python turtle graphics and data class
import turtle
from dataclasses import dataclass
@dataclass
class Point:
x: int
y: int
@automationhacks
automationhacks / setup.sh
Last active January 7, 2024 01:38
Quick setup guide: How to create an empty python3 virtualenv via pipenv and install a module
# install pipenv via homebrew
brew install pipenv
# Create a home directory
mkdir ~/.virtualenvs
# Add below in .zshrc or .bash_profile (if on mac/linux) or in your windows system variables
export WORKON_HOME=~/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
export LANG=en_US.UTF-8
@automationhacks
automationhacks / build.gradle
Created March 1, 2020 16:55
Vanilla report portal setup
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
}
...
sourceCompatibility = 1.8
repositories {
package testFrameworks.testNG.setupTearDown
import org.testng.Assert
import org.testng.annotations.BeforeMethod
import org.testng.annotations.DataProvider
import org.testng.annotations.Test
import java.util.concurrent.ThreadLocalRandom
enum class VehicleType() {
CAR,