Interview for Java SDET position
Interview for Java SDET position
1. Reverse a String
o Write a Java program to reverse a string without using the built-in reverse
function.
2. Find Duplicates in an Array
o Write a Java program to find duplicates in an array of integers.
3. Selenium WebDriver Exercise: Login Automation
o Automate a login scenario for a website (e.g., Facebook, Gmail).
o Locate the username and password fields, enter credentials, and click the login
button.
o Verify that the login was successful by checking the presence of a specific
element.
4. File Handling
o Write a Java program to read data from a CSV file and print it to the console.
5. API Testing with REST Assured
o Write a test script to validate a REST API endpoint that performs CRUD
operations.
6. Simple Calculator
o Write a Java program to implement a simple calculator with basic operations
(addition, subtraction, multiplication, division).
7. Find the Longest Substring Without Repeating Characters
o Write a Java program to find the length of the longest substring without repeating
characters.
8. Palindrome Check
o Write a Java program to check if a given string is a palindrome.
9. Selenium WebDriver Exercise: Data-Driven Testing
o Automate a form submission scenario using data from an Excel file.
o Use Apache POI to read data from Excel and input it into a web form.
10. Fibonacci Series
o Write a Java program to print the first N Fibonacci numbers.
Reverse a String
java
Copy code
public class ReverseString {
public static void main(String[] args) {
String original = "Hello, World!";
String reversed = reverseString(original);
System.out.println("Reversed String: " + reversed);
}
java
Copy code
import java.util.HashSet;
import java.util.Set;
Preparing thoroughly on these topics and practicing these exercises should help you feel
confident and ready for your SDET Java Selenium interview. Good luck!
4o
Can you provide questions and answers for those topics you suggested
ChatGPT
Sure! Here are some potential questions and answers for each topic:
Q1: What is the difference between an abstract class and an interface in Java?
A1:
Abstract Class:
o Can have both abstract and concrete methods.
o Can have instance variables.
o Can provide a default behavior.
o Can have constructors.
o A class can extend only one abstract class.
Interface:
o Can only have abstract methods (Java 8 onwards, can also have default and static
methods).
o Cannot have instance variables.
o Cannot provide any behavior (except default methods in Java 8 onwards).
o Cannot have constructors.
o A class can implement multiple interfaces.
Selenium WebDriver
A1:
java
Copy code
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
// Select by value
dropdown.selectByValue("value1");
// Select by index
dropdown.selectByIndex(1);
}
}
A2:
java
Copy code
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
A1:
Page Object Model (POM) is a design pattern that creates an object repository for web
UI elements.
Each web page is represented by a class, and the class contains methods to interact with
the web elements.
Benefits include improved code readability, reusability, and maintainability.
Example:
java
Copy code
public class LoginPage {
WebDriver driver;
By username = By.id("username");
By password = By.id("password");
By loginButton = By.id("login");
A2:
java
Copy code
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@DataProvider(name = "loginData")
public Object[][] loginData() {
return new Object[][] {
{ "user1", "pass1" },
{ "user2", "pass2" },
{ "user3", "pass3" }
};
}
@Test(dataProvider = "loginData")
public void testLogin(String username, String password) {
// Initialize WebDriver and navigate to login page
WebDriver driver = // Initialize your WebDriver
driver.get("http://example.com/login");
// Perform login
LoginPage loginPage = new LoginPage(driver);
loginPage.setUsername(username);
loginPage.setPassword(password);
loginPage.clickLogin();
xml
Copy code
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
Q2: How do you configure a Jenkins job to run your Selenium tests?
A2:
A1:
Q2: What is the difference between git pull and git fetch?
A2:
git pull:
o Fetches changes from the remote repository and merges them into your current
branch.
o Equivalent to git fetch followed by git merge.
git fetch:
o Fetches changes from the remote repository but does not merge them.
o Updates the remote tracking branches, allowing you to inspect changes before
merging.
API Testing
A1:
import io.restassured.RestAssured;
import io.restassured.response.Response;
A2:
import io.restassured.RestAssured;
import io.restassured.response.Response;
These questions and answers should help you prepare for your SDET Java Selenium interview
by covering essential topics and providing practical examples.
4o
Can you provide more questions and answers related to severity, priority, coverage, traceability,
http codes and the differences, what to validate in API testing, types of testing
ChatGPT
Memory updated
Q1: What is the difference between severity and priority in software testing?
A1:
Severity:
o Indicates the impact of a defect on the application's functionality.
o Categories: Critical, Major, Minor, Trivial.
o Example: A crash in the application is a critical severity issue.
Priority:
o Indicates the order in which a defect should be fixed.
o Categories: High, Medium, Low.
o Example: A typo in the home page might be low severity but high priority if the
product launch is imminent.
Severity: Usually determined by the tester or QA engineer based on the impact on the
application's functionality.
Priority: Typically determined by the product manager or the development team,
considering business needs and project deadlines.
A1:
Test Coverage: A metric used to measure the amount of testing performed by a set of
tests. It helps in understanding which parts of the application were tested and which were
not.
Importance:
o Ensures all parts of the application are tested.
o Helps in identifying untested parts of the application.
o Improves the quality and reliability of the software.
A2:
Traceability Matrix: A document that maps and traces user requirements with test
cases. It ensures that all requirements are covered by test cases.
Usage:
o Ensures all requirements are tested.
o Helps in identifying missing requirements or test cases.
o Facilitates impact analysis for any changes in requirements.
HTTP Codes
Q1: What are HTTP status codes and why are they important?
A1:
HTTP Status Codes: Standardized codes returned by the server to indicate the result of
the client's request.
Importance:
o Inform the client about the status of their request.
o Help in debugging and troubleshooting issues.
o Indicate whether the request was successful, caused a client error, or a server
error.
Q2: What is the difference between 4xx and 5xx HTTP status codes?
A2:
API Testing
A1:
Response Status Code: Ensure the API returns the correct status code (e.g., 200 OK, 404
Not Found).
Response Body: Validate the structure and content of the response body.
Headers: Check for required headers (e.g., Content-Type, Authorization).
Performance: Measure response time and ensure it meets performance requirements.
Error Handling: Ensure the API handles errors gracefully and returns meaningful error
messages.
Security: Validate authentication and authorization mechanisms.
A2:
Types of Testing
Q2: What is smoke testing and how is it different from sanity testing?
A2:
Smoke Testing:
o Performed on initial builds to check if the critical functionalities are working.
o Broad and shallow testing.
o Also known as "build verification testing."
Sanity Testing:
o Performed after receiving a software build with minor changes to check for the
correctness of those changes.
o Narrow and deep testing.
o Ensures specific functionality works as expected.
These questions and answers should help you deepen your understanding of essential concepts
and be well-prepared for your SDET Java Selenium interview.
4o
Can you include Page Factory and Xpath handling, relative xpath and absolute xpath, how to
write xpath and how to handle iFrames, how to handle tabs in browser, synchronization, testing
techniques, types of testing
ChatGPT
Memory updated
Q1: What is Page Factory in Selenium and how is it different from the Page Object Model?
A1:
Page Factory: A way to initialize web elements in the Page Object Model using @FindBy
annotations.
Differences:
o Page Factory uses annotations to initialize elements, making the code cleaner.
o Page Factory provides support for lazy initialization.
Example:
java
Copy code
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
@FindBy(id = "username")
WebElement username;
@FindBy(id = "password")
WebElement password;
@FindBy(id = "login")
WebElement loginButton;
XPath Handling
A1:
Absolute XPath: Starts from the root element and follows the entire path to the target
element.
o Example: /html/body/div[1]/div[2]/div[1]/button
o Less flexible; breaks easily if there are changes in the DOM structure.
Relative XPath: Starts from the current element and follows a shorter path to the target
element.
o Example: //div[@id='main']/button
o More flexible and reliable.
Q2: How do you write an XPath to locate an element with a specific attribute?
A2:
To locate an element with a specific attribute, use the @ symbol followed by the attribute
name.
o Example: //input[@id='username'] locates an input element with the id
attribute equal to username.
Handling iFrames
A1:
Example:
java
Copy code
WebDriver driver = // Initialize your WebDriver
driver.get("http://example.com");
Handling Tabs
A1:
Example:
java
Copy code
WebDriver driver = // Initialize your WebDriver
driver.get("http://example.com");
Synchronization
A1:
Implicit Wait: Tells the WebDriver to wait for a certain amount of time before throwing
a NoSuchElementException.
o Example:
java
Copy code
WebDriver driver = // Initialize your WebDriver
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Explicit Wait: Tells the WebDriver to wait for certain conditions to occur before
proceeding.
o Example:
java
Copy code
WebDriver driver = // Initialize your WebDriver
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("el
ementId")));
Testing Techniques
A1:
Boundary Value Analysis (BVA): A technique to test the boundaries between partitions.
It includes testing the minimum, maximum, just inside/outside boundaries, typical values,
and error values.
o Example: If the input range is 1 to 100, BVA would test 0, 1, 2, 99, 100, 101.
Q2: What is equivalence partitioning (EP)?
A2:
Equivalence Partitioning (EP): Divides input data into partitions of equivalent data
from which test cases can be derived. It assumes that all values in a partition behave the
same way.
o Example: If the input is a number from 1 to 100, the partitions could be: less than
1, between 1 and 100, and greater than 100.
Types of Testing
A1:
Q2: What is smoke testing and how is it different from sanity testing?
A2:
Smoke Testing:
o Performed on initial builds to check if the critical functionalities are working.
o Broad and shallow testing.
o Also known as "build verification testing."
Sanity Testing:
o Performed after receiving a software build with minor changes to check for the
correctness of those changes.
o Narrow and deep testing.
o Ensures specific functionality works as expected.
A1:
Use the text() function to locate an element by its text content.
o Example: //button[text()='Submit'] locates a button with the text "Submit".
Q2: How do you write an XPath to locate an element with a partial match on an attribute?
A2:
Use the contains() function to locate elements with a partial attribute value.
o Example: //input[contains(@id, 'user')] locates input elements with id
containing the string "user".