Turn your manual testers into automation experts Request a DemoStart testRigor Free

Lift Framework Testing

Lift Framework Testing

Lift is an open-source web framework that utilizes the Scala programming language. The Lift framework illustrates how secure, responsive, real-time applications can be developed. Considered as one of the most powerful and secure web frameworks available today, Lift allows for the creation of high-performing applications. Since Lift applications are written in Scala—an elegant, statically typed language that operates on the Java Virtual Machine (JVM)—Java libraries can be utilized and deployed to the servlet container and application server. Lift provides an expressive framework for writing web applications, predominantly modeled on the “View First” approach to web page development, inspired by the Wicket framework. Overall, Lift offers a high-performance, scalable web framework, capable of supporting a greater number of concurrent requests than what is typically possible with a thread-per-request server.

Unit testing

Unit tests focus on verifying the functionality of discrete components within an application's source code. This includes examining individual methods and functions of the classes, components, or modules used by the software. These tests are particularly conducive to automation and can be swiftly executed by a continuous integration server, ensuring consistent software quality.

Scala Unit Testing

Scala unit testing is a widely-used approach for validating Scala projects. In this type of testing, the codebase is scrutinized through Assertions and Matchers to verify the functionality of the individual units of code. As Scala language incorporates features of both functional programming and object-oriented programming, Scala Unit Testing effectively increases productivity. It facilitates simple and transparent tests, as well as executable specifications, which enhance both code quality and communication within the development team.

Here is a sample Scala unit test:
import org.scalatest._
import org.scalatest.matchers.should._
import org.scalatestplus.mockito.MockitoSugar
import net.liftweb.common.Full
 
class MyControllerSpec extends FlatSpec with Matchers with MockitoSugar {
  "MyController" should "return 200 status code for GET requests to /welcome" in {
    val controller = new MyController
    val request = mock[Req]
    request.method returns "GET"
    request.path returns "/welcome"
    val response = controller.welcome(request)
    response.code shouldEqual 200
  }
  
  it should "return a welcome message for GET requests to /welcome" in {
    val controller = new MyController
    val request = mock[Req]
    request.method returns "GET"
    request.path returns "/welcome"
    val response = controller.welcome(request)
    response.body shouldEqual Full("welcome, Peter!")
  }
 
  it should "return a 404 status code for GET requests to unknown paths" in {
    val controller = new MyController
    val request = mock[Req]
    request.method returns "GET"
    request.path returns "/unknown"
    val response = controller.handleNotFound(request)
    response.code shouldBe 404
  }
}

In the provided Scala unit test, the 'shouldEqual' assertion is employed to validate the response code and response body of GET requests to the '/welcome' endpoint. The 'shouldBe' assertion is used to confirm the response code of a GET request to an unrecognized endpoint. These checks ensure that the application is handling incoming requests as expected, providing quick feedback to developers about the correctness of their code.

Integration testing

Integration testing is when multiple modules or components of a software system are combined and tested as a group. The aim is to identify issues that might arise when these components interact with each other, such as during data exchange, adherence to communication protocols, or interdependencies. Integration testing can reveal design or implementation flaws in the system that may lead to bugs, security vulnerabilities, or performance issues.

How to conduct Integration testing?

Within the Lift framework, integration testing can be executed at different layers including the API layer, Database layer, and UI layer. Several tools and technologies, such as Mockito and Specs, can be used to facilitate this:

Mockito

Mockito is an open-source framework that aids in the generation and configuration of mock objects for testing. It uses two main types of stubs, known as "mocks" and "spies", for conducting integration testing. Mockito allows you to create a mock that can be programmed to behave in certain ways when specific methods are invoked, substituting the actual object in the test scenario. Additionally, you can create a spy which requires an actual object instance for it to spy on.

Specs

Specs is a behavior-driven testing framework for Scala that can be employed for integration testing. It uses Fluent syntax, designed to harness the expressive power of natural language, making tests simple and readable. Specs provides built-in support for mocking and stubbing, which are key for implementing integration tests.

Here is a sample integration test:
import org.scalatest.time.SpanSugar._
import org.scalawebtest.integration.ScalaWebTestBaseSpec
import scala.language.postfixOps

class EnforceNavigateTo extends ScalaWebTestBaseSpec{
  path = "/simpleAjax.jsp"
  config.enableJavaScript(throwOnError = true)
  config.enforceReloadOnNavigateTo()
  
  "A simple webpage loading content with JS" should "be correctly interpreted by HtmlUnit" in {
    eventually(timeout(3 seconds)) {
      container.text should include("Text loaded with JavaScript")
    }
  }
  
  it should "not be immediately available, if page was reloaded" in {
    container.text should not include "Text loaded with JavaScript"
  }
  
  def container: Element = {
    find(cssSelector("div#container")).get
  }
}

In this example, the EnforceNavigateTo class extends ScalaWebTestBaseSpec, a base class that provides common setup and teardown methods for the test suite. The path variable is set to '/simpleAjax.jsp', which is the URL of the webpage to be tested. The first test block ensures that the content loaded with JavaScript becomes available on the page, employing the eventually method with a timeout of 3 seconds. The assertion container.text should include("Text loaded with JavaScript") verifies that the specified text is present in the webpage's content. The second test block checks that the content isn't immediately available if the page is reloaded. The container.text should not include('Text loaded with JavaScript') assertion verifies the absence of the specified text in the webpage's content following a page reload. This type of testing is instrumental in ensuring correct behavior under various operational conditions.

End To End Testing

End-to-end testing (E2E testing), or system testing, is a comprehensive testing methodology that assesses the entirety of an application's flow—from start to finish—to ensure that the software functions correctly under real-world scenarios. E2E testing approaches the software from the user's perspective, emulating actual user interactions while considering elements such as the user interface, backend services, databases, and network communications. The primary objective of E2E testing is to validate the overall performance of the software system, which includes its functionality, reliability, performance, and security.

How to conduct E2E testing for Lift Framework testing?

Selenium:

Selenium is a free and open-source software that enables the automation of web applications. It offers a unified platform that enables the creation of test scripts using various programming languages, such as Ruby, Java, NodeJS, PHP, Perl, Python, and C#, among others. Selenium might still be a great option if you're strictly looking for open-source tools, however, be prepared to invest your time heavily and bear hidden costs associated with the tool usage. It's complicated and very time-consuming to build tests the right way, and not everyone can get it done since strong coding skills are required.

ScalaTest:

ScalaTest is a versatile testing framework for E2E testing. It supports an array of features such as matchers, assertions, fixtures, mocking, and stubbing, which are essential for comprehensive testing. Moreover, ScalaTest supports multiple testing styles like WordSpec and FeatureSpec, which are particularly apt for E2E testing.

testRigor:

testRigor is a cloud-based test automation tool that leverages advanced artificial intelligence and ML algorithms to create and execute test scenarios for web applications. Distinguishing features of testRigor include no-code test authoring, extremely low maintenance, fast and ultra-stable test execution, and ease of integration with various tools.

It is the simplest way to cover your entire application with end-to-end tests, while empowering anyone on the team to contribute. These tests, conducted entirely from a user's perspective and disregarding implementation details, provide the most accurate representation of software quality.

Below is an example test of a “Good Health” application:
click "GOOD HEALTH APP"
click "GOT IT!"
scroll down until page contains "NUTRITION LEVEL"
check that page contains "PROTEIN-55%"
check that page contains "FATS-25%"
check that page contains "CARBOHYDRATE-66%"
click on the 6th element by image from stored value "logo" with less than "10" % discrepancy

How to do End-to-end Testing with testRigor

Let us take the example of an e-commerce website that sells plants and other gardening needs. We will create end-to-end test cases in testRigor using plain English test steps.

Step 1: Log in to your testRigor app with your credentials.

Step 2: Set up the test suite for the website testing by providing the information below:

  • Test Suite Name: Provide a relevant and self-explanatory name.
  • Type of testing: Select from the following options: Desktop Web Testing, Mobile Web Testing, Native and Hybrid Mobile, based on your test requirements.
  • URL to run test on: Provide the application URL that you want to test.
  • Testing credentials for your web/mobile app to test functionality which requires user to login: You can provide the app’s user login credentials here and need not write them separately in the test steps then. The login functionality will be taken care of automatically using the keyword login.
  • OS and Browser: Choose the OS Browser combination on which you want to run the test cases.
  • Number of test cases to generate using AI: If you wish, you can choose to generate test cases based on the App Description text, which works on generative AI.

Step 3: Click Create Test Suite.

On the next screen, you can let AI generate the test case based on the App Description you provided during the Test Suite creation. However, for now, select do not generate any test, since we will write the test steps ourselves.

Step 4: To create a new custom test case yourself, click Add Custom Test Case.

Step 5: Provide the test case Description and start adding the test steps.

For the application under test, i.e., e-commerce website, we will perform below test steps:

  • Search for a product
  • Add it to the cart
  • Verify that the product is present in the cart

Test Case: Search and Add to Cart

Step 1: We will add test steps on the test case editor screen one by one.

testRigor automatically navigates to the website URL you provided during the Test Suite creation. There is no need to use any separate function for it. Here is the website homepage, which we intend to test.

First, we want to search for a product in the search box. Unlike traditional testing tools, you can identify the UI element using the text you see on the screen. You need not use any CSS/XPath identifiers.

For this search box, we see the text “What are you looking for?” So, to activate the search box, we will use the exact text in the first test step using plain English:
click "What are you looking for?"

Step 2: Once the cursor is in the search box, we will type the product name (lily), and press enter to start the search.

type "lily"
enter enter

Search lists all products with the “lily” keyword on the webpage.

Step 3: The lily plant we are searching for needs the screen to be scrolled; for that testRigor provides a command. Scroll down until the product is present on the screen:

scroll down until page contains "Zephyranthes Lily, Rain Lily (Red)"

When the product is found on the screen, testRigor stops scrolling.

Step 4: Click on the product name to view the details:

click "Zephyranthes Lily, Rain Lily (Red)"

After the click, the product details are displayed on the screen as below, with the default Quantity as 1.

Step 5: Lets say, we want to change the Quantity to 3, so here we use the testRigor command to select from a list.

select "3" from "Quantity"
After choosing the correct Quantity, add the product to the cart.
click "Add to cart"

The product is successfully added to the cart, and the “Added to your cart:” message is displayed on webpage.

Step 6: To assert that the message is successfully displayed, use a simple assertion command as below:

check that page contains "Added to your cart:"

Step 7: After this check, we will view the contents of the cart by clicking View cart as below:

click "View cart"

Step 8: Now we will again check that the product is present in the cart, under heading “Your cart” using the below assertion. With testRigor, it is really easy to specify the location of an element on the screen.

check that page contains "Zephyranthes Lily, Rain Lily (Red)" under "Your cart"

Complete Test Case

Here is how the complete test case will look in the testRigor app. The test steps are simple in plain English, enabling everyone in your team to write and execute them.

Click Add and Run.

Execution Results

Once the test is executed, you can view the execution details, such as execution status, time spent in execution, screenshots, error messages, logs, video recordings of the test execution, etc. In case of any failure, there are logs and error text that are available easily in a few clicks.

You can also download the complete execution with steps and screenshots in PDF or Word format through the View Execution option.

testRigor’s Capabilities

Apart from the simplistic test case design and execution, there are some advanced features that help you test your application using simple English commands.

  • Reusable Rules (Subroutines): You can easily create functions for the test steps that you use repeatedly. You can use the Reusable Rules to create such functions and call them in test cases by simply writing their names. See the example of Reusable Rules.
  • Global Variables and Data Sets: You can import data from external files or create your own global variables and data sets in testRigor to use them in data-driven testing.
  • 2FA, QR Code, and Captcha Resolution: testRigor easily manages the 2FA, QR Code, and Captcha resolution through its simple English commands.
  • Email, Phone Call, and SMS Testing: Use simple English commands to test the email, phone calls, and SMS. These commands are useful for validating 2FA scenarios, with OTPs and authentication codes being sent to email, phone calls, or via phone text.
  • File Upload/ Download Testing: Execute the test steps involving file download or file upload without the requirement of any third-party software. You can also validate the contents of the files using testRigor’s simple English commands.
  • Database Testing: Execute database queries and validate the results fetched.

testRigor enables you to test web, mobile (hybrid, native), API, and desktop apps with minimum effort and maintenance.

Additional Resources

Conclusion

In conclusion, the right selection of technologies and tools can create a robust and efficient testing framework that greatly enhances the quality of software applications. Implementing such a framework can help maximize return on investment (ROI), ensure high-quality deliverables, and provide the best possible user experience. Whether you choose Selenium for its wide range of language support, ScalaTest for its flexibility, or testRigor for its AI-driven automation, your choice should align with your project's specific requirements and the technical proficiency of your team.

Join the next wave of functional testing now.
A testRigor specialist will walk you through our platform with a custom demo.