How to set PATH variables into macbook ?


 How to set Path variables into mac
  
  Open terminal and hit following command
  
  vim ~/.zshrc
  
  Then Select proper option  Read Only , Edit , Delete etc.
  
  Then Add required varible path
  
  Refer following varibles which is used for Android and iOS automation on macbook
  
  
If VI is not working then hit following command and try commands again. export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

How to identify if an app is native or flutter


 
You can find whether an app is using flutter or not by using the following method,

1) Extract the apk file. You can simply rename the file extension to .zip and extract it.
2) Navigate to the lib folder.
3) You will find a list of subfolders for different architectures.
4) The subfolder will contain a libflutter.so file. This libflutter.so will be present in all 
  flutter apps.

Sauce Lab Cloud APPIUM Automation Demo


First We need to create free trail account on Sauce Lab
  
  https://saucelabs.com/
 
  
Login Sauce Lab Account and Open following url . We will get all necessary steps in below document which is provided by Saucelab
 
  
  https://www.browserstack.com/docs/app-automate/appium/getting-started/java
  
  
We will get sample app for android and iOS on following sauce lab link
  
  https://github.com/saucelabs/sample-app-mobile/releases
  

We will get devices list on following link
  https://saucelabs.com/platform/supported-browsers-devices
Note: Username and Access key is important while performing testing sauce lab
  
  Execution 
  
  

How to install iOS and Android build into Simulator/Emulator through Terminal


  In IOS
We need .app file to install into iPhone Simulator
  
Then Open terminal and follow given below steps
  
  1) Enter following command to get device list
  
  xcrun simctl list
  
  2) Then Copy simualtor UDID which we want to install app
  
  3) Enter following command to install app
  
  xcrun simctl install 700332EF-8DE1-4040-B5F9-CC56D9CB1554 ~/Desktop/Runner.app
  
  where 700332EF-8DE1-4040-B5F9-CC56D9CB1554 is simulator UDID and ~/Desktop/Runner.app is path of .app file
  
  
  In ANDROID,
   We need .apk file to install into android emulator
  
    Then Open terminal and follow given below steps
  
    1) Enter following command to get device list
  
    adb install ~/Desktop/46.apk
  
    where ~/Desktop/46.apk is path of apk
  

Abstarct and Interface Class/ Methods use in Selenium Webdriver


Selenium is an interface and the Class like FirefoxDriver, ChromeDriver, 
  InternetExplorerDriver, SafariDriver and AndroidDriver which implement the 
  Selenium interface has their own implementation for the all the abstract methods
  in Selenium interface. So all the Classes are implementing the same interface to 
  have the same methods across all the browsers but the methods implemented 
  (coding of method body) will be different for FirefoxDriver (to make the automation 
  work for Firefox Browser) and ChromeDriver (methods implemented differently to make
  the automation work on Chrome Browser)
  
  
WebDriver driver = new FirefoxDriver();

Or

WebDriver driver = new ChromeDriver();

Here, WebDriver Is Interface and FirefoxDriver and ChromeDriver are the class files where 
WebDriver Interface Is Implemented.

Use of Collection and Selenium Webdriver

Collections in java is a framework that provides an architecture to store and manipulate the 
group of objects. The Collection helps the user to store only the Object class type, but every 
single class in java is subclass to Object class, which means we can store anything with help 
classes present in the collection.
  
  
Where we use collections in selenium : Whenever we deal with more than one item, then we 
use collections in selenium webdriver. Few places are:
  

when we try to retrieve the more than one match of elements
when we handle multiple tabs/windows
When we retrieve option from the dropdown using getOptions() method
  
  
how to use arraylist in selenium webdriver
As per my knowledge, we do not use ArrayList in selenium, but we do use List. People prefer List 
over ArrayList because when you use a List, you can store a different kind of list categories 
like ArrayList, LinkedList, TreeList so on. But when we use ArrayList, then we can only store 
only the ArrayList type.

This is the primary reason why the findElements method returns List(broad) rather than ArrayList(narrow).
  
  
Now if you are like me then you get this doubt, why cannot I use ArrayList for it instead of List.
So we have to store the value based on the return type only, so when you should store the list of web elements using List only. But I did not mean that we cannot store the list of web elements in ArrayList, but it is not recommended. If you think who cares about the recommendation, then you got to downcast the returned values to store it in ArrayList with selenium.
For example, if we want to verify a value by splitting the string output, then splitting always returns an Array of values., there values will be substrings.
Few things to remember about for each loop: It starts with the keyword for like a normal for-loop. Instead of declaring and initializing a loop counter variable, you declare a variable that is the same type as the base type of the array, followed by a colon, which is then followed by the array name. In the loop body, you can use the loop variable you created rather than using an indexed array element. It's commonly used to iterate over an array or a Collections class (e.g., ArrayList, HashSet) You might need to declare a variable outside the loop if you want to terminate the loop after some iterations how to use Set in selenium webdriver Java Set is a collection of objects that allows no duplicate elements to be stored. Java Set is an interface that extends the Collection interface. Unlike List, Java Set is NOT an ordered collection; its elements does NOT have a particular order. Java Set does NOT provide control over the position where you can insert an element. You cannot access elements by their index and also search elements in the list. Set is used when we are dealing with a unique element or values like window handles, getWindowHandles()returns set of String Set allGUID = driver.getWindowHandles(); how to use the Map in selenium We can use Maps or hashMaps in selenium when we want to read key-pair values; For example, when we read data from the properties files or JSON file, we would be using HashMaps along with Selenium. Maps are perfect to use for key-value association mapping such as dictionaries. The maps are used to perform lookups by keys or when someone wants to retrieve and update elements by keys. Some examples are: A map of error codes and their descriptions. A map of zip codes and cities. A map of managers and employees. Each manager (key) is associated with a list of employees (value) he manages. A map of classes and students. Each class (key) is associated with a list of students (value).

JMeter Jenkins Integration


STEP 1: Install JMeter
  
  https://jmeter.apache.org/download_jmeter.cgi

STEP 2: Create a sample script in jemter
  
Start JMeter
  
Go to the bin folder exist in downloaded JMeter folder and Double click on 
ApacheJMeter.jar
Add Thread Group ex. demo and add Number of threads, remp up time and Loop count
Then Add Http Request
Then add Table and Graph Listener
Then Add some assertion points for request verification ex status code, duration , Size
Then Execute Script
Now save script in to default location . ex /Users/apple/Desktop/apache-jmeter-5.4.1/bin STEP 3: Create job in Jenkins First install Performance Trend Per Test Case plugin from plugin manager Create a free style job ex. jmeter jenkins demo Then add following configuration
cd /Users/apple/Desktop/apache-jmeter-5.4.1/bin sh jmeter.sh -Jjmeter.save.saveservice.output_format=xml -n -t /Users/apple/Desktop/apache-jmeter-5.4.1/bin/Demo.jmx -l /Users/apple/Desktop/apache-jmeter-5.4.1/bin/TestResult1.jtl
first part is jmeter script and another is report generation file name and location
Then add peformance Trend report in post build
Then execute build 3-4 times , we will get following reports
Execution Demo

What is StaleElementReferenceException in Selenium Webdriver

Stale means old, decayed, no longer fresh. Stale Element means an old element or no 
longer available element. Assume there is an element that is found on a web page referenced
as a WebElement in WebDriver. If the DOM changes then the WebElement goes stale. If we try 
to interact with an element which is staled then the StaleElementReferenceException is thrown.
  
  
What are the Causes of StaleElement Exception
We face this stale element reference exception when the element we are interacting with is destroyed 
and then recreated again. When this happens the reference of the element in the DOM becomes stale. 
Hence we are not able to get the reference to the element.
  
  
Cause 1: The referenced web element has been deleted completely. 
Cause 2: The referenced element is no longer attached to the DOM
  

How To Overcome Stale Element Reference Exception in Selenium:
  
Solution 1: Refreshing the web page
driver.navigate().refersh();
driver.findElement(By.xpath("xpath here")).click();
  
Solution 2: Using Try Catch Block
  for(int i=0; i<=2;i++){
  try{
     driver.findElement(By.xpath("xpath here")).click();
     break;
  }
  catch(Exception e){
     Sysout(e.getMessage());
  }
}
                         
Solution 3: Using ExpectedConditions.refreshed                         
  
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("table")));
                         
Solution 4: Using POM
We could avoid StaleElementException using POM. In POM, we use initElements() method which
loads the element but it won’t initialize elements. initElements() 
takes latest address. It initializes during run time when we try to 
perform any action on an element. This process is also known as Lazy Initialization.
                         
                                                 

How To Resolve Element Not Interactable Exception In Selenium

  
What is ‘element not interactable’ exception in selenium? OR
[exception in thread “main” org.openqa.selenium.elementnotinteractableexception: 
 element not interactable]
When a web element is present in the HTML DOM but it is not in the state that can be 
interacted. In other words when element is found but we can’t interact with it, then it throws ElementNotInteractableException.

Reason behind this exception: –
“element not interactable” exception may occur due to various reason.

Element is not visible
Element is present in off screen (After scroll down it will display)
Element is present behind any other element
Element is disable
  
  
Solutions: –

If element is not visible then wait until element is visible. For this we will use wait
command in selenium

WebDriverWait t = new WebDriverWait(driver, timeout); 
t.until(ExpectedConditions.visibilityOf(element));  
t.until(ExpectedConditions.elementToBeClickable(element));

If element is in off screen then we need to scroll down the browser and interact with element.
We will use JavaScriptExecutor interface that helps to execute JavaScript method through Selenium
Webdriver.

JavascriptExecutor Js1 = (JavascriptExecutor) driver;
Js1.executeScript("window.scrollBy(0,1000)");                   //scroll 1000 pixel vertical

How to handle multiple window in selenium

  
import java.util.Iterator; 
import java.util.Set; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class WindowHandle_Demo { 
	public static void main(String[] args) throws Exception {


		System.setProperty("webdriver.chrome.driver","Path to the driver"); 
		WebDriver driver = new ChromeDriver();

		driver.manage().window().maximize();

		// Load the website
		driver.get("http://www.naukri.com/");

		// It will return the parent window name as a String
		String parent=driver.getWindowHandle();
	
		Sets=driver.getWindowHandles();

		// Now iterate using Iterator
		Iterator I1= s.iterator();

		while(I1.hasNext())
		{

			String child_window=I1.next();


			if(!parent.equals(child_window))
			{
				driver.switchTo().window(child_window);

				System.out.println(driver.switchTo().window(child_window).getTitle());

				driver.close();
			}

		}
		//switch to the parent window
		driver.switchTo().window(parent);

}
}

Rules for Writing Automated Tests

  
Rules for Writing Automated Tests
  
Rule 1: Prioritize: Most apps include thousands of scenarios. Start by listing
the most important user flows, for example login, add to cart, checkout, etc.
  
Rule 2: Reduce, Recycle, Reuse: Break the user’s scenarios down to simple, single 
purpose, almost atomic flows. e.g. “Create user,” “Login,”  “Send email,” etc. Create a 
test for each of these flows. When completed, compare this to the the user stories.
Naming convention – Defining a good naming convention is an important part. For example,
including the component name in the flow name, which can result in flow structure (e.g 
“Account.login“ and “Account.logout”).
Reuse components. Don’t Copy/paste – for non-experienced developers/testers, a copy/paste 
seems like a reuse. However, the challenge is to update those steps when the flow changes. 
Even a single step/line that repeats in hundreds of tests is a huge hassle.

  
Rule 3: Create Structured, Single-Purpose Tests: Single purpose tests verify one
thing only!. 
  
Rule 4: Tests’ Initial State Should Always be Consistent: Since automated tests always
repeat the same set of steps, they should always start from the same initial state. The most
common maintenance issues when running automated tests are ensuring the integrity of the initial 
state. Since automated tests depend on that state, if it is not consistent test results won’t be
, either. The initial state is usually derived from user previous actions.
  
Rule 5: Compose Complex Tests from Simple Steps: Complex tests should emulate real user 
scenarios, you should prefer composing those test from simple tests parts (shared steps) 
instead of recording the entire scenario directly. Since you already tested all the simple
actions in the simple tests, the complex tests should only fail on integration issues 
  
Rule 6: Add Validations in Turnover Points: Validations are usually used at the end
of the test to signal the test is in a passed/failed state. It is also best to add them
at points of major changes as a checkpoint to stop the test if an action failed. 
  
Rule 7: No Sleep to Improve Stability: Sleep with random duration (what I call magic
numbers) is one of the main sources of flaky tests.The reason to avoid static sleep is you 
rarely know the load of machine upon you run the test on. Only in performance testing do
you have the machine to yourself (knowing for sure all CPU and memory are for you).
  
Rule 8: Use a Minimum Two Levels of Abstractions: If your test is composed mostly of
user interactions, such as clicks and set-text actions, then you’re probably doing something
wrong. If you used low-level frameworks (e.g. Selenium), you might have heard of the PageObject
Design Pattern, which recommends to separate the business logic (e.g. login) from the low-level 
implementation (e.g. set username, set password and click login button). 
  
  
Rule 9: Reduce the Occurrences of Conditions:- A test should have as few as possible 
conditions (if-statements). Those that have many are usually unpredictable (don’t know 
the exact state you’re in) or complex (you might even see loops, too). Try to simplify your tests by:

Start your test at a predefined state;
Disable random popups; and
Disable random A/B testing, and choose a specific flow.
  
Rule 10: Write Independent and Isolated Tests: An important methodology of test 
authoring is creating self contained, independent flows. This allows to run tests in 
high parallelism, which is crucial for scaling the test suites.
  

How to run cuucmber script on multiple browser

 

  We can write start method in base class like below
  
  
  @Before
   public WebDriver start() {

        String webdriver = System.getProperty("browser", "chrome");
        switch(webdriver) {
            case "firefox":
                System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "/geckodriver");
                driver = new FirefoxDriver();
                driver.get("http://live.guru99.com/");
                driver.manage().window().maximize();
                waitDriver = new WebDriverWait(driver, TIMEOUT);
                driver.manage().timeouts().implicitlyWait(TIMEOUT, TimeUnit.SECONDS);
                driver.manage().timeouts().pageLoadTimeout(PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
                return driver;
            case "chrome":
                System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/chromedriver");
                driver = new ChromeDriver();
                driver.get("http://live.guru99.com/");
                driver.manage().window().maximize();
                waitDriver = new WebDriverWait(driver, TIMEOUT);
                driver.manage().timeouts().implicitlyWait(TIMEOUT, TimeUnit.SECONDS);
                driver.manage().timeouts().pageLoadTimeout(PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
                return driver;
            default:
                throw new RuntimeException("Unsupported webdriver: " + webdriver);
        }

}
  
  
  Then we can run like mvn test -Dbrowser=chrome or mvn test -Dbrowser=firefox
  
  Default browser we set chrome
  
  mvn test 

Docker - Selenium Grid Web Demo

  
--------------------------------DOCKER INTALLATION----------------------------------------------
Step 1: We need to install docker
  
Go to the docker offical website https://www.docker.com/
Click on Get started button
Then Download docker as per your OS. I have used macOS for demo purpose
  
After downloading, Just install it.
  
  
Step 2:- Create a free account on docker website
  
Step 3:- Check docker installed or not successfully
  
Open terminal and hit following command
  
docker version
We will get docker info Then hit following command to get complete info of docker
docker info
Then try to verify image
docker run hello-world
Then hit following command to get list of images exist into docker container docker run hello-world Step 4: Start docker application and login in.
Now we are going to create selenium grid docker demo
--------------------------------SELENIUM GRID IMAGES INSTALLATION---------------------------------------------- Step 5: First we need to install all required images Go to the google and search
docker selenium
and open first result or docker selenium url https://github.com/SeleniumHQ/docker-selenium Install following docker dependecies to execute Selenium Grid Open terminal and hit following command one by one Selenium hub
docker pull selenium/hub
Selenium firefox node
docker pull selenium/node-firefox
Selenium chrome node
docker pull selenium/node-chrome
Selenium firefox debug
docker pull selenium/node-firefox-debug
Selenium chrome debug
docker pull selenium/node-chrome-debug
Then check list of images, We will get above mentioned all images in result. Same will get in Docker desktop Application
docker images
--------------------------------START HUB AND NODE--------------------------------------------- Step 6: Now we need to start hub and node to execute script Start hub :
docker run -d -p 4545:4444 --name selenium-hub selenium/hub
Note:- Here we can take any name To check hub is started or not, Open browser and enter
http://localhost:4545/
. We will get hub console Start Node for Firefox
docker run -d -P --link selenium-hub:hub selenium/node-firefox-debug
To check node started or not, Open broweser and check node into hub Start Node for Chrome
docker run -d -P --link selenium-hub:hub selenium/node-chrome-debug
To check node started or not, Open broweser and check node into hub
--------------------------------VNC INSTALLATION TO VIEW NODE CONSOLE ---------------------------------- Step 7: To view firefox and chrome docker console, We need to download vnc and install it https://www.realvnc.com/en/connect/download/viewer/macos/ Start vnc , enter node url 0.0.0.0:55000 chrome will start , here 55000 is assigned to chrome browser node 0.0.0.0:55001 Firefox will start , here 55001 is assigned to firefox browser node
--------------------------------SELENIUM SCRIPT---------------------------------------------- Step 8: We need to create demo automation script to execute on nodes Create selenium script ex. Firefox
import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.Test; import java.net.MalformedURLException; import java.net.URL; public class ffdemo { @Test public void testApp() throws MalformedURLException, InterruptedException { DesiredCapabilities cap= new DesiredCapabilities(); cap.setBrowserName(BrowserType.FIREFOX); WebDriver driver=new RemoteWebDriver(new URL("http://localhost:4545/wd/hub"),cap); driver.get("https://www.google.com/"); driver.findElement(By.name("q")).sendKeys("Autoamtion testing"); Thread.sleep(5000); driver.quit(); } }
ex. Chrome package dockerdemo; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.BrowserType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.Test; import java.net.MalformedURLException; import java.net.URL; public class chromedemo { @Test public void testApp() throws MalformedURLException, InterruptedException { DesiredCapabilities cap= new DesiredCapabilities(); cap.setBrowserName(BrowserType.CHROME); WebDriver driver=new RemoteWebDriver(new URL("http://localhost:4545/wd/hub"),cap); driver.get("https://www.google.com/"); driver.findElement(By.name("q")).sendKeys("Autoamtion testing"); Thread.sleep(5000); driver.quit(); } } tetsng.xml for parallel execution How to execute script:- Right click on testng.xml and run as suite
--------------------------------EXECUTE SCRIPT---------------------------------------------- Step 9: Execute script , Execution will start on both console , Firefox ( 0.0.0.0:55001) and chrome ( 0.0.0.0:55000 )
--------------------------------EXECUTION DEMO---------------------------------------------- Execution Demo

What is JMeter

  
What is JMeter? Why it is used?
The Apache JMeterTM is pure Java open source software, which was first developed by
  Stefano Mazzocchi of the Apache Software Foundation, designed to load test functional
  behavior and measure performance. You can use JMeter to analyze and measure the performance
  of web application or a variety of services. Performance Testing means testing a web application
  against heavy load, multiple and concurrent user traffic. JMeter originally is used for testing 
  Web Application or FTP application.
  
 
Demo
 

OOPS real time examples into webdriver

  
1) ABSTRACTION
2) INTERFACE
3) INHERITANCE
4) POLYMORPHISM
5) METHOD OVERLOADING
6) METHOD OVERRIDING
7) ENCAPSULATION

-------------------------------------------------------------------------------------------------------  
 ABSTRACTION
In Page Object Model design pattern, we write locators (such as id, name, xpath etc.,) in a 
Page Class. We utilize these locators in tests but we can’t see these locators in the tests.
Literally we hide the locators from the tests.

Abstraction is the methodology of hiding the implementation of internal details and showing the
functionality to the users.

-------------------------------------------------------------------------------------------------------  
INTERFACE
Basic statement we all know in Selenium is WebDriver driver = new FirefoxDriver();

WebDriver itself is an Interface. So based on the above statement WebDriver driver = new FirefoxDriver();
we are initializing Firefox browser using Selenium WebDriver. It means we are creating a 
reference variable (driver) of the interface (WebDriver) and creating an Object. Here
WebDriver is an Interface as mentioned earlier and FirefoxDriver is a class.

An interface in Java looks similar to a class but both the interface and class are two different 
concepts. An interface can have methods and variables just like the class but the methods 
declared in interface are by default abstract. We can achieve 100% abstraction and multiple 
inheritance in Java with Interface.

-------------------------------------------------------------------------------------------------------  
INHERITANCE
We create a Base Class in the Framework to initialize WebDriver interface, WebDriver waits,
Property files, Excels, etc., in the Base Class.

We extend the Base Class in other classes such as Tests and Utility Class. Extending one 
class into other class is known as Inheritance.

-------------------------------------------------------------------------------------------------------  
POLYMORPHISM
Combination of overloading and overriding is known as Polymorphism. We will see both 
overloading and overriding below.

Polymorphism allows us to perform a task in multiple ways.

METHOD OVERLOADING
We use implicit wait in Selenium. Implicit wait is an example of overloading. In Implicit 
  wait we use different time stamps such as SECONDS, MINUTES, HOURS etc.,

A class having multiple methods with same name but different parameters is called Method Overloading

METHOD OVERRIDING
We use a method which was already implemented in another class by changing its parameters. 
To understand this you need to understand Overriding in Java.

Declaring a method in child class which is already present in the parent class is called 
Method Overriding. Examples are get and navigate methods of different drivers in Selenium .
-------------------------------------------------------------------------------------------------------  
ENCAPSULATION
All the classes in a framework are an example of Encapsulation. In POM classes, we declare
the data members using @FindBy and initialization of data members will be done using 
Constructor to utilize those in methods.

Encapsulation is a mechanism of binding code and data together in a single unit.

-------------------------------------------------------------------------------------------------------  
Following are some important topics

WEB ELEMENT:
Web element is an interface used to identify the elements in a web page.

WEBDRIVER:
WebDriver is an interface used to launch different browsers such as Firefox, Chrome,
Internet Explorer, Safari etc.,

FIND BY:
FindBy is an annotation used in Page Object Model design pattern to identify the elements.

FIND ELEMENT:
Find Element is a method in POM to identify the elements in a web page.