└── AutomationSeleniumJavaProject ├── resources ├── TestDataOutput.properties └── Datapool.xls ├── src ├── data │ ├── config.properties │ ├── TestDataPool.java │ └── Constants.java ├── javaLibrary │ ├── NonStaticDemo.java │ ├── StaticDemo.java │ ├── OverridingParentClassDemo.java │ ├── LoopsDemo.java │ ├── OverridingChildClassDemo.java │ ├── PolymorphismDemo.java │ ├── ConstructorDemo.java │ ├── ConditionsDemo.java │ └── ArithmeticLibrary.java ├── javaTests │ ├── Welcome.java │ ├── OverloadingTest.java │ ├── ConstructorTest.java │ ├── BasicProgram.java │ ├── LoopsTest.java │ ├── StaticAndNonStaticTest.java │ ├── DataTypes.java │ ├── ExceptionHandlingTest.java │ ├── OverridingTest.java │ ├── ConditionsTest.java │ ├── ArithmeticTest.java │ ├── StringManipulationsTest.java │ └── ArrayTest.java ├── playground │ └── rnd.java ├── tests │ ├── ToolsqaHybridFrameworkTest.java │ └── GoogleLinearFrameworkTest.java ├── setup │ └── TestRunSetup.java ├── utils │ ├── ScreenshotUtils.java │ ├── ReportingUtils.java │ ├── FileSystemUtils.java │ ├── PropertyUtils.java │ ├── ExcelUtils.java │ └── KeyboardUtils.java ├── infra │ └── Operations.java ├── pageObjects │ └── AutomationPracticeFormObj.java └── pageFlows │ └── AutomationPracticeFormPage.java ├── bin ├── .gitignore ├── javaTests │ ├── Welcome.class │ ├── ArrayTest.class │ ├── DataTypes.class │ ├── LoopsTest.class │ ├── BasicProgram.class │ ├── ArithmeticTest.class │ ├── ConditionsTest.class │ ├── ConstructorTest.class │ ├── OverloadingTest.class │ ├── OverridingTest.class │ ├── ExceptionHandlingTest.class │ ├── StaticAndNonStaticTest.class │ └── StringManipulationsTest.class ├── setup │ └── TestRunSetup.class └── javaLibrary │ ├── LoopsDemo.class │ ├── StaticDemo.class │ ├── NonStaticDemo.class │ ├── ConditionsDemo.class │ ├── ConstructorDemo.class │ ├── PolymorphismDemo.class │ ├── ArithmeticLibrary.class │ ├── OverridingChildClassDemo.class │ └── OverridingParentClassDemo.class ├── .classpath ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── ToolsQaTest_HybridFramework.java └── debug.log /AutomationSeleniumJavaProject/resources/TestDataOutput.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/data/config.properties: -------------------------------------------------------------------------------- 1 | browser=firefox 2 | testName=sangam 3 | noOfTCs=1 -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/.gitignore: -------------------------------------------------------------------------------- 1 | /infra/ 2 | /tests/ 3 | /data/ 4 | /setup/ 5 | /pageFlows/ 6 | /pageObjects/ 7 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/resources/Datapool.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/resources/Datapool.xls -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/Welcome.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/Welcome.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/setup/TestRunSetup.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/setup/TestRunSetup.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/ArrayTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/ArrayTest.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/DataTypes.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/DataTypes.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/LoopsTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/LoopsTest.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaLibrary/LoopsDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaLibrary/LoopsDemo.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaLibrary/StaticDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaLibrary/StaticDemo.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/BasicProgram.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/BasicProgram.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaLibrary/NonStaticDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaLibrary/NonStaticDemo.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/ArithmeticTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/ArithmeticTest.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/ConditionsTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/ConditionsTest.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/ConstructorTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/ConstructorTest.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/OverloadingTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/OverloadingTest.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/OverridingTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/OverridingTest.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaLibrary/ConditionsDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaLibrary/ConditionsDemo.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaLibrary/ConstructorDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaLibrary/ConstructorDemo.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaLibrary/PolymorphismDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaLibrary/PolymorphismDemo.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaLibrary/ArithmeticLibrary.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaLibrary/ArithmeticLibrary.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/ExceptionHandlingTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/ExceptionHandlingTest.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/StaticAndNonStaticTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/StaticAndNonStaticTest.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaTests/StringManipulationsTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaTests/StringManipulationsTest.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaLibrary/OverridingChildClassDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaLibrary/OverridingChildClassDemo.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/bin/javaLibrary/OverridingParentClassDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangamautomation/AutomationSeleniumJavaProject/HEAD/AutomationSeleniumJavaProject/bin/javaLibrary/OverridingParentClassDemo.class -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaLibrary/NonStaticDemo.java: -------------------------------------------------------------------------------- 1 | package javaLibrary; 2 | /** 3 | * Non-Static Demo 4 | * 5 | * @author Sangam 6 | */ 7 | public class NonStaticDemo { 8 | 9 | public void myNonStaticMethod(){ 10 | System.out.println("myNonStaticMethod"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | AutomationSeleniumJavaProject 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaLibrary/StaticDemo.java: -------------------------------------------------------------------------------- 1 | package javaLibrary; 2 | /** 3 | * Static Demo 4 | * 5 | * @author Sangam 6 | */ 7 | public class StaticDemo { 8 | public static void myStaticMethod(){ 9 | System.out.println("myStaticMethod"); 10 | 11 | } 12 | 13 | public String justANonStaticMethod(String x, String y) { 14 | 15 | System.out.println("just a non static method "+x + y); 16 | 17 | return x+y; //the return statement must be the last one 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaTests/Welcome.java: -------------------------------------------------------------------------------- 1 | package javaTests; 2 | 3 | import java.util.Arrays; 4 | 5 | // To print a message "Welecome Java Session" to console 6 | 7 | public class Welcome { 8 | 9 | //Variables declaration 10 | //Methods 11 | 12 | public static void main(String[] args) { 13 | 14 | String msg = "Welcome to java class!"; 15 | System.out.println(msg); 16 | 17 | System.out.println("Welcome to Java and Automation Session!"); 18 | System.out.println("This is for automation using seleniumm webdriver!!"); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.8 12 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/ToolsQaTest_HybridFramework.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | import org.openqa.selenium.chrome.ChromeDriver; 5 | 6 | import pageFlows.AutomationPracticeFormPage; 7 | import setup.TestRunSetup; 8 | 9 | public class ToolsQaTest_HybridFramework { 10 | 11 | public static void main(String[] args) { 12 | 13 | System.out.println("*** Start ToolsQA Automation Test ***"); 14 | 15 | // Setup 16 | WebDriver driver = null; 17 | driver = TestRunSetup.launchBrowser("chrome", "http://toolsqa.com/automation-practice-form/"); 18 | 19 | // Test steps 20 | AutomationPracticeFormPage.PracticeAutomationForm(driver); 21 | 22 | 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaLibrary/OverridingParentClassDemo.java: -------------------------------------------------------------------------------- 1 | package javaLibrary; 2 | /** 3 | * Inheritance Demo 4 | * 5 | * @author Sangam 6 | */ 7 | public class OverridingParentClassDemo { 8 | 9 | 10 | int x; 11 | int y; 12 | 13 | public void setup(){ 14 | x = 10; 15 | y=20; 16 | System.out.println(" Setup -- Parent class - x= "+x); 17 | } 18 | 19 | public void add(){ 20 | System.out.println("Parent class - add"); 21 | 22 | } 23 | 24 | //overloaded method 25 | public int add(int x, int y){ 26 | 27 | System.out.println("Parent class - The sum = "+(x+y)); 28 | return x+y; 29 | 30 | } 31 | 32 | 33 | public void sub(){ 34 | System.out.println("Parent class - sub"); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/playground/rnd.java: -------------------------------------------------------------------------------- 1 | package playground; 2 | 3 | import java.awt.AWTException; 4 | 5 | import utils.KeyboardUtils; 6 | 7 | public class rnd { 8 | 9 | public static void main(String[] args) { 10 | try { 11 | String path1 = "C"; 12 | String path2 = "\\Users\\sanga\\OneDrive\\Documents\\Automation_Class\\Images\\profile.png"; 13 | String fullpath = "C:\\Users\\sanga\\OneDrive\\Documents\\Automation_Class\\Images\\profile.png#$?"; 14 | 15 | 16 | 17 | // new KeyboardUtils().type(path1); 18 | // new KeyboardUtils().Key_Colon(); 19 | // new KeyboardUtils().type(path2); 20 | // 21 | new KeyboardUtils().type(fullpath); 22 | } catch (Exception e) { 23 | e.printStackTrace(); 24 | } 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaTests/OverloadingTest.java: -------------------------------------------------------------------------------- 1 | package javaTests; 2 | import javaLibrary.PolymorphismDemo; 3 | 4 | /** 5 | * Polymorphism Test :: Overloading means redefining same function (name) by changing its signature (no of arguments/ type of args/ list of args / return type ) 6 | * 7 | * @author Sangam 8 | */ 9 | public class OverloadingTest { 10 | 11 | public static void main(String[] args) { 12 | 13 | //Instantiation 14 | 15 | PolymorphismDemo poly = new PolymorphismDemo(); 16 | poly.add(1, 2); 17 | new PolymorphismDemo().add(1, 2, 3); 18 | PolymorphismDemo.add(1.2, 2); 19 | PolymorphismDemo.add(2121, 33423.343); 20 | 21 | System.out.println("The name is "+ new PolymorphismDemo().add("John", "Adams")); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaLibrary/LoopsDemo.java: -------------------------------------------------------------------------------- 1 | package javaLibrary; 2 | 3 | public class LoopsDemo { 4 | 5 | public void arrayAscendingOrder(){ 6 | int x[]={4, 8, 10, 2}; 7 | int temp; 8 | for(int i=0;ix[j]) 13 | { 14 | temp=x[i]; 15 | x[i]=x[j]; 16 | x[j]=temp; 17 | } 18 | } 19 | System.out.print(" " +x[i]); 20 | } 21 | } 22 | 23 | 24 | public void arrayDescendingOrder(){ 25 | { 26 | int a[]={5, 8, 3, 10}; //a[0]=5, a[1]=8, a[2]=3.. 27 | 28 | 29 | /* a= 5 < b = 8 30 | 31 | temp = a = 5 32 | a = b = 8 33 | b= temp = 5 34 | 35 | 8 10 5 3 36 | 37 | 38 | 39 | 5 < 3? */ 40 | 41 | int temp; 42 | for(int i=0;i cntrl+space 10 | System.out.println(65465); 11 | 12 | // DATATYPES 13 | int x = 100; // cannot store decimals - 32 bits 14 | System.out.println(x); 15 | x=200; 16 | System.out.println(x); 17 | x=300; 18 | System.out.println("x = "+x); 19 | 20 | long var =3000L;// cannot store decimals - 64 bits 21 | char c='y'; // just one place 22 | boolean b=true; // true or false 23 | 24 | System.out.println("The statement that 3 > 12 is : " + (3>12)); //false 25 | 26 | int q=100; 27 | int w=200; 28 | 29 | boolean x1=q>w; 30 | 31 | System.out.println(x1); 32 | 33 | // IF statements logic 34 | if(q tcData = new HashMap<>(); 14 | 15 | //Default constructor (will be called when the class is instantiated) 16 | public TestDataPool(){ 17 | try { 18 | tcData=ExcelUtils.getTestDataXls(Constants.DATAPOOL_PATH, "Automation", 0, 1); 19 | } catch (Exception e) { 20 | e.printStackTrace(); 21 | } 22 | } 23 | 24 | //Parameterized constructor to read any test case data 25 | public TestDataPool(int tcRowNumber){ 26 | 27 | // Current Thread - Stack 28 | 29 | String stack; 30 | try { 31 | stack = Thread.currentThread().getStackTrace()[3].getClassName(); // For 3rd stack including AutomationProjects classes 32 | } catch (Exception e1) { 33 | stack = Thread.currentThread().getStackTrace()[2].getClassName(); // From elicpse, the test case is 2nd stack 34 | } 35 | String packageName = stack.substring(0,stack.lastIndexOf(".")); 36 | String className = stack; //e.g.regressionTest.test.Testcase100 37 | System.out.println("Test Case Details:"); 38 | System.out.println("Complete TestCase Name = "+stack); 39 | 40 | //Deleting the old execution's screenshots 41 | FileSystemUtils.deleteFilesWithExtension(Constants.screenshotFolderPath, ".jpg"); 42 | PropertyUtils.clearProps(Constants.captionsFolderPath); 43 | try { 44 | tcData=ExcelUtils.getTestDataXls(Constants.DATAPOOL_PATH, "Automation", 0, tcRowNumber); 45 | } catch (Exception e) { 46 | e.printStackTrace(); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaTests/ConditionsTest.java: -------------------------------------------------------------------------------- 1 | package javaTests; 2 | 3 | import javaLibrary.ConditionsDemo; 4 | /** 5 | * Conditional Statements Test 6 | * 7 | * @author Sangam 8 | */ 9 | public class ConditionsTest { 10 | 11 | public static void main(String[] args) { 12 | // Logic based programs 13 | ConditionsDemo con= new ConditionsDemo(); 14 | 15 | con.min(2, 5); 16 | con.min(0, -54); 17 | 18 | con.max(8, -3); 19 | int minimum = con.min(2, 3, 4); 20 | 21 | con.min(-123, 0, 1829); 22 | 23 | int myNumber = minimum + 2; // we utilize the returned value of a function 24 | System.out.println("My special number = "+ myNumber); 25 | 26 | con.max(23, 34, 44); 27 | 28 | //con.max(1.2, 2.3, 3.4); // this throws compile-time error - to rectify this error, either you pass int or create function that would accept double 29 | 30 | ConditionsDemo.maxMinOfNumber(34, 2323); 31 | ConditionsDemo.maxMinNumbers(134.343, 134.343); 32 | ConditionsDemo.maxMinNumbers(121212121L, 34343434L); 33 | ConditionsDemo.maxMinOfNumber(1, 1); 34 | 35 | int x[] = {2,3,4,5,6,7,9, 10, 0, -343, 334}; 36 | con.greaterNumberInArray(x); 37 | 38 | con.dayOfTheWeek(2); //multiple If's 39 | 40 | con.weekDays(4);//Switch-case 41 | 42 | String monthInfo = con.month("August"); 43 | System.out.println(monthInfo); 44 | 45 | con.displayNumbers(150); // Loops (for, while, do-while) 46 | /* 47 | ConditionsDemo cond= new ConditionsDemo(); 48 | int number1=5, number2=10, number3 = 15; 49 | 50 | cond.min(number1, number2); 51 | 52 | 53 | new ConditionsDemo().max(50, 457);//non-static calling 54 | 55 | cond.min(number1, number2, number3); 56 | 57 | new ConditionsDemo().max(15,20,50); 58 | cond.max(number1, number2, number3); 59 | 60 | int numbers[]={1, 4, 3, 9, 10}; 61 | con.greaterNumberInArray(numbers); 62 | */ } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/data/Constants.java: -------------------------------------------------------------------------------- 1 | package data; 2 | 3 | import java.util.Random; 4 | /** 5 | * Constants with Paths 6 | * @author Sangam 7 | */ 8 | public class Constants { 9 | 10 | public static final String CHROMEDRIVER_PATH = "C:\\drivers\\chromedriver.exe"; 11 | public static final String FIREFOXDRIVER_PATH = "C:/drivers\\geckodriver.exe"; 12 | public static final String BROWSER_TYPE = "chrome";//firefox, edge 13 | public static final String BASE_URL = "http://toolsqa.com/automation-practice-form/"; 14 | 15 | //public static final String DATAPOOL_PATH = "C:/AutomationProjects/AutomationTutorial/resources/Datapool.xls"; 16 | //public static final String TESTDATAOUTPUT_PATH= "C:\\AutomationProjects/AutomationTutorial/resources/TestDataOutput.properties"; 17 | 18 | Random rand = new Random(); 19 | public static String workingDir = System.getProperty("user.dir"); //C:\\AutomationProjects\\TestAutomation_Selenium 20 | //public static String datapoolPath = "C:\\AutomationProjects\\SeleniumTutorial\\resources\\TestDataPool_Automation.xls"; 21 | 22 | public static final String CONFIG_PATH = workingDir + "/src/data/config.properties"; 23 | public static final String DATAPOOL_PATH = workingDir + "/resources/Datapool.xls"; 24 | public static final String TESTDATAOUTPUT_PATH= workingDir+ "\\resources/TestDataOutput.properties"; 25 | 26 | public static String automationDatapoolPath = workingDir + "\\resources\\TestDataPool_Automation.xls"; 27 | 28 | 29 | // public static String screenshotFolderPath = "C:\\Selenium_Logs\\Screenshots\\"; 30 | public static String screenshotFolderPath = "C:\\Selenium_Logs\\Screenshots\\"; 31 | 32 | public static String captionsFolderPath = "C:\\Selenium_Logs\\Screenshots\\Captions.properties"; 33 | 34 | public static String configPath = "C:/AutomationProjects/SeleniumTutorial/src/config/config.properties"; 35 | public static int counter = 0; 36 | 37 | public static String dataPool_Xls = "C:\\AutomationProjects\\SeleniumTutorial\\resources\\TestDataPool_Automation.xls"; 38 | public static String dataPool_Xlsx = "C:/Selenium_Logs/TestData/Datapool.xlsx"; // \\=/ 39 | 40 | } 41 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaLibrary/ConstructorDemo.java: -------------------------------------------------------------------------------- 1 | package javaLibrary; 2 | /** 3 | * Constructor Demo 4 | * 5 | * @author Sangam 6 | */ 7 | public class ConstructorDemo { 8 | 9 | //Variable declaration 10 | private String firstName; 11 | private String middleName; 12 | private String lastName; 13 | private int age; 14 | private double income; 15 | 16 | 17 | //Default Constructor (used for initialization , called automatically at the time of instantiation) 18 | public ConstructorDemo(){ 19 | 20 | this.firstName = "Sangam"; 21 | this.middleName = "E"; 22 | this.lastName = "Yadagiri"; 23 | this.age = 30; 24 | this.income = 55000.00; 25 | 26 | } 27 | 28 | //Parameterized Constructor 29 | 30 | public ConstructorDemo(String firstName, String middleName, String lastName, int age, double income){ 31 | this.firstName = firstName; 32 | this.middleName = middleName; 33 | this.lastName = lastName; 34 | this.age = age; 35 | this.income = income; 36 | } 37 | 38 | //Getters & Setters 39 | 40 | public String getFirstName() { 41 | return firstName; 42 | } 43 | 44 | public void setFirstName(String firstName) { 45 | this.firstName = firstName; 46 | } 47 | 48 | public String getMiddleName() { 49 | return middleName; 50 | } 51 | 52 | public void setMiddleName(String middleName) { 53 | this.middleName = middleName; 54 | } 55 | 56 | public String getLastName() { 57 | return lastName; 58 | } 59 | 60 | public void setLastName(String lastName) { 61 | this.lastName = lastName; 62 | } 63 | 64 | public int getAge() { 65 | return age; 66 | } 67 | 68 | public void setAge(int age) { 69 | this.age = age; 70 | } 71 | 72 | public double getIncome() { 73 | return income; 74 | } 75 | 76 | public void setIncome(double income) { 77 | this.income = income; 78 | } 79 | 80 | 81 | public void display(){ 82 | //Example Output: Sangam E Yadagiri aged 30 has income $55,000 per annum. 83 | 84 | System.out.println(firstName + " "+ middleName + " "+ lastName + " aged "+age + " has income $"+ income+ " per annum." ); 85 | 86 | } 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/tests/GoogleLinearFrameworkTest.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | import org.openqa.selenium.chrome.ChromeDriver; 9 | import org.openqa.selenium.firefox.FirefoxDriver; 10 | /** 11 | * Selenium Google Test with Linear Framework 12 | * @author Sangam 13 | */ 14 | public class GoogleLinearFrameworkTest { 15 | 16 | public static void main(String[] args) throws Exception { 17 | 18 | //Setup 19 | System.out.println("*** Start Google Test - Linear Framework ***"); 20 | //Launching Browser & Opening URL 21 | System.setProperty("webdriver.chrome.driver", "C:/drivers\\chromedriver.exe"); 22 | //System.setProperty("webdriver.gecko.driver", "C:/drivers\\geckodriver.exe"); 23 | 24 | WebDriver driver = new ChromeDriver(); 25 | //WebDriver driver = new FirefoxDriver(); 26 | 27 | try { 28 | 29 | //Launch & Open URL 30 | driver.get("https://www.google.com"); 31 | 32 | //Maximize the browser 33 | driver.manage().window().maximize(); 34 | 35 | Thread.sleep(2000); // Static wait 36 | 37 | // Xpath of Google search textbox = //input[contains(@name,'q')] 38 | 39 | driver.findElement(By.xpath("//input[contains(@name,'q')]")).sendKeys("Flight Booking to Chicago");; 40 | 41 | // Implicit Wait 42 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 43 | 44 | //Click outside in html page to escape suggestions list to be able to see Google Search Button to click it later 45 | driver.findElement(By.xpath("//html")).click(); 46 | 47 | //Click on Google Search button 48 | driver.findElement(By.xpath("//div[2]/div/div[2]/div[2]/div/center/input[contains(@class,'gNO89b') and contains(@value,'Google Search') and contains(@name,'btnK') and contains(@type,'submit')]")).click(); 49 | 50 | } catch (Exception e) { 51 | //e.printStackTrace(); 52 | //throw e; 53 | } 54 | 55 | finally { 56 | //Close the browser 57 | driver.close(); 58 | System.out.println("*** End Google Test - Linear Framework ***"); 59 | } 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/utils/ReportingUtils.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import data.Constants; 4 | 5 | public class ReportingUtils { 6 | 7 | public static void reportSimple (String reportComment, String expectedValue, String actualValue){ 8 | if(expectedValue.equals(actualValue)) 9 | System.out.println("Pass - "+reportComment + ": Expected = "+expectedValue+ " & Actual = "+actualValue); 10 | else 11 | System.out.println("Fail - "+reportComment + ": Expected = "+expectedValue+ " is NOT same as Actual = "+actualValue); 12 | 13 | } 14 | 15 | public static void reportSimple (String reportComment, int expectedValue, int actualValue){ 16 | if(expectedValue == actualValue) 17 | System.out.println("Pass - "+reportComment + ": Expected = "+expectedValue+ " & Actual = "+actualValue); 18 | else 19 | System.out.println("Fail - "+reportComment + ": Expected = "+expectedValue+ " is NOT same as Actual = "+actualValue); 20 | 21 | } 22 | 23 | 24 | public static String compare(String expected, String actual){ 25 | String verdict = null; 26 | if(expected.equals(actual)) 27 | verdict = "Pass"; 28 | else 29 | verdict = "Fail"; 30 | return verdict; 31 | 32 | } 33 | 34 | 35 | public static void reportResult(String verdict_Pass_Fail, String header, String reportComment){ 36 | 37 | int counter = Constants.counter; 38 | Constants.counter++; 39 | 40 | switch (verdict_Pass_Fail) { 41 | case "Pass": 42 | System.out.println("PASS ~ Test Step Passed for "+header+ " :: "+ reportComment); 43 | PropertyUtils.propertyFile_Write(Constants.screenshotFolderPath+"Captions.properties", "Caption"+counter, reportComment); 44 | ScreenshotUtils.screenshot(Constants.screenshotFolderPath, counter); 45 | break; 46 | case "Fail": 47 | System.out.println("FAIL ~ Test Step FAILED for "+header+ " :: "+ reportComment); 48 | PropertyUtils.propertyFile_Write(Constants.screenshotFolderPath+"Captions.properties", "Caption"+counter, reportComment); 49 | ScreenshotUtils.screenshot(Constants.screenshotFolderPath, counter); 50 | break; 51 | case "Done": 52 | System.out.println("Done ~ Test Step is Done for "+header+ " :: "+ reportComment); 53 | PropertyUtils.propertyFile_Write(Constants.screenshotFolderPath+"Captions.properties", "Caption"+counter, reportComment); 54 | //ScreenshotUtils.screenshot(Constants.screenshotFolderPath, counter); 55 | break; 56 | default: 57 | System.out.println("Please mention either Pass, Fail or Done"); 58 | break; 59 | } 60 | 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/infra/Operations.java: -------------------------------------------------------------------------------- 1 | package infra; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.support.ui.ExpectedConditions; 8 | import org.openqa.selenium.support.ui.Select; 9 | import org.openqa.selenium.support.ui.WebDriverWait; 10 | /** 11 | * Basic infrastructure level functions 12 | * @author Sangam 13 | */ 14 | 15 | public class Operations { 16 | 17 | //Click Link 18 | public static void clickLink(WebDriver driver, String xpathExpression) { 19 | driver.findElement(By.xpath(xpathExpression)).click(); 20 | System.out.println("Clicked Link - "+ xpathExpression); 21 | 22 | } 23 | 24 | //Type in Textbox 25 | public static void setText(WebDriver driver, String xpathExpression, String inputText) { 26 | driver.findElement(By.xpath(xpathExpression)).sendKeys(inputText); 27 | System.out.println("Set Text - "+ xpathExpression + " - "+inputText); 28 | 29 | } 30 | 31 | //Select Radiobutton 32 | public static void selectRadiobutton(WebDriver driver, String xpathExpression) { 33 | driver.findElement(By.xpath(xpathExpression)).click(); 34 | System.out.println("Selected Radiobutton - "+ xpathExpression); 35 | 36 | } 37 | 38 | //Select Checkbox 39 | public static void selectCheckbox(WebDriver driver, String xpathExpression) { 40 | driver.findElement(By.xpath(xpathExpression)).click(); 41 | System.out.println("Selected Checkbox - "+ xpathExpression); 42 | 43 | } 44 | 45 | //Select Dropdown 46 | public static void selectDropdown(WebDriver driver, String xpathExpression, String inputVal) { 47 | 48 | Select sel = new Select(driver.findElement(By.xpath(xpathExpression))); 49 | sel.selectByVisibleText(inputVal); 50 | 51 | System.out.println("Selected Dropdown - "+ xpathExpression + " - " + inputVal); 52 | 53 | } 54 | 55 | //Capture Text 56 | public static String getText(WebDriver driver, String xpathExpression) { 57 | String capturedText = driver.findElement(By.xpath(xpathExpression)).getText(); 58 | System.out.println("Get Text - "+ xpathExpression + " - " + capturedText); 59 | return capturedText; 60 | 61 | } 62 | 63 | //Implicit Wait 64 | public static void waitImplicitely(WebDriver driver, long maxTimeout) { 65 | driver.manage().timeouts().implicitlyWait(maxTimeout, TimeUnit.SECONDS); 66 | System.out.println("waitImplicitely - "+ maxTimeout); 67 | } 68 | 69 | //Explicit Wait 70 | public static void waitExplicitely(WebDriver driver, long maxTimeout, String xpathExpression) { 71 | 72 | WebDriverWait webwait = new WebDriverWait(driver, maxTimeout); 73 | webwait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathExpression))); 74 | System.out.println("waitExplicitely - "+ maxTimeout + " - "+ xpathExpression); 75 | } 76 | 77 | //Explicit Wait 78 | public static void waitExplicitely(WebDriver driver, long maxTimeout, String xpathExpression, String textToBePresent) { 79 | 80 | WebDriverWait webwait = new WebDriverWait(driver, maxTimeout); 81 | webwait.until(ExpectedConditions.textToBePresentInElement(driver.findElement(By.xpath(xpathExpression)), textToBePresent)); 82 | System.out.println("waitExplicitely - "+ maxTimeout + " - "+ xpathExpression); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/debug.log: -------------------------------------------------------------------------------- 1 | [0526/094837.514:ERROR:process_info.cc(359)] UncheckedAllocate 2 | [0526/094837.906:ERROR:process_info.cc(359)] UncheckedAllocate 3 | [0526/105301.960:ERROR:process_info.cc(359)] UncheckedAllocate 4 | [0526/112559.620:ERROR:process_info.cc(375)] NtQuerySystemInformation SystemExtendedHandleInformation: {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation. (0xc0000017) 5 | [0526/112801.858:ERROR:process_reader_win.cc(90)] NtQuerySystemInformation: {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation. (0xc0000017) 6 | [0526/112801.929:ERROR:exception_snapshot_win.cc(98)] thread ID 10028 not found in process 7 | [0526/113837.640:ERROR:process_info.cc(375)] NtQuerySystemInformation SystemExtendedHandleInformation: {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation. (0xc0000017) 8 | [0526/113837.825:ERROR:process_info.cc(375)] NtQuerySystemInformation SystemExtendedHandleInformation: {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation. (0xc0000017) 9 | [0601/103451.072:ERROR:process_info.cc(359)] UncheckedAllocate 10 | [0601/103458.668:ERROR:process_info.cc(359)] UncheckedAllocate 11 | [0601/104034.888:ERROR:process_info.cc(375)] NtQuerySystemInformation SystemExtendedHandleInformation: {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation. (0xc0000017) 12 | [0601/104053.790:ERROR:process_reader_win.cc(90)] NtQuerySystemInformation: {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation. (0xc0000017) 13 | [0601/104053.790:ERROR:exception_snapshot_win.cc(98)] thread ID 3336 not found in process 14 | [0601/104054.801:ERROR:process_info.cc(359)] UncheckedAllocate 15 | [0601/104336.070:ERROR:process_info.cc(359)] UncheckedAllocate 16 | [0609/102953.844:ERROR:process_info.cc(375)] NtQuerySystemInformation SystemExtendedHandleInformation: {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation. (0xc0000017) 17 | [0609/110929.361:ERROR:process_info.cc(375)] NtQuerySystemInformation SystemExtendedHandleInformation: {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation. (0xc0000017) 18 | [0609/110929.809:ERROR:process_info.cc(375)] NtQuerySystemInformation SystemExtendedHandleInformation: {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation. (0xc0000017) 19 | [0609/120301.042:ERROR:process_info.cc(359)] UncheckedAllocate 20 | [0611/203810.238:ERROR:process_info.cc(359)] UncheckedAllocate 21 | [0611/203810.271:ERROR:process_info.cc(359)] UncheckedAllocate 22 | [0612/113337.709:ERROR:process_info.cc(359)] UncheckedAllocate 23 | [0612/113339.809:ERROR:process_info.cc(375)] NtQuerySystemInformation SystemExtendedHandleInformation: {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation. (0xc0000017) 24 | [0615/152220.578:ERROR:process_info.cc(359)] UncheckedAllocate 25 | [0616/103804.262:ERROR:process_info.cc(359)] UncheckedAllocate 26 | [0616/180346.082:ERROR:process_info.cc(359)] UncheckedAllocate 27 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaTests/ArithmeticTest.java: -------------------------------------------------------------------------------- 1 | package javaTests; 2 | 3 | import javaLibrary.ArithmeticLibrary; 4 | 5 | // Create functions or methods for writing basic arithmetic operation (+-*/%) 6 | 7 | public class ArithmeticTest { 8 | 9 | 10 | public static void main(String[] args) { 11 | 12 | //Instantiation / Default constructor / Param constructor 13 | 14 | ArithmeticLibrary al = new ArithmeticLibrary(); // Instantiation (using al, I can access all variables & methods of that class) 15 | 16 | ArithmeticLibrary obj = new ArithmeticLibrary(); //copy 1 17 | // ArithmeticLibrary obj2 = new ArithmeticLibrary(20,"Kathy","Female"); //copy 2 18 | 19 | 20 | 21 | //Calling void functions 22 | 23 | al.addition(10, 8); // Calling a function using instance of a class 24 | 25 | 26 | al.subtraction(20, 10); 27 | 28 | al.muiltiplication(4, 5); 29 | 30 | al.division(3, 2); // 1 31 | al.division(0,4); //0 32 | // al.division(8, 0); // undefined ( infinity ) 33 | al.division(2.5, 1.5); 34 | al.division(3.0, 2.0);//1.5 35 | 36 | //Calling returnable functions 37 | 38 | //Addition 39 | System.out.println("\n ################# Addition ############## \n"); 40 | 41 | int sum = obj.add(3, 6); 42 | System.out.println("The twice the sum = "+sum*2); 43 | 44 | 45 | obj.add(1, 3); 46 | obj.add(12121, 1212123); 47 | obj.add(0, 2312312); 48 | obj.add(34324234, 1312312); 49 | obj.add(-123123, 3423423); 50 | obj.add(-3233424, -34345345); 51 | 52 | //Difference 53 | System.out.println("\n ################# Subtraction ############## \n"); 54 | 55 | obj.subtract(5, 6); 56 | obj.subtract(23232, 3434); 57 | obj.subtract(2232, 3434234); 58 | obj.subtract(0, 343); 59 | obj.subtract(-334, -343); 60 | 61 | obj.builtin(454353.454); 62 | 63 | 64 | //Product 65 | 66 | System.out.println("\n ################# Product ############## \n"); 67 | 68 | int product = obj.product(8, 9); 69 | obj.product(1, 3); 70 | obj.product(3, 6); 71 | obj.product(343, 3434); 72 | obj.product(232, -3434); 73 | obj.product(-343, -3434); 74 | obj.product(0, 3434); 75 | 76 | 77 | //Division 78 | 79 | System.out.println("\n ################# Division ############## \n"); 80 | 81 | obj.divide(4, 6); 82 | obj.divide(344234, 34); 83 | obj.divide(232, 12); 84 | obj.divide(121, - 43); 85 | obj.divide(0,23); 86 | //obj.divide(343, 0); // Run time exception 87 | 88 | 89 | //Overloading method 90 | obj.divide(16.3, 2.4); 91 | 92 | 93 | 94 | 95 | //Multiplication Table 96 | obj.multiTable(5); 97 | 98 | //Even Numbers 99 | obj.evenNumbers(100); 100 | 101 | 102 | 103 | obj.multiTable(20, 10); // Non-Static method - Multiplication table of tables 104 | 105 | int difference = ArithmeticLibrary.subtraction2(5, 9); // Static way of calling 106 | 107 | 108 | 109 | //------------------------------------------------ 110 | 111 | //Static calling (by class name) 112 | 113 | 114 | int remainder = ArithmeticLibrary.moduloOfNumbers(28,3); 115 | System.out.println("Remainder = "+remainder); 116 | 117 | // Static calling (by instance name) 118 | int r = obj.moduloOfNumbers(44454, -2323); 119 | System.out.println("Remainder = "+ r); 120 | 121 | 122 | //Minimum of two numbers 123 | int min = ArithmeticLibrary.min(-4743, -342); //Static way of calling 124 | System.out.println("Mininum number is = "+min); 125 | 126 | 127 | 128 | //Perimeter of a triangle 129 | 130 | ArithmeticLibrary.perimeterOfTriangle(2.3, 3.4, 4.5); 131 | ArithmeticLibrary.perimeterOfRectangle(5, 6); 132 | 133 | 134 | 135 | 136 | obj.numbersDisplay(); 137 | 138 | String x = "A quick brown fox jumps over the lazy dog"; 139 | obj.perimeterOfTriangle(5, 7, 11); 140 | obj.perimeterOfRectangle(9, 13); 141 | obj.subtraction (30, 50); 142 | obj.display(50); 143 | obj.numbersDisplay(); 144 | 145 | 146 | // String Manipulations 147 | 148 | obj.numberOfCharactersInString("Java Programming!"); 149 | obj.countLetters(x); 150 | 151 | 152 | 153 | try { 154 | obj.simpleInterest(1000.50, 4.8, 5.5); 155 | } catch (Exception e) { 156 | e.printStackTrace(); 157 | } 158 | 159 | obj.swap(2, 4); 160 | 161 | 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaTests/StringManipulationsTest.java: -------------------------------------------------------------------------------- 1 | package javaTests; 2 | /** 3 | * String Test 4 | * 5 | * @author Sangam 6 | */ 7 | public class StringManipulationsTest { 8 | 9 | public static void StringConcatenation(String fn, String mn, String ln, int age){ 10 | 11 | System.out.println(fn + " "+ mn + " "+ ln + "'s age is "+ age +" years!"); 12 | //FirstName MiddleName LastName's age is 23 years! 13 | } 14 | 15 | 16 | public static void main(String[] args) { 17 | System.out.println("------String Manipulations--------------------------"); 18 | 19 | //Cancatenate 20 | StringConcatenation("Molla", "Shah", "MD", 30); 21 | 22 | //Trim 23 | String x = " John Doe Robertson "; //Delimiter = 24 | 25 | 26 | //Length of the string 27 | int lenghOfString = x.length(); 28 | 29 | 30 | System.out.println("The lengh of the string " + x + " = " + lenghOfString); // + Concatenation Operator 31 | System.out.println("The trimmed string_" + x.trim()+"_"); 32 | 33 | //Substring 34 | x = "Java Tutorial"; 35 | x.substring(5); 36 | 37 | System.out.println("The Substring starting from index 5="+ x.substring(5)); 38 | System.out.println("The Substring starting from index 5 & ending at 7="+ x.substring(5, 8)); 39 | 40 | //Character at position 41 | System.out.println("The Character at the index 6 = "+ x.charAt(6)); 42 | 43 | //Index of a character 44 | x.indexOf('a'); //1 45 | 46 | System.out.println("The index of o ="+ x.indexOf('o')); //8 47 | System.out.println("The index of R : "+ x.indexOf('R')); //-1 48 | System.out.println("The index of a after 5th position is "+ x.indexOf('a', 5)); //11 49 | 50 | System.out.println("The index of Java = "+ x.indexOf("Java")); //0 51 | System.out.println("The index of Tut = "+ x.indexOf("Tut"));//5 52 | System.out.println("The index of Java "+x.indexOf("Java", 1)); //-1 53 | System.out.println("The index of al "+x.indexOf("al", 9)); //11 54 | 55 | //Split 56 | x = "QA,Java,Automation,Course"; 57 | 58 | String[] partOfString = x.split(","); //delimiter 59 | 60 | System.out.println("The 1st part = "+ partOfString[0]); 61 | System.out.println("The 2nd part = "+ partOfString[1]); 62 | System.out.println("The 3rd part = "+ partOfString[2]); 63 | System.out.println("The 4th part = "+ partOfString[3]); 64 | //System.out.println("The 5th part = "+ partOfString[4]); //ArrayIndexOutOfBoundsException because index 4 does not exist 65 | 66 | 67 | //Cases (upper & lower) 68 | 69 | System.out.println("The name in lower case = " + x.toLowerCase()); 70 | System.out.println("The name in upper case = " + x.toUpperCase()); 71 | 72 | //Replacement 73 | 74 | String replacedString = x.replaceAll(",", " "); //Replace , with space 75 | System.out.println("The replaced output string = "+replacedString); 76 | x = replacedString; 77 | System.out.println("The replaced string is = " + x.replaceAll(" ", "_")); 78 | 79 | x = "1 Classes 2 Objects 3 Encapsulation 4 Polymorphism 5 Inheritence 6 Abstraction"; 80 | System.out.println("The string replacing all numbers with hiphen = "+x.replaceAll("[0-9]+", "-")); 81 | 82 | 83 | StringConcatenation("Shah", "Rukh", "Khan", 55); 84 | 85 | 86 | 87 | String firstName = "John"; 88 | String lastName = "Doe"; 89 | 90 | // firstName = "Russel"; 91 | 92 | String celebrity = "Shah Rukh Khan"; 93 | String lastNameOfCeleb = celebrity.substring(10); 94 | 95 | System.out.println("Full name is "+ firstName +" "+lastName); 96 | 97 | System.out.println("Last name of "+celebrity+ " is "+ lastNameOfCeleb); 98 | 99 | int lengthOfName = celebrity.length(); 100 | System.out.println("The lengh of "+celebrity+" = "+lengthOfName); 101 | 102 | int index = celebrity.indexOf('h'); 103 | System.out.println("The position of h in "+celebrity + " = "+index); 104 | 105 | 106 | //Homework: Create a function to declare two strings and compare them and print whether they are same or not 107 | //Homework: Create a function to declare two strings and compare them and print whether they are same or not by disregarding the case 108 | String y = "automation", z = "Automation"; 109 | y.equals(z); 110 | y.equalsIgnoreCase(z); 111 | 112 | 113 | 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaTests/ArrayTest.java: -------------------------------------------------------------------------------- 1 | package javaTests; 2 | 3 | import java.util.Iterator; 4 | 5 | /** 6 | * Array Test 7 | * 8 | * @author Sangam 9 | */ 10 | public class ArrayTest 11 | { 12 | public static void main(String[] args) 13 | { 14 | 15 | //Integer array of 1-Dimension 16 | // Array initialization 17 | int b = 7; 18 | 19 | //Integer array is a variable that holds set of integers 20 | //Declare and initialize array 21 | int[] c = {10, 20, 30, 40, 50}; 22 | 23 | int[] x1 = new int[5]; 24 | x1[0] = 2; 25 | x1[2] = 0; 26 | x1[3]= 25; 27 | x1[4] = 44; 28 | 29 | 30 | 31 | for(int i=0;i<=c.length-1;i++) 32 | System.out.println(c[i]); 33 | 34 | System.out.println("------------------------------"); 35 | 36 | for(int i=0;i<=x1.length-1;i++) 37 | System.out.println(x1[i]); 38 | 39 | System.out.println("------------------------------"); 40 | 41 | for (int i : x1 ) 42 | System.out.println(i); 43 | 44 | 45 | System.out.println("------------------------------"); 46 | 47 | 48 | double[] d = {1.2, 3.4, 5.6}; 49 | char[] c1 = {'a','b', '1','$','a'}; 50 | short s1[] = {1,23,45}; 51 | long[] l1 = {3343L, 232L}; 52 | float[] f1 = {232f, 3435f}; 53 | byte[] b2 = {23, 34}; 54 | 55 | 56 | 57 | System.out.println("------------------------------"); 58 | 59 | 60 | String name1 = "John"; 61 | 62 | String[] namez = new String [5]; 63 | 64 | 65 | namez[0] = "abc"; 66 | namez [1] = "def"; 67 | namez [3]= "xyz"; 68 | 69 | 70 | for(String j: namez) 71 | System.out.println(j); 72 | 73 | for (int i = 0; i < namez.length; i++) { 74 | System.out.println(namez[i]); 75 | 76 | } 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | // Sum of all values in integer array 86 | 87 | int sum=0; 88 | int a[] = {5,10,2,1,5}; 89 | 90 | 91 | 92 | for(int counter=0;counter rowData) 136 | throws FileNotFoundException, IOException { 137 | // Read Property File for environments 138 | Properties props = new Properties(); 139 | try { 140 | props.load(new FileInputStream(new File(path))); 141 | } catch (FileNotFoundException e1) { 142 | e1.printStackTrace(); 143 | } catch (IOException e1) { 144 | e1.printStackTrace(); 145 | } 146 | 147 | try { 148 | props.clear(); 149 | props.putAll(rowData); 150 | props.store(new FileOutputStream(path), "comments"); 151 | } catch (Exception e) { 152 | e.printStackTrace(); 153 | } 154 | } 155 | 156 | // Property Set with HashMap 157 | public static void propertySet(String path, HashMap rowData) 158 | throws FileNotFoundException, IOException { 159 | 160 | // FileSystemUtils.createFolder(path); 161 | 162 | // Read Property File for environments 163 | Properties props = new Properties(); 164 | try { 165 | props.load(new FileInputStream(new File(path))); 166 | } catch (FileNotFoundException e1) { 167 | e1.printStackTrace(); 168 | } catch (IOException e1) { 169 | e1.printStackTrace(); 170 | } 171 | 172 | try { 173 | props.clear(); 174 | props.putAll(rowData); 175 | props.store(new FileOutputStream(path), "Captions-Header"); 176 | // System.out.println("$ Property set: " + rowData ); 177 | } catch (Exception e) { 178 | e.printStackTrace(); 179 | } 180 | } 181 | 182 | // Property Set (HashMap inside) 183 | public static void propertySet(String path) 184 | throws FileNotFoundException, IOException { 185 | // Read Property File for environments 186 | HashMap h = TestDataPool.tcData; 187 | 188 | Properties props = new Properties(); 189 | try { 190 | props.load(new FileInputStream(new File(path))); 191 | } catch (FileNotFoundException e1) { 192 | e1.printStackTrace(); 193 | } catch (IOException e1) { 194 | e1.printStackTrace(); 195 | } 196 | 197 | try { 198 | //props.clear(); 199 | props.putAll(h); 200 | props.store(new FileOutputStream(path), "Test Input Data"); 201 | } catch (Exception e) { 202 | e.printStackTrace(); 203 | } 204 | } 205 | 206 | 207 | 208 | 209 | public static String propertyGet(String path, String prop) 210 | throws FileNotFoundException, IOException { 211 | // Read Property File for environments 212 | Properties props = new Properties(); 213 | try { 214 | props.load(new FileInputStream(new File(path))); 215 | } catch (FileNotFoundException e1) { 216 | e1.printStackTrace(); 217 | } catch (IOException e1) { 218 | e1.printStackTrace(); 219 | } 220 | 221 | System.out.println("$ Property get: " + prop+" @ "+ path); 222 | 223 | return props.getProperty(prop); 224 | 225 | // props.store(new 226 | // FileOutputStream(Constants.workingDir+"\\Properties\\TestCaseLog.properties"), 227 | // "s"); 228 | } 229 | 230 | 231 | } 232 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaLibrary/ConditionsDemo.java: -------------------------------------------------------------------------------- 1 | package javaLibrary; 2 | /** 3 | * Conditional Statement 4 | * 5 | * @author Sangam 6 | */ 7 | public class ConditionsDemo { 8 | 9 | // Returns minimum value out of 2 numbers 10 | 11 | public int min(int number1, int number2){ 12 | int minimum; 13 | if(number1 < number2) 14 | minimum = number1; 15 | else 16 | minimum = number2; 17 | System.out.println("The minimum of "+number1+ " and "+number2 + " is "+ minimum); 18 | return minimum; 19 | } 20 | 21 | // Returns maximum value out of 2 numbers 22 | 23 | public int max(int number1, int number2){ 24 | int maximum; 25 | if(number1 > number2) 26 | maximum = number1; 27 | else 28 | maximum = number2; 29 | System.out.println("The maximum of "+number1+ " and "+number2 + " is "+ maximum); 30 | return maximum; 31 | } 32 | 33 | 34 | // Returns minimum value out of 3 numbers (overloading) 35 | 36 | public int min(int number1, int number2, int number3){ 37 | int minimum; 38 | if((number1 < number2) && (number1 < number3)) 39 | minimum = number1; 40 | else if (number2 < number1 && number2 < number3) 41 | minimum = number2; 42 | else 43 | minimum = number3; 44 | System.out.println("The minimum of "+number1+ ", "+number2 + " and "+number3 + " is "+ minimum); 45 | return minimum; 46 | } 47 | 48 | // Returns maximum value out of 3 numbers 49 | 50 | public int max(int number1, int number2, int number3){ 51 | int maximum; 52 | if((number1 > number2) && (number1 > number3)) 53 | maximum = number1; 54 | else if (number2 > number1 && number2 > number3) 55 | maximum = number2; 56 | else 57 | maximum = number3; 58 | System.out.println("The maximum of "+number1+ ", "+number2 + " and "+number3 + " is "+ maximum); 59 | return maximum; 60 | } 61 | 62 | //Home work: Write a function to find min & max of 3 double numbers (decimal part) 63 | 64 | 65 | 66 | //Maximum & Minimum of 2 numbers 67 | 68 | public static void maxMinOfNumber(int a, int b){ 69 | 70 | if(a>b){ 71 | System.out.println("The max number is "+ a); 72 | System.out.println("The min number is "+ b); 73 | } 74 | else if (a == b){ 75 | System.out.println("Both numbers are equal"); 76 | } 77 | 78 | else { 79 | System.out.println("The max number is "+ b); 80 | System.out.println("The min number is "+ a); 81 | } 82 | System.out.println("=================================\n"); 83 | } 84 | 85 | 86 | 87 | public static void maxMinNumbers(long a, long b){ 88 | 89 | if(a>b){ 90 | System.out.println("The max number is "+ a); 91 | System.out.println("The min number is "+ b); 92 | } 93 | else{ 94 | System.out.println("The max number is "+ b); 95 | System.out.println("The min number is "+ a); 96 | 97 | } 98 | 99 | System.out.println("=================================\n"); 100 | 101 | } 102 | 103 | //Overloading 104 | public static void maxMinNumbers(double a, double b){ 105 | 106 | if(a>b){ 107 | System.out.println("The max number is "+ a); 108 | System.out.println("The min number is "+ b); 109 | } 110 | else if (a==b){ 111 | System.out.println("Both "+ a + " and "+ b + " are equal!"); 112 | } 113 | else{ 114 | System.out.println("The max number is "+ b); 115 | System.out.println("The min number is "+ a); 116 | 117 | } 118 | 119 | System.out.println("=================================\n"); 120 | 121 | } 122 | 123 | // Find maximum of any given numbers 124 | 125 | public void greaterNumberInArray(int[] x){ 126 | //int y[]={1, 4, 3, 9, 10}; y[0] = 1, y[1] = 4, y[2] = 3, y[3] = 9, y[4] = 10 127 | int max=Integer.MIN_VALUE; //-234,232 128 | for (int i = 0; i < x.length; i++) { 129 | if(x[i]>max) 130 | { 131 | max=x[i]; 132 | } 133 | 134 | 135 | } 136 | System.out.println(max); 137 | } 138 | 139 | 140 | // Home work: write a function to find minimum of n given numbers in an array 141 | 142 | // SWITCH - CASE 143 | 144 | 145 | // Method to print the name of the day by accepting number of the day 146 | public static void dayOfTheWeek(int day){ 147 | 148 | 149 | if(day==1) 150 | System.out.println("Sunday"); 151 | else if(day==2) 152 | System.out.println("Monday"); 153 | else if(day==3) 154 | System.out.println("Tuesday"); 155 | else if(day==4) 156 | System.out.println("Wednesday"); 157 | else if(day==5) 158 | System.out.println("thursday"); 159 | else if(day==6) 160 | System.out.println("Friday"); 161 | else if (day==7) 162 | System.out.println("Saturday"); 163 | else 164 | System.out.println("Please enter numbers 1 through 7"); 165 | 166 | 167 | } 168 | 169 | 170 | //Function to display the name of the week if the number of the week is passed 171 | public void weekDays(int a){ 172 | 173 | switch (a) { 174 | case 1: 175 | System.out.println("Sunday"); 176 | break; 177 | case 2: 178 | System.out.println("MOnday"); 179 | break; 180 | case 3: 181 | System.out.println("Tuesday"); 182 | break; 183 | case 4: 184 | System.out.println("Wednesday"); 185 | break; 186 | case 5: 187 | System.out.println("Thursday"); 188 | break; 189 | case 6: 190 | System.out.println("Friday"); 191 | break; 192 | case 7: 193 | System.out.println("Saturday"); 194 | break; 195 | 196 | default: 197 | System.out.println("PLease enter any number from 1 to 7 only!"); 198 | break; 199 | } 200 | 201 | 202 | } 203 | 204 | //Write a program to display month number when month name is passed as a parameter using switch-case 205 | public String month (String monthName){ 206 | 207 | String output = null; 208 | 209 | switch (monthName) { 210 | case "January": 211 | output ="January is the 1st month!"; 212 | break; 213 | case "February": 214 | output ="February is the 2nd month!"; 215 | break; 216 | case "March": 217 | output ="March is the 3rd month!"; 218 | break; 219 | case "April": 220 | output ="April is the 4th month!"; 221 | break; 222 | case "May": 223 | output ="May is the 5th month!"; 224 | break; 225 | case "June": 226 | output ="June is the 6th month!"; 227 | break; 228 | case "July": 229 | output ="July is the 7th month!"; 230 | break; 231 | case "August": 232 | output ="August is the 8th month!"; 233 | break; 234 | case "September": 235 | output ="September is the 9th month!"; 236 | break; 237 | case "October": 238 | output ="October is the 10th month!"; 239 | break; 240 | case "November": 241 | output ="November is the 11th month!"; 242 | break; 243 | case "December": 244 | output ="December is the 12th month!"; 245 | break; 246 | 247 | default: 248 | output = "Please enter correct month name with Initial Capital letter!"; 249 | break; 250 | } 251 | return output; 252 | } 253 | 254 | // If within If 255 | public void nestedIfs(int a, int b){ 256 | 257 | if(a>b){ 258 | System.out.println(" a is greater than b "); 259 | if(a>=b) 260 | System.out.println("a is greater than or equala to b"); 261 | 262 | } 263 | } 264 | 265 | //For, While, Do-While Loop Example 266 | public void displayNumbers(int maxNumberToDisplayFrom1){ 267 | 268 | System.out.println("For loop: Numbers from 1 through maxNumber"); 269 | for (int i =1; i<=maxNumberToDisplayFrom1 ; i++) 270 | System.out.println(i); 271 | 272 | System.out.println("---------------------------------------"); 273 | 274 | System.out.println("While Loop: Numbers from 100 (skip one number in between) till maxnumber"); 275 | int j = 100; 276 | while (j<=maxNumberToDisplayFrom1) { 277 | System.out.println(j); 278 | j = j+2; 279 | } 280 | 281 | System.out.println("---------------------------------------"); 282 | 283 | System.out.println("Do-While loop : print numbers from 500 backward"); 284 | 285 | int k = 500; 286 | do { 287 | System.out.println(k); 288 | k--; 289 | } while (k>=-500); 290 | 291 | } 292 | 293 | 294 | 295 | 296 | } 297 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/javaLibrary/ArithmeticLibrary.java: -------------------------------------------------------------------------------- 1 | 2 | package javaLibrary; 3 | 4 | public class ArithmeticLibrary { 5 | 6 | 7 | 8 | 9 | int age = 11 ; 10 | String name = "John"; 11 | String gender = "Male"; 12 | 13 | //Default Constructor (Automatically executed as an when the class in instantiated) 14 | 15 | public ArithmeticLibrary(){ 16 | 17 | this.age = 30; 18 | this.name = "Jacob"; 19 | this.gender = "Male"; 20 | 21 | System.out.println("This is a default constructor!"); 22 | System.out.println("Age = "+ this.age); 23 | System.out.println("Name = "+ this.name); 24 | System.out.println("Gender = "+ this.gender); 25 | 26 | 27 | System.out.println(" ----------------------------------------------------------------- \n "); 28 | } 29 | 30 | // Parameterized Constructor (this is used to pass any sets of values) 31 | 32 | public ArithmeticLibrary(int age, String name, String gender){ 33 | this.age = age; 34 | this.name = name; 35 | this.gender = gender; 36 | 37 | System.out.println("This is a Parameterized constructor!"); 38 | System.out.println("Age = "+ this.age); 39 | System.out.println("Name = "+ this.name); 40 | System.out.println("Gender = "+this.gender); 41 | 42 | } 43 | 44 | 45 | 46 | // Addition 47 | 48 | public static void addition (int a, int b) { 49 | 50 | int c = a + b; 51 | 52 | System.out.println(" The sum of two numbers = "+c ); 53 | 54 | } 55 | 56 | 57 | // Subtraction 58 | 59 | public void subtraction (int c, int d) { 60 | 61 | int a = c-d; 62 | 63 | System.out.println(" The difference of two numbers = " + a); 64 | 65 | } 66 | 67 | 68 | // Multiplication 69 | 70 | 71 | public void muiltiplication (int e, int f) { // signature 72 | 73 | int g = e * f; // definition 74 | 75 | System.out.println("The product of two numbers = "+ g); 76 | 77 | } 78 | 79 | 80 | 81 | //Division 82 | 83 | 84 | public void division (int a, int b) { 85 | 86 | int quotient = a / b; 87 | 88 | System.out.println(" The quotient when a is divided by b = "+ quotient); 89 | 90 | } 91 | 92 | public void division (double a, double b) { 93 | 94 | double result = a / b; 95 | 96 | System.out.println(" The quotient when a is divided by b = "+ result); 97 | 98 | } 99 | 100 | 101 | // User-defined functions 102 | 103 | // Addition 104 | 105 | public int add(int a, int b){ 106 | 107 | int c = a + b; 108 | System.out.println("The sum of "+ a + " and "+b + " = "+c); 109 | return c; 110 | 111 | } 112 | 113 | 114 | 115 | 116 | // Difference 117 | 118 | public int subtract(int a, int b){ 119 | 120 | int c = a - b; 121 | c = Math.abs(c); //Built-in function 122 | System.out.println("The absolute difference of "+ a + " and "+b + " = "+c); 123 | return c; 124 | 125 | } 126 | 127 | //Built-in functions 128 | 129 | public void builtin(double x){ 130 | double y = Math.sqrt(x); 131 | double z = Math.pow(2, 5); 132 | double p = Math.max(232.2, 492.7); 133 | System.out.println("The square root = "+ y); 134 | System.out.println(" 2 raised to the power of 5 "+ z); 135 | System.out.println("Max = "+ p); 136 | } 137 | 138 | // Product 139 | 140 | public int product ( int a, int b){ 141 | int c = a*b; 142 | System.out.println("The product of "+a + " and "+ b + " = "+ c); 143 | return c; 144 | } 145 | 146 | 147 | // Division 148 | 149 | public int divide ( int a, int b){ 150 | int c = a/b; 151 | System.out.println("The integral part of quotient when "+a + " is divided by "+ b + " = "+ c); 152 | return c; // Return statement is mandatory and should be the last statement in the function 153 | 154 | } 155 | 156 | 157 | 158 | // Polymorphism (Overloading) 159 | public double divide(double m, double n) 160 | { 161 | double quotient; 162 | quotient=m/n; 163 | System.out.println("The exact result of dividing "+ m +" and "+ n +" is "+ quotient); 164 | return quotient; 165 | } 166 | 167 | // Function to accept individual part of a name and age and print a sentense 168 | 169 | //Static function 170 | 171 | public static int moduloOfNumbers (int a, int b){ 172 | System.out.println("Remainder of two numbers when they are divided in that order = "+a%b); 173 | 174 | return a%b; 175 | } 176 | 177 | // Multiplication Table 178 | 179 | 180 | /* 7 * 1 = 7 181 | 7 * 2 = 14 182 | ........ 183 | 7 * 10 = 70*/ 184 | 185 | public void multiTable(int n) 186 | { 187 | System.out.println(" \n ############### MULTIPLICATION TABLE ##############"); 188 | 189 | /*FOR syntax: 190 | * for (int i = 0; i < array.length; i++) { 191 | 192 | 193 | }*/ 194 | 195 | 196 | for(int i=1;i<=20;i=i+1) 197 | { 198 | System.out.println(n + " * " + i+" = " +(n*i)); // 8 * 2 = 16 199 | } 200 | } 201 | 202 | 203 | // Write a function to display even numbers till specified limit 204 | public void evenNumbers(int maxEvenNumber) { 205 | System.out.println("Even Numbers :: "); 206 | for(int i = 2; i<= maxEvenNumber ; i=i+2) { 207 | System.out.print(i + ", "); 208 | 209 | } 210 | } 211 | 212 | // HomeWork :: Write a function to display odd numbers till a specified limit 213 | 214 | 215 | //Multiple multiplication tables 216 | public void multiTable(int maxNumberForTable, int tableLines) 217 | { 218 | System.out.println(" /n ****************Multiplication Table of Tables ****************** /n"); 219 | for(int i=1;i<=maxNumberForTable;i++) 220 | { 221 | for (int j=1;j<=tableLines;j++) 222 | { 223 | System.out.print(i*j+", "); 224 | } 225 | System.out.println(); 226 | } 227 | 228 | } 229 | 230 | // Conditional Statements (if-else if - else) 231 | 232 | //WAP for displaying difference of two numbers absolutely using if-else condition 233 | public static int subtraction2(int x, int y) 234 | { 235 | int diff; 236 | if (x>y) 237 | diff=x-y; 238 | else // y>x 239 | diff=y-x; 240 | 241 | 242 | System.out.println("the difference of two numbers is " +diff); 243 | return diff; 244 | 245 | 246 | } 247 | 248 | public static int min(int x, int y){ 249 | 250 | if(x 43 | */ 44 | public static HashMap getTestDataXls(String filePath, String sheetName, int headerRowNum, int tcRowNum) throws Exception 45 | { 46 | 47 | 48 | HashMap rowData = new HashMap<>(); 49 | 50 | HSSFSheet sheet = null; 51 | HSSFWorkbook workbook = null; 52 | HSSFRow headerRow,tcRow; 53 | 54 | FileInputStream file = null; 55 | 56 | //File file1 = new File(filePath); 57 | //FileInputStream fis = new FileInputStream(file1); 58 | try { 59 | file = new FileInputStream(new File(filePath));//D:\Selenium_Logs\TestData\Datapool.xls 60 | workbook = new HSSFWorkbook(file); 61 | 62 | } catch (Exception e) { 63 | e.printStackTrace(); 64 | } 65 | 66 | 67 | sheet = workbook.getSheet(sheetName); 68 | headerRow = sheet.getRow(headerRowNum); 69 | tcRow = sheet.getRow(tcRowNum); 70 | 71 | Iterator cellIterator = headerRow.cellIterator(); 72 | 73 | int i = 0; 74 | while(cellIterator.hasNext()){ 75 | 76 | org.apache.poi.ss.usermodel.Cell cell = cellIterator.next(); 77 | 78 | rowData.put(cellValueStr(workbook,headerRow,i), cellValueStr(workbook,tcRow,i)); 79 | 80 | i++; 81 | 82 | } 83 | 84 | workbook.close(); 85 | file.close(); 86 | 87 | return rowData; 88 | 89 | 90 | } 91 | 92 | 93 | public static String cellValueStr (HSSFWorkbook workbook, HSSFRow row, int cellNum){ 94 | DataFormatter format = new DataFormatter(); 95 | FormulaEvaluator eval = new HSSFFormulaEvaluator(workbook); 96 | 97 | HSSFCell cellValue = row.getCell(cellNum); 98 | 99 | eval.evaluate(cellValue); 100 | 101 | String cellValueStr = format.formatCellValue(cellValue,eval); 102 | 103 | 104 | return cellValueStr; 105 | 106 | 107 | } 108 | 109 | public static String cellValueStrX (XSSFWorkbook workbook, XSSFRow row, int cellNum){ 110 | DataFormatter format = new DataFormatter(); 111 | FormulaEvaluator eval = new XSSFFormulaEvaluator((XSSFWorkbook) workbook); 112 | 113 | XSSFCell cellValue = row.getCell(cellNum); 114 | 115 | eval.evaluate(cellValue); 116 | 117 | String cellValueStr = format.formatCellValue(cellValue,eval); 118 | 119 | 120 | return cellValueStr; 121 | 122 | 123 | } 124 | 125 | 126 | 127 | 128 | //// 129 | 130 | 131 | public static HashMap getTestDataXlsx(String filePath, 132 | String sheetName, int headerRowNum, String testCaseID) { 133 | HashMap rowData = new HashMap<>(); 134 | XSSFSheet sheet = null; 135 | XSSFWorkbook workbook = null; 136 | XSSFRow tcRow, headerRow; 137 | FileInputStream file = null; 138 | 139 | try { 140 | file = new FileInputStream(new File(filePath)); 141 | 142 | workbook = new XSSFWorkbook(file); 143 | } catch (IOException e) { 144 | e.printStackTrace(); 145 | } 146 | 147 | sheet = workbook.getSheet(sheetName); 148 | headerRow = sheet.getRow(headerRowNum); // Row number which contains the columns 149 | // names 150 | tcRow = sheet.getRow(findRow(sheet, testCaseID)); 151 | // iterate through each columns 152 | Iterator cellIterator = headerRow 153 | .cellIterator(); 154 | int i = 0; 155 | while (cellIterator.hasNext()) { 156 | org.apache.poi.ss.usermodel.Cell cell = cellIterator.next(); 157 | 158 | rowData.put(cellValueStr(workbook, headerRow, i), 159 | cellValueStr(workbook, tcRow, i)); 160 | // System.out.println(i + ":Key=" 161 | // + cellValueStr(workbook, headerRow, i) + ",Value=" 162 | // + cellValueStr(workbook, tcRow, i)); 163 | i++; 164 | } 165 | try { 166 | workbook.close(); 167 | file.close(); 168 | } catch (IOException e) { 169 | e.printStackTrace(); 170 | } 171 | // System.out.println("DataPool Records - " + sheetName +" - " + testCaseID + ": \n"+ rowData ); 172 | try { 173 | // Prints Hashmap data to property file 174 | // printHashmap(rowData);// The date elements are converted from number to date; Some elements are modified and put back to rowData and need to add few more elements separately, So, the values are written to property file after modification which need to be done from testdatapool itself. 175 | } catch (Exception e) { 176 | e.printStackTrace(); 177 | } 178 | return rowData; 179 | } 180 | 181 | 182 | 183 | /** 184 | * Retuns a HashMap with the Random names of 8 persons from the list of names given in the sheetName located at filePath 185 | * @param filePath 186 | * @param sheetName 187 | * @return 188 | */ 189 | public static HashMap getNamesMap(String filePath, 190 | String sheetName) { 191 | HashMap namesData = new HashMap<>(); 192 | XSSFSheet sheet = null; 193 | XSSFWorkbook workbook = null; 194 | XSSFRow tcRow, headerRow; 195 | FileInputStream file = null; 196 | int noOfPersons = 8; 197 | 198 | try { 199 | file = new FileInputStream(new File(filePath)); 200 | 201 | workbook = new XSSFWorkbook(file); 202 | } catch (IOException e) { 203 | e.printStackTrace(); 204 | } 205 | 206 | sheet = workbook.getSheet(sheetName); 207 | int noOfRows = sheet.getPhysicalNumberOfRows(); 208 | 209 | for(int i = 1; i <= noOfPersons; i++){ 210 | 211 | tcRow = sheet.getRow(randInt(1, noOfRows)); 212 | namesData.put("firstName"+i, cellValueStr(workbook, tcRow, 0)); 213 | tcRow = sheet.getRow(randInt(1, noOfRows)); 214 | namesData.put("middleName"+i, cellValueStr(workbook, tcRow, 1)); 215 | tcRow = sheet.getRow(randInt(1, noOfRows)); 216 | namesData.put("lastName"+i, cellValueStr(workbook, tcRow, 2)); 217 | 218 | } 219 | try { 220 | workbook.close(); 221 | file.close(); 222 | } catch (IOException e) { 223 | e.printStackTrace(); 224 | } 225 | return namesData; 226 | } 227 | 228 | 229 | /** 230 | * Returns random name from the given columnWanted from the sheetName at filePath 231 | * @param filePath 232 | * @param sheetName 233 | * @param columnWanted 234 | * @return 235 | */ 236 | public static String getName(String filePath, 237 | String sheetName, String columnWanted) { 238 | XSSFSheet sheet = null; 239 | XSSFWorkbook workbook = null; 240 | XSSFRow tcRow, headerRow; 241 | FileInputStream file = null; 242 | 243 | try { 244 | file = new FileInputStream(new File(filePath)); 245 | 246 | workbook = new XSSFWorkbook(file); 247 | } catch (IOException e) { 248 | e.printStackTrace(); 249 | } 250 | 251 | sheet = workbook.getSheet(sheetName); 252 | int noOfRows = sheet.getPhysicalNumberOfRows(); 253 | Integer columnNo = null; 254 | 255 | headerRow = sheet.getRow(0); 256 | 257 | for(org.apache.poi.ss.usermodel.Cell cell:headerRow){ 258 | if (cell.getStringCellValue().equals(columnWanted)){ 259 | columnNo = cell.getColumnIndex(); 260 | } 261 | } 262 | 263 | 264 | if (columnNo != null){ 265 | tcRow = sheet.getRow(randInt(1, noOfRows)); 266 | return cellValueStr(workbook, tcRow, columnNo); 267 | }else{ 268 | System.out.println("could not find column " + columnWanted + " in first row"); 269 | } 270 | try { 271 | workbook.close(); 272 | file.close(); 273 | } catch (IOException e) { 274 | // TODO Auto-generated catch block 275 | e.printStackTrace(); 276 | } 277 | return ""; 278 | } 279 | 280 | /** 281 | * Returns a psuedo-random number between min and max, inclusive. 282 | * The difference between min and max can be at most 283 | * Integer.MAX_VALUE - 1. 284 | * 285 | * @param min Minimim value 286 | * @param max Maximim value. Must be greater than min. 287 | * @return Integer between min and max, inclusive. 288 | * @see java.util.Random#nextInt(int) 289 | */ 290 | public static int randInt(int min, int max) { 291 | 292 | // Usually this can be a field rather than a method variable 293 | Random rand = new Random(); 294 | 295 | // nextInt is normally exclusive of the top value, 296 | // so add 1 to make it inclusive 297 | int randomNum = rand.nextInt((max - min) + 1) + min; 298 | 299 | return randomNum; 300 | } 301 | 302 | public static int findRow(XSSFSheet sheet, String cellContent) {/* 303 | for (org.apache.poi.ss.usermodel.Row row : sheet) { 304 | for (org.apache.poi.ss.usermodel.Cell cell : row) { 305 | if (cell.getCellType() == org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING) { 306 | if (cell.getRichStringCellValue().getString().trim() 307 | .equals(cellContent)) { 308 | return row.getRowNum(); 309 | } 310 | } 311 | } 312 | } 313 | */ return 0; 314 | } 315 | 316 | public static String cellValueStr(XSSFWorkbook workbook, XSSFRow row, int cellNum) { 317 | 318 | DataFormatter objDefaultFormat = new DataFormatter(); 319 | FormulaEvaluator objFormulaEvaluator = new XSSFFormulaEvaluator( 320 | (XSSFWorkbook) workbook); 321 | 322 | XSSFCell cellValue = row.getCell(cellNum); 323 | objFormulaEvaluator.evaluate(cellValue); // This will evaluate the cell, 324 | // And any type of cell will 325 | // return string value 326 | String cellValueStr = objDefaultFormat.formatCellValue(cellValue, 327 | objFormulaEvaluator); 328 | return cellValueStr; 329 | } 330 | 331 | 332 | 333 | 334 | public static String cellToString(XSSFCell column){ 335 | Object result; 336 | //int type = column.getCellType(); 337 | int type = Integer.parseInt(column.getCellType().toString()); 338 | switch(type){ 339 | case 0: 340 | result = (int)column.getNumericCellValue(); 341 | break; 342 | case 1: 343 | result = column.getStringCellValue(); 344 | break; 345 | default: 346 | throw new RuntimeException("This column data type is not identified"); 347 | } 348 | return result.toString(); 349 | } 350 | 351 | 352 | /** 353 | * generateCsvFile 354 | * @param sFileName 355 | * generateCsvFile("c:\\test.csv"); 356 | */ 357 | private static void generateCsvFile(String sFileName) 358 | { 359 | try 360 | { 361 | FileWriter writer = new FileWriter(sFileName); 362 | 363 | writer.append("Name"); 364 | writer.append(','); 365 | writer.append("Age"); 366 | writer.append('\n'); 367 | 368 | writer.append("Sangam"); 369 | writer.append(','); 370 | writer.append("26"); 371 | writer.append('\n'); 372 | 373 | writer.append("Yadagiri"); 374 | writer.append(','); 375 | writer.append("29"); 376 | writer.append('\n'); 377 | 378 | //generate whatever data you want 379 | 380 | writer.flush(); 381 | writer.close(); 382 | } 383 | catch(IOException e) 384 | { 385 | e.printStackTrace(); 386 | } 387 | } 388 | 389 | public HashMap loadExcelData(String xlsxPath) throws Exception{ 390 | File myFile = new File(xlsxPath); 391 | FileInputStream fis = new FileInputStream(myFile); 392 | HashMap excelData = new HashMap<>(); 393 | HashMap headerData = new HashMap<>(); 394 | // Finds the workbook instance for XLSX file 395 | XSSFWorkbook myWorkBook = new XSSFWorkbook (fis); 396 | DataFormatter objDefaultFormat = new DataFormatter(); 397 | FormulaEvaluator objFormulaEvaluator = new XSSFFormulaEvaluator( 398 | (XSSFWorkbook) myWorkBook); 399 | 400 | // Return first sheet from the XLSX workbook 401 | XSSFSheet mySheet = myWorkBook.getSheetAt(0); 402 | 403 | // Get iterator to all the rows in current sheet 404 | Iterator rowIterator = mySheet.iterator(); 405 | Row row = rowIterator.next(); 406 | int colNo = 0, rowNo = 1; 407 | Iterator cellIterator = row.cellIterator(); 408 | while (cellIterator.hasNext()) { 409 | Cell cell = cellIterator.next(); 410 | colNo++; 411 | objFormulaEvaluator.evaluate(cell); 412 | String cellValueStr = objDefaultFormat.formatCellValue(cell, 413 | objFormulaEvaluator); 414 | System.out.println(cellValueStr); 415 | headerData.put("col"+colNo, cellValueStr); 416 | } 417 | 418 | // Traversing over each row of XLSX file 419 | while (rowIterator.hasNext()) { 420 | row = rowIterator.next(); 421 | // For each row, iterate through each columns 422 | cellIterator = row.cellIterator(); 423 | colNo=0; 424 | while (cellIterator.hasNext()) { 425 | Cell cell = cellIterator.next(); 426 | colNo++; 427 | objFormulaEvaluator.evaluate(cell); 428 | String cellValueStr = objDefaultFormat.formatCellValue(cell, 429 | objFormulaEvaluator); 430 | System.out.println(cellValueStr); 431 | excelData.put(headerData.get("col"+colNo) + rowNo, cellValueStr); 432 | } 433 | rowNo++; 434 | } 435 | myWorkBook.close(); 436 | fis.close(); 437 | return excelData; 438 | } 439 | 440 | } 441 | -------------------------------------------------------------------------------- /AutomationSeleniumJavaProject/src/utils/KeyboardUtils.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | import static java.awt.event.KeyEvent.*; 3 | import static java.awt.event.KeyEvent.VK_1; 4 | import static java.awt.event.KeyEvent.VK_2; 5 | import static java.awt.event.KeyEvent.VK_3; 6 | import static java.awt.event.KeyEvent.VK_4; 7 | import static java.awt.event.KeyEvent.VK_5; 8 | import static java.awt.event.KeyEvent.VK_6; 9 | import static java.awt.event.KeyEvent.VK_7; 10 | import static java.awt.event.KeyEvent.VK_8; 11 | import static java.awt.event.KeyEvent.VK_9; 12 | import static java.awt.event.KeyEvent.VK_A; 13 | import static java.awt.event.KeyEvent.VK_AMPERSAND; 14 | import static java.awt.event.KeyEvent.VK_ASTERISK; 15 | import static java.awt.event.KeyEvent.VK_AT; 16 | import static java.awt.event.KeyEvent.VK_B; 17 | import static java.awt.event.KeyEvent.VK_BACK_QUOTE; 18 | import static java.awt.event.KeyEvent.VK_BACK_SLASH; 19 | import static java.awt.event.KeyEvent.VK_C; 20 | import static java.awt.event.KeyEvent.VK_CIRCUMFLEX; 21 | import static java.awt.event.KeyEvent.VK_CLOSE_BRACKET; 22 | import static java.awt.event.KeyEvent.VK_COLON; 23 | import static java.awt.event.KeyEvent.VK_COMMA; 24 | import static java.awt.event.KeyEvent.VK_D; 25 | import static java.awt.event.KeyEvent.VK_DOLLAR; 26 | import static java.awt.event.KeyEvent.VK_E; 27 | import static java.awt.event.KeyEvent.VK_ENTER; 28 | import static java.awt.event.KeyEvent.VK_EQUALS; 29 | import static java.awt.event.KeyEvent.VK_EXCLAMATION_MARK; 30 | import static java.awt.event.KeyEvent.VK_F; 31 | import static java.awt.event.KeyEvent.VK_G; 32 | import static java.awt.event.KeyEvent.VK_H; 33 | import static java.awt.event.KeyEvent.VK_I; 34 | import static java.awt.event.KeyEvent.VK_J; 35 | import static java.awt.event.KeyEvent.VK_K; 36 | import static java.awt.event.KeyEvent.VK_L; 37 | import static java.awt.event.KeyEvent.VK_LEFT_PARENTHESIS; 38 | import static java.awt.event.KeyEvent.VK_M; 39 | import static java.awt.event.KeyEvent.VK_MINUS; 40 | import static java.awt.event.KeyEvent.VK_N; 41 | import static java.awt.event.KeyEvent.VK_NUMBER_SIGN; 42 | import static java.awt.event.KeyEvent.VK_O; 43 | import static java.awt.event.KeyEvent.VK_OPEN_BRACKET; 44 | import static java.awt.event.KeyEvent.VK_P; 45 | import static java.awt.event.KeyEvent.VK_PERIOD; 46 | import static java.awt.event.KeyEvent.VK_PLUS; 47 | import static java.awt.event.KeyEvent.VK_Q; 48 | import static java.awt.event.KeyEvent.VK_QUOTE; 49 | import static java.awt.event.KeyEvent.VK_QUOTEDBL; 50 | import static java.awt.event.KeyEvent.VK_R; 51 | import static java.awt.event.KeyEvent.VK_RIGHT_PARENTHESIS; 52 | import static java.awt.event.KeyEvent.VK_S; 53 | import static java.awt.event.KeyEvent.VK_SEMICOLON; 54 | import static java.awt.event.KeyEvent.VK_SHIFT; 55 | import static java.awt.event.KeyEvent.VK_SLASH; 56 | import static java.awt.event.KeyEvent.VK_SPACE; 57 | import static java.awt.event.KeyEvent.VK_T; 58 | import static java.awt.event.KeyEvent.VK_TAB; 59 | import static java.awt.event.KeyEvent.VK_U; 60 | import static java.awt.event.KeyEvent.VK_UNDERSCORE; 61 | import static java.awt.event.KeyEvent.VK_V; 62 | import static java.awt.event.KeyEvent.VK_W; 63 | import static java.awt.event.KeyEvent.VK_X; 64 | import static java.awt.event.KeyEvent.VK_Y; 65 | import static java.awt.event.KeyEvent.VK_Z; 66 | import java.awt.AWTException; 67 | import java.awt.Robot; 68 | import java.awt.event.KeyEvent; 69 | 70 | /** 71 | * Description : Keyboard Utility Functions 72 | * @author Sangam 73 | * 74 | */ 75 | 76 | public class KeyboardUtils { 77 | 78 | public static void main(String... args) throws Exception { 79 | KeyboardUtils keyboard = new KeyboardUtils(); 80 | keyboard.type("Hello there, how are you?"); 81 | String filePath = "C:\\Users\\sanga\\OneDrive\\Documents\\Automation_Class\\Images\\profile.png"; 82 | new KeyboardUtils().type(filePath); 83 | } 84 | 85 | // Press TAB 86 | public static void Key_Tab() throws AWTException, InterruptedException 87 | { 88 | Thread.sleep(1000); 89 | Robot r = new Robot(); 90 | 91 | r.keyPress(KeyEvent.VK_TAB); 92 | r.keyRelease(KeyEvent.VK_TAB); 93 | } 94 | 95 | 96 | 97 | public void Key_BrowserBack() throws AWTException, InterruptedException 98 | { 99 | Thread.sleep(1000); 100 | Robot r = new Robot(); 101 | 102 | r.keyPress(KeyEvent.VK_ALT); 103 | r.keyPress(KeyEvent.VK_LEFT); 104 | r.keyRelease(KeyEvent.VK_ALT); 105 | r.keyRelease(KeyEvent.VK_LEFT); 106 | } 107 | public void Key_ZoomOut(int n) throws AWTException, InterruptedException 108 | { 109 | Thread.sleep(1000); 110 | Robot r = new Robot(); 111 | for (int i = 0; i < n; i++) { 112 | r.keyPress(KeyEvent.VK_CONTROL); 113 | r.keyPress(KeyEvent.VK_MINUS); 114 | r.keyRelease(KeyEvent.VK_CONTROL); 115 | r.keyRelease(KeyEvent.VK_MINUS); 116 | } 117 | 118 | } 119 | public void Key_ZoomIn(int n) throws AWTException, InterruptedException 120 | { 121 | Thread.sleep(1000); 122 | Robot r = new Robot(); 123 | for (int i = 0; i < n; i++) { 124 | r.keyPress(KeyEvent.VK_CONTROL); 125 | r.keyPress(KeyEvent.VK_PLUS); 126 | r.keyRelease(KeyEvent.VK_CONTROL); 127 | r.keyRelease(KeyEvent.VK_PLUS); 128 | } 129 | 130 | } 131 | public void Key_ZoomReset() throws AWTException, InterruptedException 132 | { 133 | Thread.sleep(1000); 134 | Robot r = new Robot(); 135 | 136 | r.keyPress(KeyEvent.VK_CONTROL); 137 | r.keyPress(KeyEvent.VK_0); 138 | r.keyRelease(KeyEvent.VK_CONTROL); 139 | r.keyRelease(KeyEvent.VK_0); 140 | } 141 | public void Key_ScrollLock() throws AWTException, InterruptedException 142 | { 143 | Thread.sleep(1000); 144 | Robot r = new Robot(); 145 | 146 | r.keyPress(KeyEvent.VK_SCROLL_LOCK); 147 | r.keyRelease(KeyEvent.VK_SCROLL_LOCK); 148 | } 149 | public void Key_Pause() throws AWTException, InterruptedException 150 | { 151 | Thread.sleep(1000); 152 | Robot r = new Robot(); 153 | 154 | r.keyPress(KeyEvent.VK_PAUSE); 155 | r.keyRelease(KeyEvent.VK_PAUSE); 156 | } 157 | public void Key_Tab(int n) throws AWTException, InterruptedException 158 | { 159 | Thread.sleep(1000); 160 | Robot r = new Robot(); 161 | 162 | for (int i = 0; i < n; i++) { 163 | r.keyPress(KeyEvent.VK_TAB); 164 | r.keyRelease(KeyEvent.VK_TAB); 165 | Thread.sleep(1000); 166 | 167 | } 168 | System.out.println("+ Key_Tab..."); 169 | } 170 | 171 | public void Key_ScrollLock(int n) throws AWTException, InterruptedException 172 | { 173 | Thread.sleep(1000); 174 | Robot r = new Robot(); 175 | 176 | for (int i = 0; i < n; i++) { 177 | r.keyPress(KeyEvent.VK_SCROLL_LOCK); 178 | r.keyRelease(KeyEvent.VK_SCROLL_LOCK); 179 | Thread.sleep(1000); 180 | 181 | 182 | } 183 | System.out.println("+ Key_ScrollLock..."); 184 | } 185 | 186 | 187 | public void Key_Pause(int n) throws AWTException, InterruptedException 188 | { 189 | Thread.sleep(1000); 190 | Robot r = new Robot(); 191 | 192 | for (int i = 0; i < n; i++) { 193 | r.keyPress(KeyEvent.VK_PAUSE); 194 | r.keyRelease(KeyEvent.VK_PAUSE); 195 | Thread.sleep(1000); 196 | 197 | 198 | } 199 | System.out.println("+ Key_Pause..."); 200 | } 201 | // Press ESC 202 | public void Key_Esc() throws Exception 203 | { 204 | Thread.sleep(500); 205 | System.out.println("Key_Esc"); 206 | Robot r = new Robot(); 207 | 208 | r.keyPress(KeyEvent.VK_ESCAPE); 209 | r.keyRelease(KeyEvent.VK_ESCAPE); 210 | } 211 | 212 | // Press Key_COLON 213 | public void Key_Colon() throws AWTException 214 | { 215 | Robot robot = new Robot(); 216 | robot.keyPress(KeyEvent.VK_SHIFT); 217 | robot.keyPress(KeyEvent.VK_COLON); 218 | robot.keyRelease(KeyEvent.VK_COLON); 219 | robot.keyRelease(KeyEvent.VK_SHIFT); 220 | } 221 | 222 | // Press Key_ScrollDown 223 | public void Key_ScrollDown() throws AWTException 224 | { 225 | Robot r = new Robot(); 226 | 227 | r.keyPress(KeyEvent.VK_PAGE_DOWN); 228 | r.keyRelease(KeyEvent.VK_PAGE_DOWN); 229 | 230 | } 231 | 232 | // Press Key_Enter 233 | public static void Key_Enter() throws InterruptedException, AWTException 234 | { 235 | Robot r = new Robot(); 236 | 237 | Thread.sleep(1000); 238 | 239 | r.keyPress(KeyEvent.VK_ENTER); 240 | r.keyRelease(KeyEvent.VK_ENTER); 241 | Thread.sleep(500); 242 | 243 | } 244 | // Press Key_Space 245 | public void Key_Space() throws InterruptedException, AWTException 246 | { 247 | System.out.println("Key_Space"); 248 | Robot r = new Robot(); 249 | 250 | Thread.sleep(1000); 251 | 252 | r.keyPress(KeyEvent.VK_SPACE); 253 | r.keyRelease(KeyEvent.VK_SPACE); 254 | 255 | } 256 | 257 | // Press Key_Any with KeyEvent as arg 258 | public void Key_Any(int keyCode_Eg_KeyEventDotVK_A) throws InterruptedException, AWTException 259 | { 260 | Robot r = new Robot(); 261 | 262 | Thread.sleep(1000); 263 | 264 | r.keyPress(keyCode_Eg_KeyEventDotVK_A); //KeyEvent.VK_A 265 | r.keyRelease(keyCode_Eg_KeyEventDotVK_A); //KeyEvent.VK_A 266 | 267 | } 268 | public void Key_TabsNEnter(int n) throws AWTException 269 | { 270 | Robot r = new Robot(); 271 | 272 | System.out.println("+ Key_Tab..."); 273 | 274 | for (int i = 0; i < n; i++) { 275 | r.keyPress(KeyEvent.VK_TAB); 276 | r.keyRelease(KeyEvent.VK_TAB); 277 | } 278 | r.keyPress(KeyEvent.VK_ENTER); 279 | r.keyRelease(KeyEvent.VK_ENTER); 280 | } 281 | 282 | public void Key_TabsNType(int n, CharSequence value) throws AWTException 283 | { 284 | Robot r = new Robot(); 285 | 286 | System.out.println("+ Key_TabsNType..."); 287 | 288 | for (int i = 0; i < n; i++) { 289 | r.keyPress(KeyEvent.VK_TAB); 290 | r.keyRelease(KeyEvent.VK_TAB); 291 | } 292 | 293 | type(value); 294 | // r.keyPress(KeyEvent.VK_ENTER); 295 | // r.keyRelease(KeyEvent.VK_ENTER); 296 | } 297 | 298 | public void Key_TabsNTypeNEnter(int n, CharSequence value) throws AWTException 299 | { 300 | Robot r = new Robot(); 301 | 302 | System.out.println("+ Key_TabsNTypeNEnter..."); 303 | 304 | for (int i = 0; i < n; i++) { 305 | r.keyPress(KeyEvent.VK_TAB); 306 | r.keyRelease(KeyEvent.VK_TAB); 307 | } 308 | 309 | type(value); 310 | r.keyPress(KeyEvent.VK_ENTER); 311 | r.keyRelease(KeyEvent.VK_ENTER); 312 | } 313 | // Press Key_ScrollDown 314 | public static void Key_ScrollDown(int n) throws AWTException 315 | { 316 | Robot r = new Robot(); 317 | 318 | for (int i = 0; i < n; i++) 319 | r.keyPress(KeyEvent.VK_PAGE_DOWN); 320 | r.keyRelease(KeyEvent.VK_PAGE_DOWN); 321 | } 322 | // Press Key_ScrollUp 323 | public static void Key_ScrollUp(int n) throws AWTException 324 | { 325 | Robot r = new Robot(); 326 | 327 | for (int i = 0; i < n; i++) 328 | r.keyPress(KeyEvent.VK_PAGE_UP); 329 | r.keyRelease(KeyEvent.VK_PAGE_UP); 330 | } 331 | // Press Key_Down 332 | public static void Key_Down(int n) throws AWTException 333 | { 334 | Robot r = new Robot(); 335 | 336 | for (int i = 0; i < n; i++) 337 | r.keyPress(KeyEvent.VK_DOWN); 338 | r.keyRelease(KeyEvent.VK_DOWN); 339 | } 340 | 341 | // Press Key_Up 342 | public static void Key_Up(int n) throws AWTException 343 | { 344 | Robot r = new Robot(); 345 | 346 | for (int i = 0; i < n; i++) 347 | r.keyPress(KeyEvent.VK_UP); 348 | r.keyRelease(KeyEvent.VK_UP); 349 | } 350 | 351 | // Press Key_Left 352 | public static void Key_Left(int n) throws AWTException 353 | { 354 | Robot r = new Robot(); 355 | 356 | for (int i = 0; i < n; i++) 357 | r.keyPress(KeyEvent.VK_LEFT); 358 | r.keyRelease(KeyEvent.VK_LEFT); 359 | } 360 | 361 | // Press Key_Right 362 | public static void Key_Right(int n) throws AWTException 363 | { 364 | Robot r = new Robot(); 365 | 366 | for (int i = 0; i < n; i++) 367 | r.keyPress(KeyEvent.VK_RIGHT); 368 | r.keyRelease(KeyEvent.VK_RIGHT); 369 | } 370 | // Press Key_Home 371 | public static void Key_Home(int n) throws AWTException 372 | { 373 | Robot r = new Robot(); 374 | 375 | for (int i = 0; i < n; i++) 376 | r.keyPress(KeyEvent.VK_HOME); 377 | r.keyRelease(KeyEvent.VK_HOME); 378 | } 379 | 380 | // Press Key_End 381 | public static void Key_End(int n) throws AWTException 382 | { 383 | Robot r = new Robot(); 384 | 385 | for (int i = 0; i < n; i++) 386 | r.keyPress(KeyEvent.VK_END); 387 | r.keyRelease(KeyEvent.VK_END); 388 | } 389 | 390 | // Press Key_Alt_Press 391 | public static void Key_Alt_Press() throws AWTException 392 | { 393 | Robot r = new Robot(); 394 | r.keyPress(KeyEvent.VK_ALT); 395 | } 396 | 397 | // Press Key_Alt_Release 398 | public static void Key_Alt_Release() throws AWTException 399 | { 400 | Robot r = new Robot(); 401 | r.keyRelease(KeyEvent.VK_ALT); 402 | } 403 | 404 | // Press Key_Ctrl_Press 405 | public static void Key_Ctrl_Press() throws AWTException 406 | { 407 | Robot r = new Robot(); 408 | r.keyPress(KeyEvent.VK_CONTROL); 409 | } 410 | 411 | // Press Key_Ctrl_Release 412 | public static void Key_Ctrl_Release() throws AWTException 413 | { 414 | Robot r = new Robot(); 415 | r.keyRelease(KeyEvent.VK_CONTROL); 416 | } 417 | 418 | // Press Key_ContextMenu 419 | public static void Key_RightClick() throws AWTException 420 | { 421 | Robot r = new Robot(); 422 | r.keyPress(KeyEvent.VK_CONTEXT_MENU); 423 | r.keyRelease(KeyEvent.VK_CONTEXT_MENU); 424 | } 425 | /*public KeyboardUtils() throws AWTException { 426 | Robot r = new Robot(); 427 | 428 | this.r = new Robot(); 429 | }*/ 430 | 431 | /*public KeyboardUtils(Robot robot) { 432 | Robot r = new Robot(); 433 | 434 | this.r = robot; 435 | }*/ 436 | 437 | 438 | //WORKING : call this and pass a string which is taken as charsequence 439 | public void type(CharSequence characters) throws AWTException { 440 | int length = characters.length(); 441 | for (int i = 0; i < length; i++) { 442 | char character = characters.charAt(i); 443 | type(character); 444 | } 445 | } 446 | 447 | //In case of any letter not working, just add its case (add shift if needed) 448 | public void type(char character) throws AWTException { 449 | switch (character) { 450 | case 'a': doType(VK_A); break; 451 | case 'b': doType(VK_B); break; 452 | case 'c': doType(VK_C); break; 453 | case 'd': doType(VK_D); break; 454 | case 'e': doType(VK_E); break; 455 | case 'f': doType(VK_F); break; 456 | case 'g': doType(VK_G); break; 457 | case 'h': doType(VK_H); break; 458 | case 'i': doType(VK_I); break; 459 | case 'j': doType(VK_J); break; 460 | case 'k': doType(VK_K); break; 461 | case 'l': doType(VK_L); break; 462 | case 'm': doType(VK_M); break; 463 | case 'n': doType(VK_N); break; 464 | case 'o': doType(VK_O); break; 465 | case 'p': doType(VK_P); break; 466 | case 'q': doType(VK_Q); break; 467 | case 'r': doType(VK_R); break; 468 | case 's': doType(VK_S); break; 469 | case 't': doType(VK_T); break; 470 | case 'u': doType(VK_U); break; 471 | case 'v': doType(VK_V); break; 472 | case 'w': doType(VK_W); break; 473 | case 'x': doType(VK_X); break; 474 | case 'y': doType(VK_Y); break; 475 | case 'z': doType(VK_Z); break; 476 | case 'A': doType(VK_SHIFT, VK_A); break; 477 | case 'B': doType(VK_SHIFT, VK_B); break; 478 | case 'C': doType(VK_SHIFT, VK_C); break; 479 | case 'D': doType(VK_SHIFT, VK_D); break; 480 | case 'E': doType(VK_SHIFT, VK_E); break; 481 | case 'F': doType(VK_SHIFT, VK_F); break; 482 | case 'G': doType(VK_SHIFT, VK_G); break; 483 | case 'H': doType(VK_SHIFT, VK_H); break; 484 | case 'I': doType(VK_SHIFT, VK_I); break; 485 | case 'J': doType(VK_SHIFT, VK_J); break; 486 | case 'K': doType(VK_SHIFT, VK_K); break; 487 | case 'L': doType(VK_SHIFT, VK_L); break; 488 | case 'M': doType(VK_SHIFT, VK_M); break; 489 | case 'N': doType(VK_SHIFT, VK_N); break; 490 | case 'O': doType(VK_SHIFT, VK_O); break; 491 | case 'P': doType(VK_SHIFT, VK_P); break; 492 | case 'Q': doType(VK_SHIFT, VK_Q); break; 493 | case 'R': doType(VK_SHIFT, VK_R); break; 494 | case 'S': doType(VK_SHIFT, VK_S); break; 495 | case 'T': doType(VK_SHIFT, VK_T); break; 496 | case 'U': doType(VK_SHIFT, VK_U); break; 497 | case 'V': doType(VK_SHIFT, VK_V); break; 498 | case 'W': doType(VK_SHIFT, VK_W); break; 499 | case 'X': doType(VK_SHIFT, VK_X); break; 500 | case 'Y': doType(VK_SHIFT, VK_Y); break; 501 | case 'Z': doType(VK_SHIFT, VK_Z); break; 502 | case '`': doType(VK_BACK_QUOTE); break; 503 | case '0': doType(VK_0); break; 504 | case '1': doType(VK_1); break; 505 | case '2': doType(VK_2); break; 506 | case '3': doType(VK_3); break; 507 | case '4': doType(VK_4); break; 508 | case '5': doType(VK_5); break; 509 | case '6': doType(VK_6); break; 510 | case '7': doType(VK_7); break; 511 | case '8': doType(VK_8); break; 512 | case '9': doType(VK_9); break; 513 | case '-': doType(VK_MINUS); break; 514 | case '=': doType(VK_EQUALS); break; 515 | case '~': doType(VK_SHIFT, VK_BACK_QUOTE); break; 516 | case '!': doType(VK_SHIFT,VK_1); break;//VK_EXCLAMATION_MARK 517 | case '@': doType(VK_SHIFT,VK_2); break; // correct 518 | case '#': doType(VK_SHIFT,VK_3); break;//VK_NUMBER_SIGN 519 | case '$': doType(VK_SHIFT,VK_4); break;//VK_DOLLAR 520 | case '%': doType(VK_SHIFT, VK_5); break; 521 | case '^': doType(VK_SHIFT,VK_6); break;//VK_CIRCUMFLEX 522 | case '&': doType(VK_SHIFT,VK_7); break;//VK_AMPERSAND 523 | case '*': doType(VK_SHIFT,VK_8); break;//VK_ASTERISK 524 | case '(': doType(VK_SHIFT,VK_9); break;//VK_LEFT_PARENTHESIS 525 | case ')': doType(VK_SHIFT,VK_0); break;//VK_RIGHT_PARENTHESIS 526 | case '_': doType(VK_SHIFT, VK_MINUS); break; //VK_UNDERSCORE 527 | case '+': doType(VK_SHIFT,VK_EQUALS); break;//VK_PLUS 528 | case '\t': doType(VK_TAB); break; 529 | case '\n': doType(VK_ENTER); break; 530 | case '[': doType(VK_OPEN_BRACKET); break; 531 | case ']': doType(VK_CLOSE_BRACKET); break; 532 | case '\\': doType(VK_BACK_SLASH); break; 533 | case '{': doType(VK_SHIFT, VK_OPEN_BRACKET); break; 534 | case '}': doType(VK_SHIFT, VK_CLOSE_BRACKET); break; 535 | case '|': doType(VK_SHIFT, VK_BACK_SLASH); break; 536 | case ';': doType(VK_SEMICOLON); break; 537 | case ':': doType(VK_SHIFT, VK_SEMICOLON); break; //VK_COLON 538 | case '\'': doType(VK_QUOTE); break; 539 | case '"': doType(VK_QUOTEDBL); break; 540 | case ',': doType(VK_COMMA); break; 541 | case '<': doType(VK_SHIFT, VK_COMMA); break; 542 | case '.': doType(VK_PERIOD); break; 543 | case '>': doType(VK_SHIFT, VK_PERIOD); break; 544 | case '/': doType(VK_SLASH); break; 545 | case '?': doType(VK_SHIFT, VK_SLASH); break; 546 | case ' ': doType(VK_SPACE); break; 547 | default: 548 | throw new IllegalArgumentException("Cannot type character " + character); 549 | } 550 | } 551 | 552 | protected void doType(int... keyCodes) throws AWTException { 553 | doType(keyCodes, 0, keyCodes.length); 554 | } 555 | 556 | private void doType(int[] keyCodes, int offset, int length) throws AWTException { 557 | Robot r = new Robot(); 558 | 559 | if (length == 0) { 560 | return; 561 | } 562 | 563 | r.keyPress(keyCodes[offset]); 564 | doType(keyCodes, offset + 1, length - 1); 565 | r.keyRelease(keyCodes[offset]); 566 | } 567 | 568 | //NOTWORKING: call type(charsequence) 569 | 570 | public static void typeString(String s) 571 | { 572 | try { 573 | Robot robik = new Robot(); 574 | byte[] bytes = s.getBytes(); 575 | for (byte b : bytes) 576 | { 577 | int code = b; 578 | // keycode only handles [A-Z] (which is ASCII decimal [65-90]) 579 | if (code > 96 && code < 123) code = code - 32; 580 | robik.delay(40); 581 | robik.keyPress(code); 582 | robik.keyRelease(code); 583 | } 584 | } catch (AWTException e){ 585 | } 586 | } 587 | } --------------------------------------------------------------------------------