Skip to content

Instantly share code, notes, and snippets.

@KrishnB
KrishnB / FileExtension.java
Created June 28, 2017 17:56
Search for a file in a project directory.
public enum FileExtension {
JAVA(".java"),
TEXT(".txt"),
SQL(".sql"),
FEATURE(".feature"),
EXCEL(".xls");
private String fileExtension;
FileExtension(String fileExtension) {
@KrishnB
KrishnB / AppiumServerManager.java
Created August 17, 2018 06:04
Appium Service
/*
* Copyright (c) 2017. TestVagrant Technologies
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@KrishnB
KrishnB / CreateAppiumService.java
Last active August 17, 2018 06:18
Create appium service
public AppiumDriverLocalService startAppiumService() {
AppiumServiceBuilder appiumServiceBuilder = new AppiumServiceBuilder()
.usingDriverExecutable(new File(executionDetails.getAppium_node_path()))
.withAppiumJS(new File(executionDetails.getAppium_js_path()))
.withIPAddress("127.0.0.1")
.withArgument(SESSION_OVERRIDE)
.usingAnyFreePort();
if (isAndroid) {
appiumServiceBuilder
.withArgument(AndroidServerFlag.BOOTSTRAP_PORT_NUMBER,
public Integer aRandomOpenPortOnAllLocalInterfaces() {
try (
ServerSocket socket = new ServerSocket(0);
) {
return socket.getLocalPort();
} catch (IOException e) {
throw new RuntimeException("no open ports found for bootstrap");
}
}
@KrishnB
KrishnB / FragmentationTask.java
Created August 17, 2018 07:51
Fragmentation task
def runDeviceFragmentation(List<String> udidList) {
def size = udidList.size()
println "Total devices -- " + size
GParsPool.withPool(size) {
udidList.eachParallel { String udid ->
project.javaexec {
main = "cucumber.api.cli.Main"
classpath = optimusExtension.classpath
args = ["-p", "pretty", "-p", ("json:${reportingExtension.baseDir}/cucumber/" + updateReportFileName(udid) + ".json"), "--glue", "steps", "-t", "@sampleTag",
"${project.projectDir}/src/test/resources/features"];
@KrishnB
KrishnB / DistributionTask.java
Created August 17, 2018 08:04
Distribution Task
def runFunctionalDistribution(List<String> udidList, List<File> featureFiles) {
def size = udidList.size()
println "pool size -- " + size
def cucumberArgs;
GParsPool.withPool(size) {
allFiles.eachParallel { File feature ->
project.javaexec {
main = "cucumber.api.cli.Main"
classpath = optimusExtension.classpath
args = ["-p", "pretty", "-p",
@KrishnB
KrishnB / CommonFunctions.java
Last active January 17, 2019 06:26
This code performs date selection in a calendar.
public static void calendarHandling(String date, WebDriver driver) {
// elements for clicking calendar buttons
String PrevButtonM = "//div[@id='ui-datepicker-div']/descendant::div[@class='header']/a[@title='Prev']";
String NextButtonM = "//div[@id='ui-datepicker-div']/descendant::div[@class='header']/a[@title='Next']";
String currentReturnedYear = "//div[@id='ui-datepicker-div']/descendant::div[@class='monthBlock first']//div[@class='title']/span[@class='ui-datepicker-year']";
String returnedMonth = "//div[@id='ui-datepicker-div']/descendant::div[@class='monthBlock first']//div[@class='title']/span[@class='ui-datepicker-month']";
date = date.trim();
String DateArr[] = date.split("/");
@KrishnB
KrishnB / OptimusDashboardSetup.md
Last active June 24, 2019 08:47
Setting up optimus dashboard

Step 1

Install Docker https://docs.docker.com/install/

Step 2

Pull Optimus dashboard docker image

    docker pull testvagrant/optimusdashboard

Step 3

Create a configuration file eg: env.list

@KrishnB
KrishnB / OtpReader.java
Created September 12, 2019 08:31
Otp Reader
package utils;
import com.testvagrant.commons.entities.SmartBOT;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.appmanagement.AndroidInstallApplicationOptions;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
// Any local variable declaration
List<String> list = new ArrayList<String>();
Stream<String> stream = getStream()
// For Lambda Expression.
(String a, String b) -> a.concat(b)