Tuesday, December 22, 2020

How to create Build Pipeline in Jenkins


Step1: login to Jenkins

Step2: Click Dashboard




Step 3. Click on New Item


Step 4. Enter Job name.

Ex. I have entered ‘SimpleDemoJob’

Steps 5. Select Freestyle project and Click on ‘OK’ button


 

Steps 6. After clicking on ‘OK’ button. You will navigate to dashboard and observe job, which we just created.








Step 7. Click on Job we just created.

Step 8. Click on ‘Configure’






Step 8. Click on Build section. And Select ‘Execute windows batch command’ from ‘Add build step’

Step 9. Add below command, just for testing purpose

echo %DATE%

echo %Time%

echo "Build process successfully done...."




Step 10. Click on Apply and Save



Step 11. Similarly, Create others job

SampleTestJob

SampleDeployJob

SampleReleaseJob





Step 12. Now add job dependency Click on ‘SampleDeployJob’

Go toà Build Trigger à Build after other project are built à Enter SampleBuildJob

 

Stepe 13. Similarly, Add job dependency for other jobs also.


Click on ‘SampleTestJob’

Go toà Build Trigger à Build after other project are built à Enter SampleDeployJob

 

Stepe 14. Similarly, Add job dependency for other jobs also.

Click on ‘SampleReleaseJob’

Go toà Build Trigger à Build after other project are built à Enter SampleTestJob

 

Now click on Dashboard,

Click on ‘+’ as highlight in below screenshot




Step 15. Enter View Name à PipelineDemo

Step 16. Select Build PipeLine view and Click on OK


Step 17. Select Upstream/ downstream config

Select Parent job name, In your case parent job is SampleBuildJob on which others jobs are depends.





Step 18. Click on OK

Step 19. Observe the Build Pipeline

When you run the pipeline by clicking on RUN button. All jobs will run in sequence

SampleBuildJob à SampleDeployJob à SampleTestJobàSampleReleaseJob




















Sunday, December 20, 2020

Set up Selenium GRID on windows Machine



Selenium Grid:




java -jar selenium-server-standalone-3.141.59.jar -role hub




java -Dwebdriver.chrome.driver="D:\Desktop_Data\chromedriver_win32\chromedriver1.exe" -jar selenium-server-standalone-3.141.59.jar -role webdriver -hub http://192.168.0.104:4444/grid/register -port 5566


java -Dwebdriver.chrome.driver="D:\Desktop_Data\chromedriver_win32\edge\msedgedriver.exe" -jar selenium-server-standalone-3.141.59.jar -role webdriver -hub http://192.168.0.104:4444/grid/register -port 5566

Know about Selenium GRID

What is Selenium GRID?
Selenium Grid allows the execution of WebDriver scripts on remote machines (virtual or real) by routing commands sent by the client to remote browser instances. It aims to provide an easy way to run tests in parallel on multiple machines.

Selenium Grid allows us to run tests in parallel on multiple machines, and to manage different browser versions and browser configurations centrally (instead of in each individual test).

Purposes and main functionalities of Selenium GRID
  • Central entry point for all tests
  • Management and control of the nodes / environment where the browsers run
  • Scaling
  • Running tests in parallel
  • Cross platform testing
  • Load balancing

Why you might want to use Grid
To run your tests against multiple browsers, multiple versions of browser, and browsers running on different operating systems.
To reduce the time it takes for the test suite to complete a test pass. 


Selenium GRID Architecture



Hub
  • Intermediary and manager
  • Accepts requests to run tests
  • Takes instructions from client and executes them remotely on the nodes
  • Manages threads

A Hub is a central point where all your tests are sent. Each Selenium Grid consists of exactly one hub. The hub needs to be reachable from the respective clients (i.e. CI server, Developer machine etc.) The hub will connect one or more nodes that tests will be delegated to.


Nodes
  • Where the browsers live
  • Registers itself to the hub and communicates its capabilities
  • Receives requests from the hub and executes them

Nodes are different Selenium instances that will execute tests on individual computer systems. There can be many nodes in a grid. The machines which are nodes do not need to be the same platform or have the same browser selection as that of the hub or the other nodes. A node on Windows might have the capability of offering Internet Explorer as a browser option, whereas this wouldn’t be possible on Linux or Mac.



Monday, December 7, 2020

Latest Top 20 Selenium Interview Question and Answers SET 1

1. What are the types of waits in selenium?
There are two type of waits. 
1. Dynamic Waits
2. Static Wait

1. Dynamic Waits:
a. Implicit Wait - It is dynamic wait and it is used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script.
Implicitly wait is applied globally, which means it is always available for all the web elements throughout the driver instance.
Syntax: driver.manage().timeouts().implicitlyWait(4,TimeUnit.SECONDS);

b. Explicit Wait - Explicit waits are used to halt the execution until the expected condition is met. Expected Conditions are as below.

presenceOfAllElementsLocatedBy()
presenceOfElementLocated()
textToBePresentInElement()
textToBePresentInElementLocated()
textToBePresentInElementValue()
visibilityOfAllElements()
visibilityOfAllElementsLocatedBy()
visibilityOfElementLocated()

Syntax: 
WebDriverWait wait= new WebDriverWait(driver, 5);
WebElement ele=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“xpath")));

c. Fluent Wait - The Fluent Wait command defines the maximum amount of time for Selenium WebDriver to wait for a certain condition to appear. It also defines the frequency with which WebDriver will check if the condition appears before throwing the “ElementNotVisibleException”.

Syntax:
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(40))
.pollingEvery(Duration.ofSeconds(8))
.ignoring(Exception.class);


WebElement ele = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.xpath(“xpath"));
}
});

2. Static Wait:
a. Thread.sleep() - This method will stop the execution of the script for the specified duration of time, irrespective of whether the element is found or not on the web page.




3. Explain framework used In project.

UI Framework: 

Type of framework: Modular Hybrid Framework with Page Object model design



Powerful Features in the Framework:
1. It has better logging and error handling mechanism
2. We can run the tests parallelly as well as sequentially
3. It can be integrated with Jenkins
4. It supports data through excel files
5. It supports 3rd party tools like Auto IT, Skuli etc.
6. We can also integrate with BrowserStack, Dockerised GRID
8. It also capture screenshots as well as video recording (using solenoid)


Languages and Design Patterns Used: Java, Singleton & Builder Pattern

Tools Used: JAVA, Selenium WebDriver, Maven, Grid, Jenkins, Git, Testng, Apache POI libraries, Allure Report, Auto IT, Skuli, Log4j


Components In the framework:
1. Pom.xml - For storing dependencies, plugins
2. Data provider - for retrieving data through excel and passing them to test methods
3. Base Page - To initialize WebDriver and remote driver
4. Components - This will have actions for each page
5. Locators - This will have locators for each Page
6. Properties file - To get URL's and other hard coded values
7. Excel file- To store all the data
8. Utils - This will have Utility to get Properties files, Excel Reader, Any Database connection, Logger, JavaScript Helpers etc.
9. Listeners - This will be used for TestNG as well as Webdriver Listeners
10. BaseTest - This will be used to store TestNG Annotations like @Before Class, @Before Method, @After Class, @After Method
11. Test File - This will have all the Test Methods
12. Testng.xml - This will have all the classes and methods
13. Allure Report- This is used for reporting purpose
14. Validators- To validate the elements on the page.


How the framework works
1. Whenever I commit a code in the Git hub, the web hook (it is one of the ways web applications can communicate with each other) makes a call to Jenkins
2. In the Jenkins, I had setup the complete pipeline (from build, deploy, Run feature Automation, Run Regression, Run Pre-prod Smoke, Deploy to Pre-prod)
3. When it comes to Automation phase, the Jenkins looks for Maven arguments and finds the POM.xml file, and I have configured testNG.xml in POM.xml
4. The testng.xml file will have Test classes and methods
5. The test methods will have Data providers, groups, and other annotation
6. DataProvider get data from excel file by using Excel Reader utility and pass that to test method
7. The test method will also have page actions and locators
8. The test method will finally do validations to assert elements on the page
9. Once the test gets executed the results will be generated through Allure report.
11. To make debugging quicker, Logging had been implemented and it gets logged over there.


4: Handle windows authentication popup without using any third party tool .

Using Autoit (Third Party Tool)
Download and in Autoit editor write script through below command
ControlFocus()
ControlSet()
ControlClick()
Save file and Compile Script with your version and after that you get .exe file.
Java code for executing .exe file
Runtime.getRuntime().exec(\\Path)
It throws checked exception IOexception.


Another way of doing this is using Robot class
Robot Class is available under java.awt.package.
Methods in Robot Class can be effectively used to do the interaction with pop-ups in Web Applications. Selenium does not provide support to handle browser pop-ups or the native operating system pop-ups. To handle this kind of pop-up, we need help of Robot Class. This is also used while we need to handle file upload and download activity using selenium Webdriver.
Some of the popular methods under Robot Class are:
.keyPress();
.mousePress();
.mouseMove();
.keyRelease();
.mouseRelease();

First of all create the object of the Robot Class as following
Robot robot=new Robot(); 
1. .keyPress() 
robot.keyPress(KeyEvent.VK_ESC); This will press Escape key on keyboard. 

2. .keyRelease() 
robot.keyRelease(KeyEvent.VK_CAPS_LOCK);  This will release the CAPS_LOCK key. 

3. .mousePress()
 robot.mousePress(InputEvent.BUTTON1_MASK); This will press Left mouse button. 

4. .mouseRelease() 
robot.mouseRelease(InputEvent.BUTTON1_MASK); This will release Left mouse button. 

5. .mouseMove() 
robot.mouseMove(coordinates.getX(), coordinates.getY()); This will move the mouse pointer to X and Y co-ordinates.


5. Which is better to use in Selenium automation? Sleep or Wait?
Both Thread.sleep and Object.wait make the current thread wait for a specified amount of time. 
This is useful when the current thread needs to wait for other thread before it can proceed. 
For example, web element might not be clickable or enabled, or in the expected state. Instead of using Thread.sleep, a better approach is to check for right state. Selenium provides a set of common ExpectedConditions that can be leveraged on top of webdriverwait. 
Unlike Thread.sleep (where locks are not released), in Object.wait locks are released as the thread goes to sleep. This approach helps make the test more stable and reliable.


6. Why using JavascriptExecutor in WebDriver can be dangerous.
I have occasionally seen people recommending running javascript using the JavascriptExecutor implementation. For example, I was working on a project where a test would pass on the developer's computer but would fail on the functional test machine. The line of code which failed was:

driver.findElement(By.cssSelector(".save")).click();

So the developer changed it to:

((JavascriptExecutor)driver).executeScript("$('.save').click();");

It seemed harmless and it worked.

The GUESS was that WebDriver found the button because it was always in the DOM with style="display: none;" but the click failed because it wasn't waiting for the button to become visible.

The idea was that the test was REALLY:

- open the dialog
- wait for the button to become visible
- click the button

If we used javascript we didn't have to wait for the button to be visible. So javascript seemed faster but was still testing the right thing.

No problem, right? Wrong. It turned out that the save button was on a javascript dialog which did not scroll. If you scrolled up and down the page the dialog remained still; the dialog ALWAYS stay exactly 120px from the top of display. When all the tests ran it created data which made the dialog 830px high. This placed the bottom of the dialog at 950px. The developers machine was 1600x1200 display. It made the dialog fully visible on the display. The functional test machine was set to 800x600. This forced the bottom of the dialog off the bottom of the display. Even when you made the browser full screen you could not see the save button.

So on the developers machine WebDriver would see and click the save button because it was visible. On the functional test machine (set to 800x600 because that was the minimum requirement) it was not visible and you could not scroll it into view because the dialog did not scroll.

When they switched to the javascript code it clicked the button regardless of whether the button was visible or not. If we shipped this application, any customer who was using a computer with 800x600 display (a significant number of people based on analytics) would be unable to click the save button even though the functional test passed.

The moral of the story is, if the javascript solution doesn't test EXACTLY the same requirement as the WebDriver solution, you could be making your tests report a false positive.



7. Why declaring the driver object as static in base class is not a good practice in selenium? 
If you perform sequential test case execution then it will work perfectly. 
But when you do the same thing for parallel execution it will stop the execution because your first test case will use your driver object but at the same another testcase running parallelly they will also grab the driver object so it may through null pointer exception or may get some weird result and your script will fail.
But if you want to declare driver object as static you can do. By defining local variable of driver object in each class or you can use ThreadLocal class to make driver thread safe.


8. Where did we use abstract class in selenium framework
Basic Example---

Lets say we have a Utility class. This class I define as abstract and declared a reusable method

public abstract class Utilities {
public abstract String clearElement(); //method to clear data in a field on webpage
 }
Now why I have added clearElement as abstract because I can have different implementation for it.
==>If want to clear a data in a field then we have driver.clear();
==>But this sometime does not work.
==>So I can implement with Actions class or Robot class By Pressing CTRL + A and Press DELETE key
==> There are some more scenarios we can do with Actions and Robot class.

So, I created two subclasses for above Utility class in which we will Override and implement abstract clearElement() method.

EX-
public class UtilsWithActionsClass extends Utilities {

@Override
public String clearElement() {
String s="Implemented with ActionsClass";
return s;
    }
}
public class UtilsWithRobotClass extends Utilities {

@Override
public String clearElement() {
String s="Implemented with RobotClass";
return s;
    }
}

So If clear data is not working with Actions class then I can call clearElement() from UtilsWithRobotClass with Object reference.
==>So here we are able to use same method name "clearElement()" and provide different implementation for it.
==>We are not required to create two separate methods with different names like "clearElement1()" and "clearElement2()"
==> So basic idea is to have all such reusable methods(for which u think u may need different implementation in future)
in abstract class so that subclasses can implement them as per their choice/requirement




9 Can you tell me Oops concepts and relate it with your Framework?
We have Polymorphism, Inheritance, Encapsulation and Abstraction in Oops. So, we will start with 1) DATA ABSTRACTION

Data Abstraction means to handle complexity by hiding unnecessary details from the user. In java, abstraction is achieved by interfaces and abstract classes. We can achieve 100% abstraction using interfaces.

In Selenium, WebDriver itself acts as an interface. Consider the below statement:

WebDriver driver = new ChromeDriver();

We initialize the Chrome 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 and ChromeDriver is a class.

We can apply Data Abstraction in a Selenium framework by using the Page Object Model design pattern. We define all our locators and their methods in the page class. We can use these locators in our tests but we cannot see the implementation of their underlying methods. So we only show the locators in the tests

but hide the implementation. This is a simple example of how we can use Data Abstraction in our Automation Framework.

2) ENCAPSULATION
Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. Encapsulation can be achieved by: Declaring all the variables in the class as private and writing public methods in the class to set and get the values of variables. All the classes in an Automation Framework are an example of Encapsulation. In Page Object Model classes, we declare the data members using @FindBy and initialization of data members will be done using Constructor to utilize those in methods.

3) INHERITANCE
Inheritance is the mechanism in java by which one class is allowed to inherit the features (fields and methods) of another class.

We can apply Inheritance in our Automation Framework by creating a Base Class to initialize the WebDriver interface, browsers, waits, reports, logging, etc. and then we can extend this Base Class and its methods in other classes like Tests or Utilities. This is a simple example of how we can apply Inheritance in our framework.

4) POLYMORPHISM
Polymorphism allows us to perform a single action in different ways. In Java polymorphism can be achieved by two ways:

– Method Overloading: When there are multiple methods with same name but different parameters then these methods are said to be overloaded. Methods can be overloaded by change in number of arguments or/and change in type of arguments.

In Selenium Automation, Implicit wait is an example of Method Overloading. In Implicit wait we use different time stamps such as SECONDS, MINUTES, HOURS etc.

– Method Overriding: It occurs when a derived class has a definition for one of the member functions of the base class. That base function is said to be overridden.

In Selenium Automation, Method Overriding can be achieved by overriding any WebDriver method. For example, we can override the findElement method

In assertion we have used overload because in assertion we used to like asset.true(actual, expected) and second time we can use same assert.true(actual, expected, message).




10 How can you use interface and how it is different from Abstract class?
Abstract class may have Abstract, concrete methods and it has final and non final data members, and there is not any compulsion in adding abstract method in abstract class. But in Interface, we do have only abstract methods and only final data members and we don’t need to write abstract keyword in Interface this is by default public and abstract.



11. What do you mean by Static keyword in Java?
Static means it is at class level not at instance level, we have static method, static variable & static inner class. When we have any variable as static so it will remain same for all the instance of our classes, and static/Private/Final methods can’t be over-ridden like if we have initialized any method as Static so we cannot override it in any child class.




12. How to call static method and variable in java? 
We can call static variables using class name or direct calls(Only method name)



13. Can I access Static method by using object reference?
Yes we can, but we got one warning that you need to access it via Direct or By class name.



14. How to call non-static method and variable in java?
For calling non static method we need to create object firs


15. Can we overload & override main method?
We can overload main() method but can not override. because main method is static and static method can not be override it breaks the overriding rule . if static method overrides it called method hiding.


16.What do you mean by wrapper class and how will you do data conversion?
Wrapper class in java are used for data conversion. In data conversion if user wants to convert Int to string, String to int, Boolean, double then we use Wrapper class.
  • Integer.parseInt(); - To convert string to Integer
  • Double.parseDouble(); - To convert string to Double
  • Boolean.parse Boolean(); - To convert string to Boolean
  • String.valueof(); - To convert Integer to String.


17. Can you convert string a =”110a” in integer?
No we will get NumberFormatException while converting the above string. 



18. What do you mean by Call by Value & Call by Reference in Java?

Call by value means suppose we have created one sum method with input parameter int a, int b. So while calling the creating the object and running we provide values that is know as call by value.



19. What do you mean by Exceptions in Java?
Exception is like any interruption in our normal flow. Like if we are running anything and we got issues in our script this is we called exception, we have 2 types of exception Run Time & Compile Time. (checked & Unchecked exceptions)
a. Checked Exceptions : The exception which are checked by compiler for smooth execution of program are called checked exception. 
Eg. SQLException
IOException
ClassNotFoundException
InvocationTargetException

b. Unchecked Exceptions: The exception which are not checked by compiler are called unchecked exception.
Eg. NullPointerException
ArrayIndexOutOfBoundsException
ArithmeticException
IllegalArgumentException 
NumberFormatException


20. Can you tell me about difference between Throw and Throws keyword?
Throw is a keyword used inside a body of function. And Throws used while initializing any method. By using Throw we can throw only one exception while for Throws we can declare multiple exceptions which might occur in that particular function. Throws keyword followed by instance name and Throw keyword is followed by class name of that exception.

Sunday, November 1, 2020

Refer this SQL table for all SQL interview questions

 create table Employee

(EMPLOYEE_ID int, LAST_NAME varchar(20), FIRST_NAME varchar(30), MIDDLE_NAME varchar(20),JOB_ID int, MANAGER_ID int, HIREDATE date, SALARY int, COMM int, DEPARTMENT_ID int);

 

insert into Employee(EMPLOYEE_ID, LAST_NAME, FIRST_NAME, MIDDLE_NAME, JOB_ID, MANAGER_ID, HIREDATE,SALARY,COMM,  DEPARTMENT_ID )

values(7369,'SMITH','JOHN','Q',667,7902,'17-DEC-84',800,NULL,20);

 

insert into Employee(EMPLOYEE_ID, LAST_NAME, FIRST_NAME, MIDDLE_NAME, JOB_ID, MANAGER_ID, HIREDATE,SALARY,COMM,  DEPARTMENT_ID )

values(7499,'ALLEN', 'KEVIN', 'J', 670, 7698, '20-FEB-85', 1600, 300, 30);

 

insert into Employee(EMPLOYEE_ID, LAST_NAME, FIRST_NAME, MIDDLE_NAME, JOB_ID, MANAGER_ID, HIREDATE,SALARY,COMM,  DEPARTMENT_ID )

values(7505,'DOYLE', 'JEAN', 'K', 671, 7839, '04-APR-85', 2850, NULL, 30);

 

insert into Employee(EMPLOYEE_ID, LAST_NAME, FIRST_NAME, MIDDLE_NAME, JOB_ID, MANAGER_ID, HIREDATE,SALARY,COMM,  DEPARTMENT_ID )

values(7506,'DENNIS', 'LYNN', 'S', 671, 7839, '15-MAY-85', 2750, NULL, 30);

 

insert into Employee(EMPLOYEE_ID, LAST_NAME, FIRST_NAME, MIDDLE_NAME, JOB_ID, MANAGER_ID, HIREDATE,SALARY,COMM,  DEPARTMENT_ID )

values(7507,'BAKER', 'LESLIE', 'D', 671, 7839, '10-JUN-85', 2200, NULL, 40);

 

insert into Employee(EMPLOYEE_ID, LAST_NAME, FIRST_NAME, MIDDLE_NAME, JOB_ID, MANAGER_ID, HIREDATE,SALARY,COMM,  DEPARTMENT_ID )

values(7521,'WARK', 'CYNTHIA', 'D', 670, 7698, '22-FEB-85', 1250, 500, 30);


EMPLOYEE

EMPLOYEE_ID

LAST_NAME

FIRST_NAME

MIDDLE_NAME

JOB_ID

MANAGER_ID

HIREDATE

SALARY

COMM

DEPARTMENT_ID

7369

SMITH

JOHN

Q

667

7902

17-DEC-84

800

NULL

20

7499

ALLEN

KEVIN

J

670

7698

20-FEB-85

1600

300

30

7505

DOYLE

JEAN

K

671

7839

04-APR-85

2850

NULL

30

7506

DENNIS

LYNN

S

671

7839

15-MAY-85

2750

NULL

30

7507

BAKER

LESLIE

D

671

7839

10-JUN-85

2200

NULL

40

7521

WARK

CYNTHIA

D

670

7698

22-FEB-85

1250

500

30

   

How to install Java on EC2

***************************************** How to install Java on EC2 ***************************************** To be continued, In this post...

All Time Popular Post