You are on page 1of 24

Interview Q & A:

Building an automation framework in Selenium with Java:

• Setup Your Development Environment:


• Install Java Development Kit (JDK)
• Install an Integrated Development Environment (IDE) like Eclipse or IntelliJ IDEA
• Download Selenium WebDriver Java bindings
• Download required WebDriver binaries (e.g., chromedriver for Chrome, geckodriver for
Firefox)

• Create a New Java Project:


• Open your IDE and create a new Java project.

• Add Selenium Dependencies:


• Add Selenium WebDriver dependencies to your project. If you're using Maven, include
Selenium WebDriver dependency in your pom.xml file. If you're not using Maven, manually
add Selenium jar files to your project build path.

• Design Your Framework Structure:


• Decide on a framework structure. Common structures include Page Object Model (POM),
Page Factory, or a hybrid approach.
• Create packages for organizing your test code, utilities, configurations, and resources.

• Write Test Cases:


• Write test cases using JUnit or TestNG frameworks/ Cucumber BDD procees.
• Implement assertions to validate the expected behaviour of the application under test.

• Implement Page Objects:


• Create page classes to represent web pages or components of your application.
• Each page class should contain methods to interact with the elements on that page.
• Follow the principles of the Page Object Model (POM).

• Implement Test Base:


• Create a test base class to initialize WebDriver, manage test setup, and teardown activities.
• Implement methods to read configuration parameters, set up logging, handle browser
initialization, etc.

• Execute Tests:
• Execute your test cases either individually or collectively.
• Monitor test execution results and debug failures if any.

• Implement Data-Driven Testing:


• Use data providers to parameterize your test cases and perform data-driven testing.
• Implement Reporting (Optional but recommended):
• Integrate a reporting tool like ExtentReports or Allure to generate detailed test reports.
• Customize reports to include test execution summaries, screenshots, and other relevant
information.

• Implement Logging (Optional but recommended):


• Integrate logging frameworks like Log4j or SLF4J to capture runtime information and debug
test failures efficiently.

• Continuous Integration:
• Integrate your automation framework with Continuous Integration (CI) tools like Jenkins,
Bamboo, or Azure DevOps for automated test execution.

• Maintain and Enhance:


• Regularly maintain and enhance your framework as per the evolving requirements of your
project.
• Refactor code, optimize test scripts, and keep up with best practices in test automation.

CUCUMBER:
Setup Your Project:

• Follow the steps mentioned earlier to set up your Java project with Selenium WebDriver.
• Add Cucumber dependencies to your project. You'll need cucumber-java, cucumber-core,
cucumber-junit, and cucumber-jvm dependencies.

Define Feature Files:

• Write feature files using Gherkin syntax. Feature files describe the behavior of your
application in a human-readable format.
• Define scenarios and steps that represent different test cases.

Implement Step Definitions:

• Create step definition classes to map each step in your feature files to Java code.
• Implement the logic to interact with your application using Selenium WebDriver methods.
• Utilize regular expressions to match step definitions with corresponding steps in feature files.

Configure Cucumber Options:

• Configure Cucumber options in a test runner class. You can specify the location of your
feature files, glue code (step definitions), and other options.

Run Your Tests:

• Execute your Cucumber tests using a test runner class.


• Monitor test execution and analyze results.
Parameterization and Data-Driven Testing:

• Utilize Cucumber's scenario outline feature for parameterization of test scenarios.


• Implement data tables in feature files to perform data-driven testing.

Reporting and Logging:

• Integrate reporting plugins like Cucumber Extent Reporter or Cucumber HTML Reporter to
generate detailed test reports.
• Implement logging within step definitions to capture runtime information.

Continuous Integration:

• Integrate your Cucumber tests with a CI/CD pipeline for automated execution.
• Configure your CI server to run Cucumber tests as part of the build process.

Collaboration and Communication:

• Use Cucumber feature files as a means of communication between stakeholders, testers, and
developers.
• Ensure that feature files are written in a language that all stakeholders understand.

Best Practices and Refactoring:

• Follow best practices for writing feature files and step definitions.
• Regularly refactor and optimize your step definitions for better maintainability and
readability.

Utilities for testing:


In Selenium with Java, Utilities are classes or libraries that work alongside Selenium WebDriver to
make automating tests easier. They are additional classes or libraries that assist in various tasks
related to test automation, such as managing test data, handling browser interactions, or generating
reports. These utilities are used to enhance the efficiency, maintainability, and reliability of
automated tests.

WebDriverManager: Utility for managing WebDriver binaries for different browsers. It automatically
downloads and configures the required WebDriver executables, eliminating the need for manual
management.

Test Data Management Utilities: Libraries or methods for reading test data from external sources
such as Excel files, CSV files, or databases. These utilities help in parameterizing tests and separating
test data from test logic.

Wait Utilities: Classes and methods for implementing explicit and implicit waits in tests. They allow
waiting for certain conditions to be met before proceeding with test execution, improving test
stability and reliability.

Logging Utilities: Frameworks for logging runtime information and debugging test failures. These
utilities capture log messages, exceptions, and other relevant information during test execution for
analysis and troubleshooting.
Reporting Utilities: Libraries or plugins for generating test reports with detailed information about
test executions, including test case status, screenshots, logs, and performance metrics. These reports
help in test analysis and result interpretation.

Page Object Model (POM) Implementations: Frameworks or utilities for implementing the Page
Object Model (POM) pattern, which helps in creating reusable and maintainable page objects for
organizing and managing web elements in test scripts.

TestNG or JUnit Integration Utilities: Integrations or extensions for TestNG or JUnit frameworks that
provide additional features or utilities specific to Selenium testing, such as parallel test execution,
test parameterization, and test suite management.

Browser Manipulation Utilities: Classes and methods for handling browser-specific operations, such
as managing cookies, handling alerts, executing JavaScript, and navigating back and forward in
browser history.

Screenshot and Video Capture Utilities: Utilities for capturing screenshots or recording videos of test
executions. These utilities are useful for documenting test results, reproducing failures, and providing
visual evidence of test coverage.

BrowserStack or Sauce Labs Integration Utilities: Integrations with cloud-based testing platforms like
BrowserStack or Sauce Labs for running Selenium tests on a wide range of browsers, devices, and
operating systems in parallel.

Configuration Management Utilities: Libraries or methods for managing test configurations and
environment settings. They help in configuring test parameters, setting up test environments, and
managing test data sources.
HTML,CSS,JacaScript:

Question: What is the purpose of the <div> element in HTML, and how is it commonly used?

Answer:
The <div> element in HTML is a generic container used to group and style other elements or sections
of a web page. It does not have any specific semantic meaning and is primarily used for layout
purposes and organizing content.

Question: In the code block below, there is a bug that prevents the paragraph text from appearing.
Identify the bug and provide a fix.

<div>
<p>Some text here</p>
</div>Code language: HTML, XML (xml)

Answer:
The bug is that the closing </div> tag is missing a forward slash (“/”). The correct code should be:

<div>
<p>Some text here</p>
</div>Code language: HTML, XML (xml)

Question: Explain the CSS Box Model and its components.

Answer:
The CSS Box Model is a fundamental concept in CSS that describes how elements are rendered and
sized in a web page. It consists of four components: content, padding, border, and margin. The
content area is where the actual content of the element is displayed. The padding area surrounds
the content and provides space between the content and the border. The border is a line that goes
around the padding and content area, and the margin is the space outside the border.

Question: In the code block below, the CSS selector is incorrect. Identify the error and provide a
fix.

.styed-button {
background-color: blue;
color: white;
padding: 10px;
}Code language: CSS (css)

Answer:
The error is in the CSS selector. It should be .styled-button instead of .styed-button. The correct code
should be:

.styled-button {
background-color: blue;
color: white;
padding: 10px;
}Code language: CSS (css)
Question: Explain the purpose of the querySelector method in JavaScript, and provide an example
of how to use it.

Answer:
The querySelector method in JavaScript allows you to select elements from the DOM using CSS-style
selectors. It returns the first element that matches the selector. Here’s an example:

const element = document.querySelector(".my-class");Code language: JavaScript (javascript)

This example selects the first element with the class “my-class” and assigns it to
the element variable.

Question: In the code block below, there is a syntax error preventing the JavaScript function from
executing. Identify the error and provide a fix.

function sayHello() {
console.log("Hello, world!")
}Code language: JavaScript (javascript)

Answer:
The error is the missing closing parenthesis “)” at the end of the function definition. The correct code
should be:

function sayHello() {
console.log("Hello, world!");
}Code language: JavaScript (javascript)

Question: Explain the purpose of the href attribute in an <a> element in HTML, and how it is used.

Answer:
The href attribute in an <a> element is used to specify the URL or destination that the link should
navigate to when clicked. It is an essential attribute for creating hyperlinks in HTML. The value of
the href attribute can be an absolute URL, a relative URL, or an anchor reference within the same
page.

Question: In the code block below, the CSS property is missing. Identify the missing property and
provide a fix.

.container {
width: 500px;
height: 300px;
background-color: red;
/* Missing CSS property */
}Code language: CSS (css)

Answer:
The missing CSS property is border. To fix the code, add the border property with the desired value,
such as:

.container {
width: 500px;
height: 300px;
background-color: red;
border: 1px solid black;
}Code language: CSS (css)

Question: Explain the concept of event handling in JavaScript and provide an example of attaching
an event listener to a button.

Answer:
In JavaScript, event handling involves responding to user actions or events triggered by the browser.
Event listeners are functions that listen for specific events and execute code in response. Here’s an
example of attaching an event listener to a button:

<button id="myButton">Click me</button>Code language: HTML, XML (xml)


const button = document.getElementById("myButton");

button.addEventListener("click", () => {
console.log("Button clicked!");
});Code language: JavaScript (javascript)

In this example, the event listener is attached to the button element with the id “myButton.” When
the button is clicked, the anonymous arrow function is executed, and it logs “Button clicked!” to the
console.

Question: In the code block below, the JavaScript function contains an error preventing it
from executing. Identify the error and provide a fix.

function calculateSum(a, b) {
const sum = a + b;
console.log("The sum is: " + sum);
}

calculateSum(5, 10;Code language: JavaScript (javascript)

Answer:
The error is the missing closing parenthesis “)” at the end of the function call. The correct
code should be:

calculateSum(5, 10);
HTML Interview Questions and Answers

1. What is HTML?
HTML stands for HyperText Markup Language. It is used to design web pages using a markup
language. HTML is a combination of Hypertext and Markup language. Hypertext defines the link
between the web pages. The markup language is used to define the text document within the tag
which defines the structure of web pages. HTML is used to structure the website and is therefore
used for Web Development.

2. Difference between HTML and XHTML


S.No. HTML XHTML

HTML stands for Hypertext Markup XHTML stands for Extensible Hypertext
1.
Language. Markup Language.

It was developed by W3C i.e.lowercase World


2. It was developed by Tim Berners-Lee.
Wide Web Consortium.

3. It was developed in 1991. It was released in 2000.

4. It is extended from SGML. It is extended from XML and HTML.

5. The format is a document file format. The format is a markup language.

All tags and attributes are not necessarily In this, every tag and attribute should be in
6.
to be in lower or upper case. lower case.

Doctype is not necessary to write at the Doctype is very necessary to write at the top
7.
top. of the file.

It is not necessary to close the tags in the It is necessary to close the tags in the order
8.
order they are opened. they are opened.

While using the attributes it is not


While using the attributes it is mandatory to
9. necessary to mention quotes. For e.g.
mention quotes. For e.g. <Geeks=”GFG”>.
<Geeks>.

The used filename extensions are .html, The used Filename extensions are .xhtml, .xht,
10.
.htm. .xml.

3. What is the difference between HTML and HTML 5?


HTML HTML5

It didn’t support audio and video without the use It supports audio and video controls with the
of Flash player support. use of <audio> and <video> tags.

It uses SQL databases and application cache


It uses cookies to store temporary data.
to store offline data.

Allows JavaScript to run in the background.


Does not allow JavaScript to run in the browser. This is possible due to JS Web worker API in
HTML5.

Vector graphics are possible in HTML with the help


Vector graphics is additionally an integral
of various technologies such as VML, Silver-light,
part of HTML5 like SVG and canvas.
Flash, etc.

It does not allow drag-and-drop effects. It allows drag-and-drop effects.

Not possible to draw shapes like circles, HTML5 allows drawing shapes like circles,
rectangles, triangles, etc. rectangles, triangles, etc.

It is supported by all-new browsers like


It works with all old browsers.
Firefox, Mozilla, Chrome, Safari, etc.

Older versions of HTML are less mobile-friendly. HTML5 language is more mobile-friendly.

The doctype declaration is too long and The doctype declaration is quite simple and
complicated. easy.

New elements for web structure like nav,


Elements like nav and header were not present.
header, footer, etc.

Character encoding is long and complicated. Character encoding is simple and easy.

It is almost impossible to get the true GeoLocation One can track the Geo Location of a user
of users with the help of the browser. easily by using JS GeoLocation API.

It can not handle inaccurate syntax. It is capable of handling inaccurate syntax.

Attributes like charset, async, and ping are absent Attributes of the charset, async, and ping are
in HTML. a part of HTML 5.
4.What are the various markup languages available?
• HTML: Hypertext Markup Language
• KML: Key whole Markup Language
• MathML: Mathematical Markup Language
• SGML: Standard Generalized Markup Language
• XHTML: eXtensible Hypertext Markup Language
• XML: eXtensible Markup Language

5. What is the current version of HTML?


HTML 5 is the fifth and current version of HTML.
6. What is !DOCTYPE?
A doctype or document-type declaration is an instruction that tells the web browser about the
markup language in which the current page is written. The doctype is not an element or tag, it lets
the browser know about the version of or standard of HTML or any other markup language that is
being used in the document. The DOCTYPE for HTML5 is case-insensitive and can be written as
shown below:
<!DOCTYPE html>

7. What are elements and tags, and what are the differences between them?
HTML Tags: Tags are the starting and ending parts of an HTML element. They begin with < symbol
and end with > symbol. Whatever is written inside < and > are called tags.
Syntax:
<b> </b>
HTML elements: Elements enclose the contents in between the tags. They consist of some kind of
structure or expression. It generally consists of a start tag, content, and an end tag.
Syntax:
<b>This is the content.</b>
Difference between HTML Tag & HTML Element:
HTML Tag HTML Element

Either opening or closing is used to mark the start Collection of a start tag, end tag, and its
or end of an element. attributes.

Used to hold the HTML element. Holds the content.

Whatever is written within an HTML tag are


Starts with < and ends with >.
HTML elements.

8. What are the various heading tags and their importance?


There are 6 levels of headings defined by HTML. These six heading elements are H1, H2, H3, H4, H5,
and H6; with H1 being at the highest level and H6 at the least.
Importance of Heading:
• Search Engines use headings for indexing the structure and content of the webpage.
• Headings are used for highlighting important topics.
• They provide valuable information and tell us about the structure of the document.
9. How to redirect to a particular section of a page using HTML?
One can use the anchor tag to redirect to a particular section on the same page. You need to add
“id attribute” to the section that you want to show and use the same id in href attribute with “#” in
the anchor tag. So that On click a particular link, you will be redirected to the section that has the
same id mentioned in the anchor tag.
Syntax:
<a href="#home_section">home</a>

<section id="home_section">
Information About Page
</section>
Example: When the user clicks on the “Contact Us” link, he will be redirected to the “Contact Us
section” on the same page.

• HTML

<!DOCTYPE html>
<html>

<head>
<style>
div {
width: 100%;
height: 400px;
border: 1px solid black;
}
</style>
</head>

<body>
<h2>Welcome to GeeksforGeeks</h2>
<p>
This is the example of
<i>
Redirect to a particular section
using HTML on same page
</i>
</p>

<a href="#contactUs"> Contact Us </a>


<div>
<h2>Home section</h2>
</div>
<div>
<h2>About Us section</h2>
</div>
<div id="contactUs">
<h2>Contact Us section </h2>
</div>
<div>
<h2>Team Section</h2>
</div>
</body>

</html>

Output:

10. What are attributes?


An attribute is used to provide extra or additional information about an element.
• All HTML elements can have attributes. Attributes provide additional information about
an element.
• It takes 2 parameters ie., name and value. These define the properties of the element
and are placed inside the opening tag of the element. The name parameter takes the
name of the property we would like to assign to the element and the value takes the
property value or extent of the property names that can be aligned over the element.
• Every name has some value that must be written within quotes.

11. Are <b> and <strong> tags same? If not, then why?
HTML strong tag: The strong tag is one of the elements of HTML used in formatting HTML texts. It
is used to show the importance of the text by making it bold or highlighting it semantically.
Syntax:
<strong> Contents... </strong>
HTML bold tag: The bold tag or <b> is also one of the formatting elements of HTML. The text written
under the <b> tag makes the text bold presentationally to draw attention.
Syntax:
<b> Contents... </b>
The main difference between the <bold> tag & <strong> tag is that the strong tag semantically
emphasizes the important word or section of words while the bold tag is just offset text
conventionally styled in bold.

12. What is the difference between <em> and <i> tags?


<i> tag: It is one of the elements of HTML which is used in formatting HTML texts. It is used to define
a text in technical terms, alternative mood or voice, a thought, etc.
Syntax:
<i> Content... </i>
<em> tag: It is also one of the elements of HTML used in formatting texts. It is used to define
emphasized text or statements.
Syntax:
<em> Content... </em>
By default, the visual result is the same but the main difference between these two tags is that the
<em> tag semantically emphasizes the important word or section of words while the <i> tag is just
offset text conventionally styled in italic to show alternative mood or voice. Click Here to know the
difference between them.

13. How are comments added in HTML?


The comment tag (<!– Comment –>) is used to insert comments in the HTML code.
Types of HTML Comments: There are three types of comments in HTML which are:
• Single-line comment
• Multi-lines comment
• Using <comment> tag

14. What are the different formats in which colors in HTML can be declared?
The color of an element can be defined in the following ways:
• Built-In Color
• RGB Format
• RGBA Format
• Hexadecimal Notation
• HSL
• HSLA
• Hue: Hue is the degree of the color wheel. Its value lies between 0 to 360 where 0
represents red, 120 represents green and 240 represents blue color.
• Saturation: It takes a percentage value, where 100% represents completely saturated,
while 0% represents completely unsaturated (gray).
• Lightness: It takes a percentage value, where 100% represents white, while 0%
represents black.

15. How to create a link in HTML?


A Link is a connection from one Web resource to another. A link has two ends, An anchor and a
direction. The link starts at the “source” anchor and points to the “destination” anchor, which may
be any Web resource such as an image, a video clip, a sound bite, a program, an HTML document,
or an element within an HTML document.
HTML Link Syntax: Links are specified in HTML using the “a” tag.
<a href="url">Link Text<a>
Explanation:
• href: The href attribute is used to specify the destination address of the link used.
• Text link: The text link is the visible part of the link.

16. What is the use of the target attribute in the <link> tag?
The HTML <link> target Attribute is used to specify the window or a frame where the linked
document is loaded. It is not supported by HTML 5.
Syntax:
<link target="_blank|_self|_parent|_top|framename">
Attribute Values:
• _blank: It opens the link in a new window.
• _self: It opens the linked document in the same frame.
• _parent: It opens the linked document in the parent frameset.
• _top: It opens the linked document in the full body of the window.
• framename: It opens the linked document in the named frame.

17. What is the use of alt attribute in images?


The <img> alt attribute is used to specify the alternate text for an image. It is useful when the image
is not displayed. It is used to give alternative information for an image.
Syntax:
<img alt="text">

18. What are the HTML tags used to display a table?


• <table>: It is used to define a table.
• <tr>: It is used to define a row in a table.
• <th>: It is used to define a header cell in a table.
• <td>: It is used to define a cell in a table.
• <caption>: It is used to define the table caption.
• <colgroup>: It is used to define a group of one or more columns in a table for formatting.
• <col>: It is used with <colgroup> element to specify column properties for each column.
• <tbody>: It is used to define a group of body content in a table.
• <thead>: It is used to group the header content in a table.
• <tfooter>: It is used to group the footer content in a table.

19. What are the different types of lists in HTML?


A list is a record of short pieces of related information used to display the data or any information
on web pages in the ordered or unordered form. HTML offers 3 ways for specifying lists of
information. All lists must contain one or more list elements. The types of lists that can be used in
HTML are:
• Unordered List: It will list the items using plain bullets.
• Ordered List: It will use different schemes of numbers to list your items.
• Definition List: It arranges your items in the same way as they are arranged in a
dictionary.

20. What is the difference between block and inline elements?


Every element in HTML has a default display value which depends upon the element
type. Block or inline is the default display value for most of the elements.
Block-Level Elements: A block-level element always starts on a new line and stretches out to the
left and right as far as it can.
• div element: The div element is used as a container for other HTML elements. It has
no required attributes. Style, class, and id are the commonly used attributes.
• span element: The span element is used as a container for text. It has no required
attributes. Style, class, and id are the commonly used attributes.

APPIUM:

1) Explain what is Appium?


Appium is a freely distributed open source mobile application UI Testing framework.

2) List out the Appium abilities?


Appium abilities are

• Test Web
• Provides cross-platform for Native and Hybrid mobile automation
• Support JSON wire protocol
• It does not require recompilation of App
• Support automation test on physical device as well as similar or emulator both
• It has no dependency on mobile device

3) List out the pre-requisite to use APPIUM?


Pre-requisite to use APPIUM is

• ANDROID SDK
• JDK
• TestNG
• Eclipse
• Selenium Server JAR
• Webdriver Language Binding Library
• APPIUM for Windows
• APK App Info On Google Play
• js

4) List out the limitations of using Appium?

• Appium does not support testing of Android Version lower than 4.2
• Limited support for hybrid app testing. E.g., not possible to test the switching action of
application from the web app to native and vice-versa
• No support to run Appium Inspector on Microsoft Windows
Appium interview questions

5) Explain how to find DOM element or xPath in a mobile application?


To find the DOM element use “UIAutomateviewer” to find DOM element for Android application.

6) Explain the design concept of Appium?

• Appium is an “HTTP Server” written using Node.js platform and drives iOS and Android
session using Webdriver JSON wire protocol. Hence, before initializing the Appium Server,
Node.js must be pre-installed on the system
• When Appium is downloaded and installed, then a server is setup on our machine that
exposes a REST API
• It receives connection and command request from the client and execute that command on
mobile devices (Android / iOS)
• It responds back with HTTP responses. Again, to execute this request, it uses the mobile test
automation frameworks to drive the user interface of the apps. Framework like
• Apple Instruments for iOS (Instruments are available only in Xcode 3.0 or later with
OS X v10.5 and later)
• Google UIAutomator for Android API level 16 or higher
• Selendroid for Android API level 15 or less

7) What language does Appium support?


Appium support any language that support HTTP request like Java, JavaScript with Node.js, Python,
Ruby, PHP, Perl, etc.

8) Explain the pros and cons of Appium?


Pros:

• For programmer irrespective of the platform, he is automating ( Android or iOS) all the
complexities will remain under single Appium server
• It opens the door to cross-platform mobile testing which means the same test would work
on multiple platforms
• Appium does not require extra components in your App to make it automation friendly
• It can automate Hybrid, Web and Native mobile applications

Cons:

• Running scripts on multiple iOS simulators at the same time is possible with Appium
• It uses UIAutomator for Android Automation which supports only Android SDK platform, API
16 or higher and to support the older API’s they have used another open source library
called Selendroid
9) Explain what is APPIUM INSPECTOR?
Similar to Selenium IDE record and Playback tool, Appium has an “Inspector” to record and playback.
It records and plays native application behavior by inspecting DOM and generates the test scripts in
any desired language. However, Appium Inspector does not support Windows and use UIAutomator
viewer in its option.

10) Mention what are the basic requirement for writing Appium tests?
For writing Appium tests you require,

• Driver Client: Appium drives mobile applications as though it were a user. Using a client
library you write your Appium tests which wrap your test steps and sends to the Appium
server over HTTP.
• Appium Session: You have to first initialize a session, as such Appium test takes place in the
session. Once the Automation is done for one session, it can be ended and wait for another
session
• Desired Capabilities: To initialize an Appium session you need to define certain parameters
known as “desired capabilities” like PlatformName, PlatformVersion, Device Name and so
on. It specifies the kind of automation one requires from the Appium server.
• Driver Commands: You can write your test steps using a large and expressive vocabulary of
commands.

11) Mention what are the possible errors one might encounter using Appium?
The possible errors one might face in Appium includes

• Error 1: The following desired capabilities are needed but not provided: Device Name,
platformName
• Error 2: Could not find adb. Please set the ANDROID_HOME environment variable with the
Android SDK root directory path
• Error 3: openqa.selenium.SessionNotCreatedException: A new session could not be created
• Error 4: How to find DOM element or XPath in a mobile application?

12) Do you need a server machine to run tests on Appium?


No, you don’t need server machine to run tests on Appium. Appium facilitates a 2-tier architecture
where a test machine connects to a test server running Appium and automating the whole thing.
You can have Appium running on the same machine where your test runs.

13) Is it possible to interact with my apps using Javascript while I am testing with Appium?
Yes, it is possible to interact with App while using Javascript. When the commands run on Appium,
the server will send the script to your app wrapped into an anonymous function to be executed.
14) Mention what are the most difficult scenarios to test with Appium?
The most difficult scenario to test with Appium is data exchange.

15) While using Appium can I run my tests in a multithreaded environment?


Yes, you can run the test in a multithreaded environment but you have to ensure that no more than
one test runs at the same time against the same Appium server.

16) In Android, do you need an app’s .apk to automate using Appium or you also need app in my
workspace?
In Android, you only need .apk file to automate using Appium.

17) Explain what is Appium package master? How to create package?


Appium package master is a set of tools manage and create appium packages. For example to create
package you can use the code

# using es7/babe1

Gulp create-package –n <package-name>

#regular es5

Gulp create-package ---nobabe1 –n <package-name>

The package will be generated in the out/<package-name>

18) Explain how test frameworks are supported by Appium?


Appium does not support test framework as such there is no need to support them. Appium can be
used with any frameworks you want.
API and Postman:
1. What is API testing?

API testing is a type of software testing that involves checking if the Application Programming
Interfaces (APIs) meet their functionality, reliability, performance, and security requirements. It
focuses on verifying the communication and data exchange between different software
components or systems.

2. What is Postman?

Postman is a popular tool used for API development and testing. It provides an intuitive user
interface for sending requests to APIs, testing API endpoints, automating API testing workflows,
and generating API documentation.

3. Why is API testing important?

API testing is crucial because it ensures that APIs function correctly and reliably, facilitating
smooth communication and data exchange between different software components or systems.
It helps identify bugs, security vulnerabilities, and performance issues early in the development
lifecycle, saving time and resources.

4. How do you perform API testing using Postman?

In Postman, API testing involves creating requests to API endpoints using HTTP methods like GET,
POST, PUT, DELETE, etc. We can then send these requests to the API server and analyze the
responses to verify if the API behaves as expected. Postman provides features like environment
variables, test scripts, assertions, and collections to streamline and automate the API testing
process.

5. What are environment variables in Postman?


• Environment variables in Postman are placeholders for dynamic values that can be reused
across multiple requests. They help streamline testing workflows by allowing users to define
variables like base URLs, authentication tokens, or user inputs once and use them
consistently throughout their tests. This makes it easier to manage and maintain test
configurations.
• Environment variables in Postman are like sticky notes for important information. They're
placeholders that can hold things like website addresses, secret codes, or anything else you
need for testing. You write down these details once, and then you can use them over and
over again in all your tests. This saves time and makes sure everything stays organized and
correct.

6. How can you automate API testing in Postman?

Automation in Postman can be achieved using collections and test scripts. Collections allow you
to organize and group related requests together, while test scripts enable you to define custom
validation logic and assertions. By combining collections with test scripts and leveraging features
like Newman (Postman's command-line tool) or integrating with continuous integration (CI)
systems, we can automate the execution of API tests as part of your development pipeline.
7. What are some common challenges faced in API testing?

Some common challenges in API testing include handling authentication mechanisms, ensuring
proper data validation and error handling, managing dependencies on external services, testing
for edge cases and boundary conditions, and maintaining test suites as APIs evolve over time.
Effective strategies and tools like Postman can help address these challenges and streamline the
API testing process.

8. What is the importance of status codes in API testing?

Status codes in API responses indicate the success or failure of a request and provide additional
information about the result. For example, HTTP status code 200 indicates a successful response,
while codes like 404 signify that the requested resource was not found. In API testing, analyzing
status codes helps verify if the API behaves as expected under different conditions and enables
testers to identify and troubleshoot issues effectively.

9. How do you handle authentication in API testing with Postman?

Postman provides various authentication methods such as Basic Auth, Digest Auth, OAuth 1.0,
OAuth 2.0, API Key, etc. You can configure authentication for your requests within Postman by
selecting the appropriate method and providing the required credentials or tokens. Additionally,
Postman allows you to automate authentication processes using environment variables or
scripts, making it easier to manage and reuse authentication settings across multiple requests.

10. What are some best practices for API testing?

Some best practices for API testing include:

• Identifying test scenarios: Determine the functionality, performance, security, and edge
cases to be tested.
• Creating reusable test cases: Develop modular and maintainable test cases that can be
reused across different API endpoints.
• Using automation: Automate repetitive tasks and regression tests to increase efficiency and
consistency.
• Validating responses: Verify response data, status codes, headers, and error messages to
ensure correctness and reliability.
• Handling dependencies: Mock external dependencies or use stubs to isolate the API under
test and ensure reliable test execution.
• Implementing security testing: Test for vulnerabilities such as injection attacks,
authentication flaws, and data exposure.
• Monitoring performance: Measure response times, throughput, and resource utilization to
assess performance under different loads.
• Documenting tests: Document test cases, scenarios, and results for traceability and
knowledge sharing within the team.
11. How can you parameterize requests in Postman?
• Parameterization in Postman allows you to replace static values in requests with variables,
making tests more dynamic and reusable.
• You can use variables to represent values like URLs, query parameters, headers, request
bodies, etc.
• Postman supports various types of variables, including environment variables, global
variables, collection variables, and local variables defined within request scripts.
• By parameterizing requests, you can easily adapt tests to different environments or scenarios
without modifying the test logic.
12. What is API mocking, and how is it useful in API testing?

API mocking means creating pretend responses from API endpoints without talking to the real
backend. It's like practicing with a dummy instead of a real opponent. It helps testers to try out
different situations and problems before everything is fully set up, making testing faster and
more flexible.

13. How do you handle pagination in API testing with Postman?

Pagination is like breaking a big list into smaller pieces. In Postman, you handle it by asking for
one piece at a time and then automatically getting the next piece until you have everything. It's
like asking for a few pages of a book at a time instead of the whole book at once.

14. What are pre-request scripts and post-request scripts in Postman?

Pre-request scripts are like getting ready before you go out — you might check the weather or
grab your keys. In Postman, it's code you run just before sending a request. Post-request scripts
are like what you do after you come back home — maybe you unpack your bags or write down
what happened. In Postman, it's code you run just after getting a response.

Program Statement:
Given two sorted arrays 'a' and 'b' of size 'n' and 'm' respectively.

Find the median of the two sorted arrays.

Median is defined as the middle value of a sorted list of numbers. In case the length of list is
even, median is the average of the two middle elements.

The expected time complexity is O(min(logn, logm)), where 'n' and 'm' are the sizes of arrays 'a'
and 'b', respectively, and the expected space complexity is O(1).

Example:
Input: 'a' = [2, 4, 6] and 'b' = [1, 3, 5]

Output: 3.5

Explanation: The array after merging 'a' and 'b' will be { 1, 2, 3, 4, 5, 6 }. Here two medians are 3 and
4. So the median will be the average of 3 and 4, which is 3.5.
Detailed explanation ( Input/output format, Notes, Images )
Sample Input 1:
33
246
135
Sample Output 1:
3.5
Explanation of Sample Input 1 :
The array after merging 'a' and 'b' will be { 1, 2, 3, 4, 5, 6 }.
Here two medians are 3 and 4. So the median will be the average of 3 and 4, which is 3.5.
Sample Input 2:
32
246
13
Sample Output 2:
3
Explanation of Sample Input 2 :
The array after merging 'a' and 'b' will be { 1, 2, 3, 4, 6 }.
The median is 3.
Sample Input 3:
33
122
244
Sample Output 3:
2.0
Explanation of Sample Input 3 :
The array after merging 'a' and 'b' will be { 1, 2, 2, 2, 4, 4 }.
Here two medians are 2 and 2. So the median will be the average of 2 and 2, which is 2.
Constraints:
1 <= 'n' <= 10 ^ 6
1 <= 'm' <= 10 ^ 6
1 <= 'a[i]' <= 10 ^ 9
1 <= 'b[i]' <= 10 ^ 9

Time limit: 1 sec.


Program:

import java.util.Arrays;

public class Solution {


public static double median(int[] a, int[] b) {
int[] merged = new int[a.length + b.length];
System.arraycopy(a, 0, merged, 0, a.length);
System.arraycopy(b, 0, merged, a.length, b.length);
Arrays.sort(merged);
int totalLength = merged.length;
if (totalLength % 2 == 0) {
return (merged[totalLength / 2 - 1] + merged[totalLength / 2]) / 2.0;
} else {
return merged[totalLength / 2];
}
}
}

• Import Statement:

This line imports the Arrays class from the java.util package, which provides utility methods for
arrays, including sorting.

• Method Declaration:

The median method takes two integer arrays a and b as input parameters and returns a double value,
which represents the median of the merged array.
• Merging Arrays:

Here, we create a new integer array merged with a length equal to the sum of the lengths of arrays a
and b. We then use System.arraycopy() method to copy the elements of arrays a and b into the
merged array. This effectively merges the two arrays into a single array.

• Sorting:

After merging the arrays, we sort the merged array in ascending order using the Arrays.sort()
method. Sorting the array is necessary to find the median value.

• Calculating Median:

If the total length of the merged array is even, we take the average of the two middle elements to get
the median. If the total length is odd, we simply return the middle element as the median.

• Return Statement:

Finally, the method returns the calculated median value.

This implementation is straightforward and easy to understand. It merges the arrays, sorts them, and
then calculates the median based on the length of the merged array.

You might also like