Test Engineer FAQ. Test Theory and Automation

February 27, 2023

What is a Test Case and Test Suite?

In software testing, a test case is a set of conditions or variables that are designed to test a particular aspect or feature of a software application. It is a specific set of steps or actions that are executed to verify the correct behavior of a software system under certain conditions.

A test case usually consists of several elements, including a description of the test, input data to be used in the test, the expected output of the test, and any other conditions or requirements that must be met for the test to be considered successful.

A test suite, on the other hand, is a collection of test cases that are designed to test the functionality of a software application as a whole. It is a set of related test cases that are executed together to ensure that the software system behaves correctly in different scenarios and under various conditions.

A test suite can be made up of hundreds or even thousands of individual test cases, and it is usually designed to cover all the major features and functionalities of the software application. Test suites can be automated or executed manually, depending on the complexity and nature of the software being tested.

What's the example of using WebDriver framework for Test Automation?

Here's an example of using WebDriver and Java to automate a Google search query:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleSearchExample {
    public static void main(String[] args) {
        // Set the path to the chromedriver executable
        System.setProperty("webdriver.chrome.driver", "path/to/chromedriver.exe");

        // Create a new instance of the Chrome driver
        WebDriver driver = new ChromeDriver();

        // Navigate to Google
        driver.get("https://www.google.com");

        // Find the search box element and enter a query
        WebElement searchBox = driver.findElement(By.name("q"));
        searchBox.sendKeys("java webdriver example");

        // Submit the query
        searchBox.submit();

        // Wait for the search results to load
        driver.findElement(By.id("result-stats"));

        // Print the title of the first search result
        WebElement firstResult = driver.findElement(By.xpath("//div[@class='g']//h3"));
        System.out.println("First result: " + firstResult.getText());

        // Close the browser
        driver.quit();
    }
}

In this example, we use the ChromeDriver to open a new instance of the Chrome browser and navigate to Google. We then find the search box element on the page using the By.name() method and enter a query using the sendKeys() method. We submit the query by calling the submit() method on the search box element.

After the search results load, we wait for the element with the ID "result-stats" to be present on the page using the findElement() method. We then find the title of the first search result using the By.xpath() method and print it to the console.

Finally, we close the browser using the quit() method on the WebDriver instance.

How to use Cypress for Unit Testing?

Here is an example of a unit test using Cypress:

Suppose we have a simple function that performs a basic calculation:

function addNumbers(a, b) {
  return a + b;
}

We can create a unit test for this function using Cypress. Here's how it can be done:

  1. First, we create a new Cypress test file in the cypress/integration directory. We can call it add.spec.js.
  2. In the add.spec.js file, we import the addNumbers function and write our test case. Here's an example:
describe('addNumbers', () => {
  it('adds two numbers correctly', () => {
    const result = addNumbers(2, 3);
    expect(result).to.equal(5);
  });
});
  1. In the test case, we call the addNumbers function with two numbers (2 and 3), and we expect the result to be 5. If the result is not 5, the test will fail.
  2. We can run the test by opening the Cypress Test Runner with the command npm run cypress:open (assuming we have set up Cypress in our project and added the necessary scripts to the package.json file). Then we can click on the add.spec.js file to run the test.
  3. If the test passes, we will see a green checkmark in the Cypress Test Runner. If it fails, we will see a red X and an error message indicating what went wrong.

This is a very simple example, but unit tests can become much more complex as the functions being tested become more complex. Cypress provides a powerful set of tools for testing web applications, and it can be a great choice for unit testing as well as other types of testing.

What is a Page Object Model (POM)?

The Page Object Model (POM) is a design pattern used in test automation to organize web application tests in a structured and maintainable way. It aims to provide a clear separation between the test code and the page-specific implementation details, such as the HTML structure, CSS, or JavaScript code.

In the Page Object Model, each web page or component in the application is represented by a separate class that contains all the related test methods and element locators. This class is responsible for interacting with the web page or component, and exposing its functionality to the test methods.

Here's an example of implementing the Page Object Model in JavaScript using the WebDriverIO library:

class LoginPage {
  get usernameField() { return $('#username'); }
  get passwordField() { return $('#password'); }
  get loginButton() { return $('#login-button'); }

  enterUsername(username) {
    this.usernameField.waitForDisplayed();
    this.usernameField.setValue(username);
  }

  enterPassword(password) {
    this.passwordField.waitForDisplayed();
    this.passwordField.setValue(password);
  }

  clickLoginButton() {
    this.loginButton.waitForDisplayed();
    this.loginButton.click();
  }
}

In this example, we have a LoginPage class that represents the login page of a web application. It has three getter methods (usernameField, passwordField, and loginButton) that use WebDriverIO's $ function to locate the corresponding elements on the page. The class also has three methods (enterUsername, enterPassword, and clickLoginButton) that simulate user actions on the page.

In the test code, we can create an instance of the LoginPage class and use its methods to interact with the page, like this:

const LoginPage = require('./LoginPage');

describe('Login functionality', () => {
  it('should allow valid user to login', () => {
    browser.url('https://example.com/login');
    const loginPage = new LoginPage();

    loginPage.enterUsername('myusername');
    loginPage.enterPassword('mypassword');
    loginPage.clickLoginButton();

    // Continue with the test...
  });
});

By using the Page Object Model, we can keep our test code organized, modular, and easy to maintain as the web application evolves over time.

How to do Performance Testing Using K6 framework?

K6 is a popular open-source load testing tool that allows developers to write performance tests in JavaScript. Here are the steps to perform performance testing using K6:

  1. Install K6: You can download and install K6 from the official website: https://k6.io/docs/getting-started/installation/
  2. Write a script: Once you have installed K6, you can write a script to perform the performance testing. The script is written in JavaScript and contains the instructions to simulate user behavior and generate load on the system. K6 provides various functions and modules to help you write the script.

Here is an example of a simple script that sends an HTTP request to a website and logs the response time:

import http from "k6/http";
import { check } from "k6";

export default function() {
  let response = http.get("https://example.com/");
  check(response, {
    "is status 200": (r) => r.status === 200
  });
}

Run the script: You can run the script by executing the following command in the terminal: k6 run script.js

This will start the performance test and display the results on the Terminal.

Analyze the results: Once the performance test is complete, you can analyze the results to identify any bottlenecks or issues in the system. K6 provides various options to output the results in different formats, such as JSON, CSV, and InfluxDB. You can use tools like Grafana to visualize the results and gain insights into the system's performance.

Overall, K6 is a powerful tool for performance testing and allows developers to write scripts in JavaScript, making it easier to integrate with the development workflow.

What is an Accessibility Testing?

Accessibility testing is the process of evaluating a website, application, or product to ensure that it can be used by individuals with disabilities, such as those with visual, auditory, motor, or cognitive impairments. The goal of accessibility testing is to identify and remove any barriers or obstacles that may prevent individuals with disabilities from accessing and using the product.

Accessibility testing may involve manual testing by individuals with disabilities, automated testing using specialized tools, or a combination of both. Some common accessibility testing techniques include:

  1. Screen reader testing: Testing the product using a screen reader to ensure that it is accessible to users with visual impairments.
  2. Keyboard-only testing: Testing the product using only the keyboard to ensure that it is accessible to users with motor impairments who cannot use a mouse.
  3. Color contrast testing: Testing the product to ensure that text and other elements are visible to users with color vision deficiencies.
  4. Caption and transcript testing: Testing multimedia elements to ensure that they are accessible to users who are deaf or hard of hearing.
  5. Assistive technology testing: Testing the product using various assistive technologies such as magnifiers, speech recognition software, or alternative input devices.

By conducting accessibility testing, developers can identify and address accessibility issues early in the development process, making their products more inclusive and accessible to all users.

What are the most common ADB commands for Android Testing?

ADB (Android Debug Bridge) is a versatile command-line tool that can be used for various tasks, including Android testing. Here are some of the most common ADB commands for Android testing:

  1. Install an APK file: adb install path/to/apk/file.apk
  2. Uninstall an app: adb uninstall package.name
  3. Clear an app's data: adb shell pm clear package.name
  4. Launch an app: adb shell am start -n package.name/activity.name
  5. Stop an app: adb shell am force-stop package.name
  6. Capture a screenshot:
adb shell screencap -p /sdcard/screenshot.png
adb pull /sdcard/screenshot.png path/to/local/directory
  1. Record a screen video:
adb shell screenrecord /sdcard/video.mp4
adb pull /sdcard/video.mp4 path/to/local/directory
  1. Grant a persmission to an app: adb shell pm grant package.name permission
  2. Revoke a permission to an app: adb shell pm revoke package.name permission
  3. Get a list of connected devices: adb devices
  4. Get logs from a device: adb logcat
  5. Reboot a device: adb reboot

These are just a few of the many ADB commands available for Android testing. To learn more, you can check out the official ADB documentation.

Example of a Bug Report?

Title: Unable to Submit Contact Form

Description: I am unable to submit the contact form on the website. Whenever I fill in the form fields and click the submit button, nothing happens. I have tried submitting the form multiple times, but the same issue persists.

Steps to Reproduce:

  1. Go to the Contact page on the website.
  2. Fill in the form fields with valid information.
  3. Click on the "Submit" button.

Expected Result: The form should be submitted successfully and a confirmation message should be displayed.

Actual Result: Nothing happens after clicking the "Submit" button.

Browser and Device Information:

Browser: Google Chrome Version 96.0.4664.110
Operating System: Windows 10

Additional Information: I have tried clearing my browser cache and cookies, but it did not resolve the issue. I also tried using a different browser, Microsoft Edge, but the same issue occurred.


Profile picture

Written by Dmitry Yarygin Test Engineer and a Digital Nomad.
Follow me on Medium
Personal WebSite

© 2023 Dmitry Yarygin