August 2019 - All About Testing August 2019

What is the recipe for successful achievement?

To my mind there are just four essential ingredients: Choose a career you love, give it the best there is in you, seize your opportunities, and be a member of the team.

“All our dreams can come true, if we have the courage to pursue them.”

“I’m a great believer in luck, and I find the harder I work, the more I have of it.”

Success unshared is failure.

To make our way, we must have firm resolve, persistence, tenacity. We must gear ourselves to work hard all the way. We can never let up.

"Everyone you will ever meet knows something you don't."

he fact that I can plant a seed and it becomes a flower, share a bit of knowledge and it becomes another's, smile at someone and receive a smile in return, are to me continual spiritual exercises.

The secret of success is to do the common things uncommonly well.

Good things come to people who wait, but better things come to those who go out and get them.

Friday, 23 August 2019

Selenium Interview Questions

1.  What are the significant changes in upgrades in various Selenium versions?
Selenium v1 included only three suite of tools: Selenium IDE, Selenium RC, and Selenium Grid. Note that there was no WebDriver in Selenium v1. Selenium WebDriver was introduced in Selenium v2. With the onset of WebDriver, Selenium RC got deprecated and is not in use since. Older versions of RC is available in the market though, but support for RC is not available. Currently, Selenium v3 is in use, and it comprises of IDE, WebDriver and Grid.
IDE is used for recording and playback of tests, WebDriver is used for testing dynamic web applications via a programming interface and Grid is used for deploying tests in remote host machines.

2.  Explain the different exceptions in Selenium WebDriver.
Exceptions in Selenium are similar to exceptions in other programming languages. The most common exceptions in Selenium are:
TimeoutException: This exception is thrown when a command performing an operation does not complete in the stipulated time
NoSuchElementException: This exception is thrown when an element with given attributes is not found on the web page
ElementNotVisibleException: This exception is thrown when the element is present in DOM (Document Object Model), but not visible on the web page
StaleElementException: This exception is thrown when the element is either deleted or no longer attached to the DOM

3. What is exception test in Selenium?
An exception test is an exception that you expect will be thrown inside a test class. If you have written a test case in such way that it should throw an exception, then you can use the @Test annotation and specify which exception you will be expecting by mentioning it in the parameters. Take a look at the example below: @Test(expectedException = NoSuchElementException.class)
Do note the syntax, where the exception is suffixed with .class

4. Why and how will you use an Excel Sheet in your project?
The reason we use Excel sheets is because it can be used as a data source for tests. An excel sheet can also be used to store the data set while performing DataDriven Testing. These are the two main reasons for using Excel sheets.
When you use the excel sheet as a data source, you can store the following:
Application URL for all environments: You can specify the URL of the environment in which you want to do the testing like: development environment or testing environment or QA environment or staging environment or production/ pre-production environment.
User name and password credentials of different environments: You can store the access credentials of the different applications/ environments in the excel sheet. You can store them in an encoded format and whenever you want to use them, you can decode them instead of leaving it plain and unprotected.
Test cases to be executed: You can list down the entire set of test cases in a column and in the next column, you can specify either Yes or No which indicates if you want that particular test case to be executed or ignored.
When you use the excel sheet for DataDriven Test, you can store the data for different iterations to be performed in the tests. For example, while testing a web page, the different sets of input data that needs to be passed to the test box can be stored in the excel sheet

5. What is the use of JavaScriptExecutor?
JavaScriptExecutor is an interface which provides a mechanism to execute Javascript through the Selenium WebDriver. It provides “executescript” and “executeAsyncScript” methods, to run JavaScript in the context of the currently selected frame or window. An example of that is:
1 JavascriptExecutor js = (JavascriptExecutor) driver;
2 js.executeScript(Script,Arguments);

6. How to scroll down a page using JavaScript in Selenium?
We can scroll down a page by using window.scrollBy() function. Example:
1 ((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)");

7. How to scroll down to a particular element?
To scroll down to a particular element on a web page, we can use the function scrollIntoView(). Example:
1 ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element);

8. How to handle keyboard and mouse actions using Selenium?
We can handle special keyboard and mouse events by using Advanced User Interactions API. The Advanced User Interactions API contains the Actions and the Action Classes that are needed for executing these events. Most commonly used keyboard and mouse events provided by the Actions class are in the table below:
Selenium functions and their explanation
Method               Description
clickAndHold()   Clicks (without releasing) the current mouse location.
dragAndDrop() Performs click-and-hold at the location of the source element, moves.
source, target() Moves to the location of the target element, then releases the mouse

9. How to send ALT/SHIFT/CONTROL key in Selenium WebDriver?
When we generally use ALT/SHIFT/CONTROL keys, we hold onto those keys and click other buttons to achieve the special functionality. So it is not enough just to specify keys.ALT or keys.SHIFT or keys.CONTROL functions.
For the purpose of holding onto these keys while subsequent keys are pressed, we need to define two more methods: keyDown(modifier_key) and keyUp(modifier_key)

Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)
Purpose: Performs a modifier key press and does not release the modifier key. Subsequent interactions may assume it’s kept pressed.
Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)
Purpose: Performs a key release.
Hence with a combination of these two methods, we can capture the special function of a particular key.
public static void main(String[] args)
{
String baseUrl = “https://www.facebook.com”;
WebDriver driver = new FirefoxDriver();
driver.get("baseUrl");
WebElement txtUserName = driver.findElement(By.id(“Email”);
Actions builder = new Actions(driver);
Action seriesOfActions = builder
.moveToElement(txtUerName)
.click()
.keyDown(txtUserName, Keys.SHIFT)
.sendKeys(txtUserName, “hello”)
.keyUp(txtUserName, Keys.SHIFT)
.doubleClick(txtUserName);
.contextClick();
.build();
seriesOfActions.perform();
}

10. How to take screenshots in Selenium WebDriver?
You can take a screenshot by using the TakeScreenshot function. By using getScreenshotAs() method you can save that screenshot. Example:
File scrFile = ((TakeScreenshot)driver).getScreenshotAs(outputType.FILE);

# How to set the size of the browser window using Selenium?
To maximize the size of browser window, you can use the following piece of code:
driver.manage().window().maximize(); – To maximize the window
To resize the current window to a particular dimension, you can use the setSize() method. Check out the below piece of code:
System.out.println(driver.manage().window().getSize());
Dimension d = new Dimension(420,600);
driver.manage().window().setSize(d);
To set the window to a particular size, use window.resizeTo() method. Check the below piece of code:
((JavascriptExecutor)driver).executeScript("window.resizeTo(1024, 768);");

11. Explain how you will login into any site if it is showing any authentication popup for username and password?
Since there will be popup for logging in, we need to use the explicit command and verify if the alert is actually present. Only if the alert is present, we need to pass the username and password credentials. The sample code for using the explicit wait command and verifying the alert is below:
WebDriverWait wait = new WebDriverWait(driver, 10);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.authenticateUsing(new UserAndPassword(**username**, **password**));

12. Explain how can you find broken links in a page using Selenium WebDriver?
This is a trick question which the interviewer will present to you. He can provide a situation where in there are 20 links in a web page, and we have to verify which of those 20 links are working and how many are not working(broken).
Since you need to verify the working of every link, the workaround is that you need to send http requests to all of the links on the web page and analyze the response. Whenever you use driver.get() method to navigate to a URL, it will respond with a status of 200 – OK. 200 – OK denotes that the link is working and it has been obtained. If any other status is obtained, then it is an indication that the link is broken.
But how will you do that?
First, we have to use the anchor tags <a> to determine the different hyperlinks on the web page. For each <a> tag, we can use the attribute ‘href’ value to obtain the hyperlinks and then analyze the response received for each hyperlink when used in driver.get() method.

13. What is parameterization in TestNG? How to pass parameters using testng.xml?
Parameterization is the technique of defining values in testng.xml file and sending them as parameters to the test class. This technique is especially useful when we need to pass multiple login credentials of various test environments. Take a look at the code below, in which “myName” is annotated as a parameter.
public class ParameterizedTest1{
@Test
@Parameters("myName")
public void parameterTest(String myName) {
System.out.println("Parameterized value is : " + myName);
}
}
To pass parameters using testng.xml file, we need to use ‘parameters’ tag. Look at the below code for example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name=”CustomSuite">
  <test name=”CustomTest”>
   <parameter name="myName" value=”John"/>
    <classes>
     <class name="ParameterizedTest1" />
    </classes>
  </test>
</suite>

 14. Explain what is Group Test in TestNG?
In TestNG, methods can be categorized into groups. When a particular group is being executed, all the methods in that group will be executed.  We can execute a group by parameterizing it’s name in group attribute of @Test annotation. Example: @Test(groups={“xxx”})
@Test(groups={“Car”})
public void drive(){
system.out.println(“Driving the vehicle”);
}
@Test(groups={“Car”})
public void changeGear() {
system.out.println("Change Gears”);
}
@Test(groups={“Car”})
public void accelerate(){
system.out.println(“Accelerating”);
}

15. How does TestNG allow you to state dependencies? Explain it with an example.
Dependency is a feature in TestNG that allows a test method to depend on a single or a group of test methods. Method dependency only works if the “depend-on-method” is part of the same class or any of the inherited base classes (i.e. while extending a class). Syntax:
@Test(dependsOnMethods = { “initEnvironmentTest” })
@Test(groups={“Car”})
public void drive(){
system.out.println(“Driving the vehicle”);
}
@Test(dependsOnMethods={“drive”},groups={cars})
public void changeGear() {
system.out.println("Change Gears”);
}
@Test(dependsOnMethods={“changeGear”},groups={“Car”})
public void accelerate(){
system.out.println(“Accelerating”);
}

16. Explain what does @Test(invocationCount=?) and @Test(threadPoolSize=?) indicate.
@Test(invocationCount=?) is a parameter that indicates the number of times this method should be invoked.
@Test(threadPoolSize=?) is used for executing suites in parallel. Each suite can be run in a separate thread.
To specify how many times @Test method should be invoked from different threads, you can use the attribute threadPoolSize along with invocationCount. Example:
@Test(threadPoolSize = 3, invocationCount = 10)
public void testServer() {
}

Jenkin Interview Questions for Testers

Q1. What is Jenkins?
My suggestion is to start this answer by giving a definition of Jenkins.
Jenkins is an open-source automation tool written in Java with plugins built for Continuous Integration purpose. Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. It also allows you to continuously deliver your software by integrating with a large number of testing and deployment technologies.
Once you have defined Jenkins give an example, you can refer the below-mentioned use case:
First, a developer commits the code to the source code repository. Meanwhile, the Jenkins server checks the repository at regular intervals for changes.
Soon after a commit occurs, the Jenkins server detects the changes that have occurred in the source code repository. Jenkins will pull those changes and will start preparing a new build.
If the build fails, then the concerned team will be notified.
If the build is successful, then Jenkins deploys the built-in the test server.
After testing, Jenkins generates feedback and then notifies the developers about the build and test results.
It will continue to check the source code repository for changes made in the source code and the whole process keeps on repeating.
Jenkins Architecture - DevOps Interview Questions Jenkins - Edureka
The interviewer now knows what is Jenkins but why we use it, there are many other CI tools as well, so why Jenkins? the next question in this Jenkins interview questions will deal with that answer.

Q2. What are the benefits of using Jenkins?
I will suggest you include the following benefits of Jenkins if you can recall any other benefit apart from the below-mentioned points you can include that as well.
At the integration stage, build failures are cached.
For each change in the source code, an automatic build report notification is generated.
To notify developers about build report success or failure, it is integrated with LDAP mail server.
Achieves continuous integration agile development and test driven development.
With simple steps, the maven release project is automated.
Easy tracking of bugs at an early stage in a development environment than production.
Interviewer: Okay Jenkins looks like a really cool tool, but what are the requirements for using Jenkins?

Q3. What are the pre-requisites for using Jenkins?
Answer to this is pretty straightforward To use Jenkins you require:
A source code repository which is accessible, for instance, a Git repository.
A working build script, e.g., a Maven script, checked into the repository.
Remember, you have mentioned Plugins in your previous answer, so the next question in this Jenkins interview questions blog will be regarding Plugins.

Q4. Mention some of the useful plugins in Jenkins?
Below I have mentioned some important Plugins:
Course Curriculum
DevOps Certification Training
Instructor-led SessionsReal-life Case StudiesAssignmentsLifetime Access
Maven 2 project
Git
Amazon EC2
HTML publisher
Copy artifact
Join
Green Balls
Jenkins Plugins - Jenkins Interview Questions - Edureka
These Plugins I feel are the most useful plugins, if you want to include any other Plugin that is not mentioned above, you can add that as well, but make sure you first mention the above-stated plugins and then add your own.

Q5. Mention what are the commands you can use to start Jenkins manually?
For this answer I will suggest you go with the below mentioned flow:
To start Jenkins manually open the Console/Command line, then go to your Jenkins installation directory. Over there you can use the below commands:
To start Jenkins: jenkins.exe start
To stop Jenkins: jenkins.exe stop
To restart Jenkins: jenkins.exe restart

Q6. Explain how you can set up Jenkins job?
My approach to this answer will be to first mention how to create a Jenkins job.
Go to Jenkins top page, select “New Job”, then choose “Build a free-style software project”.
Now you can tell the elements of this freestyle job:
Optional SCM, such as CVS or Subversion where your source code resides.
Optional triggers to control when Jenkins will perform builds.
Some sort of build script that performs the build (ant, maven, shell script, batch file, etc.) where the real work happens.
Optional steps to collect information out of the build, such as archiving the artifacts and/or recording Javadoc and test results.
Optional steps to notify other people/systems with the build result, such as sending e-mails, IMs, updating issue tracker, etc..

Q7. Explain how to create a backup and copy files in Jenkins?
Answer to this question is really direct.
To create a backup all you need to do is to periodically back up your JENKINS_HOME directory. This contains all of your build jobs configurations, your slave node configurations, and your build history. To create a back-up of your Jenkins setup, just copy this directory. You can also copy a job directory to clone or replicate a job or rename the directory.
Learn Jenkins With DevOps Now

Q8. How will you secure Jenkins?
The way I secure Jenkins is mentioned below if you have any other way to do it than mention that:
Ensure global security is on.
Ensure that Jenkins is integrated with my company’s user directory with the appropriate plugin.
Ensure that the matrix/Project matrix is enabled to fine-tune access.
Automate the process of setting rights/privileges in Jenkins with custom version controlled script.
Limit physical access to Jenkins data/folders.
Periodically run security audits on same.
I hope you have enjoyed the above set of Jenkins interview questions, the next set of questions will be more challenging, so be prepared.
Course Curriculum
DevOps Certification Training

Q9 Explain how you can deploy a custom build of a core plugin?
Below are the steps to deploy a custom build of a core plugin:
Stop Jenkins.
Copy the custom HPI to $Jenkins_Home/plugins.
Delete the previously expanded plugin directory.
Make an empty file called <plugin>.hpi.pinned.
Start Jenkins.

Q10. What is the relation between Hudson and Jenkins?
You can just say Hudson was the earlier name and version of current Jenkins. After some issue, the project name was changed from Hudson to Jenkins.

Q11. What you do when you see a broken build for your project in Jenkins?
There can be multiple answers to this question I will approach this task in the following way:
I will open the console output for the broken build and try to see if any file changes were missed. If I am unable to find the issue that way, then I will clean and update my local workspace to replicate the problem on my local and try to solve it.
If you do it in a different way then just mention that in your answer.

Q12. Explain how you can move or copy Jenkins from one server to another?
I will approach this task by copying the jobs directory from the old server to the new one. There are multiple ways to do that, I have mentioned it below:
You can:
Move a job from one installation of Jenkins to another by simply copying the corresponding job directory.
Make a copy of an existing job by making a clone of a job directory by a different name.
Rename an existing job by renaming a directory. Note that if you change a job name you will need to change any other job that tries to call the renamed job.

Q13. What are the various ways in which build can be scheduled in Jenkins?
You can schedule a build in Jenkins in the following ways:
By source code management commits
After completion of other builds
Can be scheduled to run at a specified time ( crons )
Manual Build Requests

Q14. What is the difference between Maven, Ant, and Jenkins?
Maven and Ant are Build Technologies whereas Jenkins is a continuous integration tool.

Q15. Which SCM tools Jenkins supports?
Below are Source code management tools supported by Jenkins:
AccuRev
CVS,
Subversion,
Git,
Mercurial,
Perforce,
Clearcase
RTC
Now, the next set of Jenkins interview questions will test your experience with Jenkins.

Q16. What are the two components Jenkins is mainly integrated with?
According to me, Jenkins is mainly integrated with the following:
Version Control system like GIT, SVN.
Build tools like Apache Maven.