This is a many part series. More videos pertaining to this will be added. Complete You tube playlist:
Video Tutorial: GitHub Repo: https://github.com/akashdktyagi/AutoFratCommonLib Code: Runner File:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
package runner; import org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions ( features="classpath:features", glue="", tags="", plugin = {"pretty", "html:target/html/", "json:target/json/file.json", "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"}, dryRun=false ) public class RunTest { } |
2. Step Defs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
package stepdefs; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import cucumber.api.Scenario; import cucumber.api.java.Before; import cucumber.api.java.en.Given; public class StepDefs { Scenario scenario; @Before public void SetUp(Scenario s) { scenario = s; } @Given("I open the Browser and Navigate to the URL {string}") public void i_open_the_Browser_and_Navigate_to_the_URL(String string) { WebDriver driver = new ChromeDriver(); driver.get(string); scenario.write("Opened the Browser with URL: " + string); } } |
3. POM File:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.visionit</groupId> <artifactId>CanBeDeleted</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <cucumber.version>4.2.0</cucumber.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M1</version> <configuration> <parallel>methods</parallel> <threadCount>2</threadCount> <perCoreThreadCount>false</perCoreThreadCount> <!-- <useUnlimitedThreads>true</useUnlimitedThreads>--> <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine> </configuration> </plugin> </plugins> </build> <!-- For Cucumber --> <dependencies> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>${cucumber.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit</artifactId> <version>${cucumber.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <!-- For dependency Injection --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-picocontainer</artifactId> <version>${cucumber.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> <!-- For Extent Reports --> <!-- Extent Report Adapter for Cucumber --> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports-cucumber4-adapter</artifactId> <version>1.0.7</version> </dependency> <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports --> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>4.0.9</version> </dependency> <!-- https://mvnrepository.com/artifact/org.freemarker/freemarker --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.28</version> </dependency> <!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver --> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>3.10.2</version> </dependency> </dependencies> </project> |
Steps to take: Create account in Git Hub. https://github.com/ Note down user name, email and password. Down load git from git-scm…
Automation Framework design patterns: Before we understand Automation Design patterns we first need to understand the components of an Automation…
This is a recording of class room sessions. During these session we will be covering FW creation using Cucumber and…
This is a recording of multiple class rooms lectures. Artifacts/code is kept in git at below locations: Best Buy API…
This is a multi part series of videos and tutorials. Most of these sessions are recorded during the live class…
This is a sample project to automate rest full API. Will add more such code and tutorial coming forward. POM.XML…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
package dev.backup.akash.codesnippets; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import org.testng.Assert; public class HandlingMegaMenuAmazon { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\Users\\Devina\\Downloads\\chromedriver_win32\\chromedriver.exe"); //1 Create Driver object WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); //Navigate and click on the link driver.get("https://www.amazon.in/"); HandleMegaMenu_SelectItems(driver,"Mobiles, Computers","Tablets"); } public static void HandleMegaMenu_SelectItems(WebDriver driver, String category, String sub_category) { //Get shop-all element and hover on it by using Actions Class WebElement shop_all = driver.findElement(By.id("nav-link-shopall")); //Use Actions class for mouse over Actions action = new Actions(driver); action.moveToElement(shop_all).build().perform(); //Find the Category element and mouse over it //WebElement category_element = driver.findElement(By.xpath("//span[@class='nav-text' and text()='Fire TV Stick']")); WebElement category_element = driver.findElement(By.xpath("//span[@class='nav-text' and text()='" + category + "']")); action.moveToElement(category_element).build().perform(); //Find the Sub Category element and click //WebElement category_element = driver.findElement(By.xpath("//span[@class='nav-text' and text()='Fire TV Stick']")); WebElement sub_category_element = driver.findElement(By.xpath("//span[@class='nav-text' and text()='"+ sub_category +"']")); sub_category_element.click(); //Valdiation here using page titles or some page header } } |
Code to find all broken links in a web page. Broken links are the links which navigates no where, i.e.…
Open Url: https://www.flipkart.com (Do not Login) and validate the page is opened by checking the title and a page locator. Search…
What is A FW A FW is a blueprint or a set of guidelines to organize the code. It tells…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
package AutoIt; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.Reporter; import org.testng.annotations.Test; /** * * @author PALLLAVI TANDALE * */ /** * UploadFile class * */ package AutoIt; import java.io.IOException; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; public class UploadFile{ WebDriver driver; @Test public void testautoit() throws Throwable { System.setProperty("webdriver.chrome.driver","E:\\chromedriver.exe"); driver=new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(2000,TimeUnit.SECONDS); driver.get("http://tinyupload.com/"); driver.findElement(By.xpath("//input[@name='uploaded_file']")).click(); //runtime is a class to run Auto IT Script Runtime.getRuntime().exec("C:\\Users\\MAYUR\\Desktop\\AutoIt\\FileUpload.exe"); Thread.sleep(3000); driver.quit(); } } /** * *Auto IT Script */ ControlFocus("Open","","Edit1") Sleep(3000) ControlSetText("Open","","Edit1","C:\Users\MAYUR\Desktop\AutoIt\UploadFile.txt") Sleep(3000) ControlClick("Open","","Button1") |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
package string_manipulation; import java.util.Scanner; public class ReverseString { public static void main(String[] args) { Scanner scn=new Scanner(System.in); System.out.println("Enter your string to check palindrome"); String s=scn.nextLine(); scn.close(); String []s1=s.split(""); String reverseString=""; for(int i=s1.length-1;i>=0;i--){ reverseString=reverseString+s1[i]; } System.out.println(reverseString); if(s.equals(reverseString)){ System.out.println("Given string is a palindrom"); } else{ System.out.println("Given string is not a palindromen"); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
//Using Hashmap package string_manipulation; import java.util.HashMap; public class CharCountInStringUsingHashMap { public static void main(String[] args) { //Creating a HashMap containing char as a key and occurrences as a value String inputString="My name is Snehal Dasharsth Jadhav"; HashMap<Character, Integer> charCountMap = new HashMap<Character, Integer>(); //Converting given string to char array char[] strArray = inputString.toCharArray(); //checking each char of strArray for (char c : strArray) { if(charCountMap.containsKey(c)) { //If char is present in charCountMap, incrementing it's count by 1 charCountMap.put(c, charCountMap.get(c)+1); } else { //If char is not present in charCountMap, //putting this char to charCountMap with 1 as it's value charCountMap.put(c, 1); } } //Printing the charCountMap System.out.println(charCountMap); } } //Using for loop package string_manipulation; public class charCountInString { public static void main(String[] args) { String s=new String("My name is snehal dasharath jadhav "); char []a=s.toCharArray(); for(int i=0;i<a.length;i++){ int count=1; for(int j=i+1;j<a.length;j++) { if(a[i]==a[j]) { count++; a[j]= '0'; } } if(count>1 && a[i]!='0'){ //System.out.println(a[i]); System.out.println("number of times repeated "+a[i]+" is "+count); } } }} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
package string_manipulation; public class StringMethods { public static void main(String[] args) { String s=" hello Friends "; String s2 = s.concat("my name is abc"); System.out.println(s); s=s.concat("my name is abc"); System.out.println(s); //equals method check the content of string so it will return boolean value if(s.equals(s2)) { System.out.println("both are same"); } else{ System.out.println("different in equals"); } //It will check address of giver reference variable &return boolean value if(s==s2){ System.out.println("Pointing to same address"); } else{ System.out.println("pointing to different address"); } //It will give the length of string System.out.println(s.length()); //It will return the character of 4th index System.out.println(s.charAt(4)); //To remove whitespaces from starting and ending of perticular string System.out.println(s.trim()); //to check string is empty or not it will return boolean value System.out.println(s.isEmpty()); // It will replace character 'e' with 's' System.out.println(s.replace("e", "S")); //return the address of the string object System.out.println(s.hashCode()); //Convert the given string into upperCase System.out.println(s.toUpperCase()); // split() will convert string into string array String[] a = s.split(""); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
/****author: Bindiya Patil****/ /****forEach()method****/ package program; import java.util.ArrayList; import java.util.List; public class ForEachmethod { public static void main(String[] args) { List<String> fruits = new ArrayList<String>(); fruits.add("Apple"); fruits.add("Orange"); fruits.add("Banana"); fruits.add("Pear"); fruits.add("Mango"); //lambda expression in forEach Method fruits.forEach(str->System.out.println(str)); } } /****functional interface***/ package program; public interface functional_interface { public int add(int a, int b); } /****Lambda Expression****/ package program; public class lambda_expression { public static void main(String[] args) { functional_interface d2=(a,b)-> (a+b); System.out.println(d2.add(10, 20)); } } /***Stream API*****/ package program; import java.util.ArrayList; import java.util.List; public class Stream_API { public static void main(String[] args) { List<String> names = new ArrayList<String>(); names.add("Ajeet"); names.add("Negan"); names.add("Aditya"); names.add("Steve"); //Using Stream and Lambda expression long count = names.stream().filter(str->str.length()<6).count(); System.out.println("There are "+count+" strings with length less than 6"); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
package ChromeHeadless; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.firefox.FirefoxBinary; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; /** * * @author Sarang Holey * * 10:49:00 pm */ public class BrowserHeadlessImplimentations { // creating WebDriver instance as static static WebDriver driver; public static void main(String[] args) { // calling static chrome driver headless method ChromeHeadless("https://www.facebook.com"); // calling static firefox driver headless method FirefoxHeadless("https://www.flipkart.com"); } /** * * @param URL */ public static void ChromeHeadless(String URL) { // setting up chromedriver system properties System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); //creating ChromeOptions object ChromeOptions options = new ChromeOptions(); // adding arguments for activation of chrome browser in headless mode options.addArguments("--headless"); // creating ChromeDriver instance with argument to the constructor ChromeOptions instance driver = new ChromeDriver(options); // passing the URL from method argument driver.get(URL); // printing title of the given URL page of the Website System.out.println(driver.getTitle()); } /** * * @param URL */ public static void FirefoxHeadless(String URL) { // creating object of firefox binary FirefoxBinary firefoxbinary = new FirefoxBinary(); // adding the argument to activate headless mode of firefox firefoxbinary.addCommandLineOptions("--headless"); // setting up chromedriver system properties System.setProperty("webdriver.gecko.driver", "geckodriver.exe"); // creating FirefoxOptions object FirefoxOptions fo = new FirefoxOptions(); // setting up firefoxbinary fo.setBinary(firefoxbinary); // creating FirefoxDriver instance with argument to the constructor FirefoxOptions instance WebDriver driver = new FirefoxDriver(fo); // passing the URL from method argument driver.get(URL); // printing title of the given URL page of the Website System.out.println(driver.getTitle()); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
package TakeScreenshotReusable; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; /** * * @author Sarang Holey * * 9:15:22 pm */ public class ScreenshotReusable { static WebDriver driver; public static void main(String[] args) { // Setting up browser properties System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); // creating object of ChromeDriver with the reference of WebDriver interface driver = new ChromeDriver(); // passing the required url driver.get("https://www.google.co.in"); // calling the re-usable function for taking screenshot of current page on browser takeScreenshot("google"); } //Reusbale function for capturing screenshot with unique filename /** * * @param fileName */ public static void takeScreenshot(String fileName) { // capturing screenshot as output type file from getScreenshotAs method by up casting the WebDriver reference to TakeScreenshot Interface File file = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try { // Coping screenshot file into Screenshots folder with Filename from argument along with current time appended to file name FileUtils.copyFile(file, new File("../TakeScreenshot/src/test/resources/Screenshots/"+fileName+""+System.currentTimeMillis()+".png")); } catch (IOException e) { // catching the exception while file handling e.printStackTrace(); } } } |
This can be explained as a Challenging Scenario in interviews as below: “UI-DB validation: I faced a scenario where I…
Perfect Example of why you need Abstraction is: WebDriver driver = new ChromeDriver(); In above line “WebDriver” is an interface…
Below is the code for JDBC MySQl connection and reusable method which return 2 D array. GitHub location: https://github.com/akashdktyagi/AutomationPoCCucumber/tree/master/src/test/java/bddcucumber/managers/dbmanager Code:…
In this three part video sessions, I have explained how to create the new feature file and their respective step…
Cucumber with Java Tutorial and Framework. Cucumber Framework Demo Video: Below is a complete Cucumber tutorial and base framework kept…
Below are the List of all top level test cases for Testing a Health Care Domain Application. For each test…
Selenium Web Table Handling using XPATH and XPATH Axes
This is a basic automation test to automate zero app
Framework Development Part 4-All about Git and how to use Git in a Live Team Set Up Check for the…
Check for the Latest copy of the Framework here at git hub: https://github.com/akashdktyagi/AutomationPoCFW Part 3: This video contains Discussion around…