Currently Browsing

JUnit

Setting up Allure (Part 1)

What is allure?

 

Allure is a flexible test report framework that not only shows a very concise representation of what have been tested in a neat web report form, but allows everyone participating in the development process to extract maximum of useful information from everyday execution of tests, with the possibility to add screenshots, logs, attachments and so on.

 

In order to get results, you need to:

  • • Add AllureRunListener to Junit
  • • Add AspectJ Weaver and respective properties
  • • Run test

 

Maven installation

Cucumber in Web testing (part 8 of 8)

8. Keyword “Examples” and conclusion

 

Gherkin keyword: Examples

Cucumber provides another useful Gherkin keyword which is used scenario parametrization. A scenario with an “Example” keyword will be executed multiple times with different parameters. Here is an instance:

@init @logout
  Scenario Outline: Successful Login with Valid Credentials
    Given User is on Home Page
    When User Navigate to LogIn Page
    And User enters username "<userName>"
    And User enters password "<password>"
    And Click login
    Then Message displayed Login Successfully

 
Examples:
| userName | password |
| username1 | password 1 |
| invalid | invalid |

Cucumber in Web testing (part 7 of 8)

7. Hooks

 

Cucumber provides a methodology called Hooks which is analogue to traditional before and after methods. The hooks must be annotated with @Before and @After in step classes. Make sure to use cucumber.api.java.Before and cucumber.api.java.After annotations and not the JUnit ones. By default each before method will be executed before all scenarios and each after method will be executed after all scenarios. If a hook needs to be executed only for a particular scenario, then we need to use tags. To tag a before method, we need to insert a string parameter to the annotation. To bind the tagged hook to a particular scenario we need to “annotate” the scenario with the same string tag. Here is an example:

@Before("@login")
	public void login() throws Throwable{
		openDriver();
		System.out.println("login()");
		testSteps.user_is_on_Home_Page();
		testSteps.user_Navigate_to_LogIn_Page();
		testSteps.user_enters_UserName("Tester843");
		testSteps.user_enters_Password("x%kzJwbsW1)AIB2k");
		testSteps.click_login();
		testSteps.message_displayed_Login_Successfully();
	}
@After("@close")
	public void close_driver() throws Throwable {
		System.out.println("close_driver()");
		baseObject.driver.close();
	}

@login @close
 Scenario: Successful LogOut
    When User LogOut from the Application
    Then Message displayed LogOut Successfully

Cucumber in Web testing (part 5 of 8)

5. Web testing project structure

 

Structure without cucumber

The following picture represents our basic structure what we use for web testing:

 
TestBase contains the initialization and termination of a Selenium Webdriver. It usually contains a before() and after() method where we start and close web browser. In addition to this we setting up desired capabilities if needed.
 

Cucumber in Web testing (part 4 of 8)

4. TestRunner and Test steps

To run features we need a Java class to start the test run. Here is a simple example:

package cucumberTest;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
features = "Feature",
dryRun = true
)

public class TestRunner {

}

The TestRunner class needs to be annotated with @RunWith(Cucumber.class) and a body of it can be totally empty. By annotating the class with @CucumberOptions we can specify extra options to our test run. In this case, we used the annotation to specify the location of the feature file and to set the test run to ‘dry’. Running the test in ‘dry’ mode means that cucumber will not execute the test steps, rather it will just check for test steps implementations. For the previously given feature, we got this output on the console.

Cucumber in Web testing (part 2 of 8)

2. How to install cucumber in Eclipse

To start using cucumber in eclipse we need to install few things:

  1. First of all eclipse and Java Development Kit (JDK) need to be installed on the computer.
  2. Ones eclipse finished with the installation we are able to install “Cucumber Eclipse Plugin” with eclipse built-in plugin installation tool. Step by step instructions can be found here.
  3. Download cucumber libraries. Multiple solution can be found here. We recommend to use Maven to download and manage all dependencies.

Our pom.xml contains the following dependencies:

Amazon web services – Device Farm

Device Farm is an app testing service that enables you to test your Android, iOS, and Fire OS apps on real, physical phones and tablets that are hosted by Amazon Web Services (AWS). Currently Device Farm allows you to run your own tests or built-in compatibility tests parallelly on the selected devices. The list below contains the test types on various platforms (from amazon.com):

Basic tutorial to setup a new project and test run

Once you are signed in, go to Amazon Console and click on Device Farm. Click on the Create New Project button and enter desired name for your project. Click on a newly created project and you will be automatically redirected to “Create new run” page. Upload your application what you want to test and click on the “Next step” to choose your test run type.

Change iOS Settings on virtual device with Appium

In our previous post we introduced the steps to set up your Appium environment for iOS 9 devices. In this post we will write about how can you open the Settings app and do some changes in it. We will use Java as programming language, Eclipse for IDE and JUnit as runner.

Ok, so first step is to get the Java client of Selenium from www.seleniumhq.org/download/. Extract the downloaded *.zip file, create a new Java Project in Eclipse and add all extracted *.jar files to Build Path. Now, we can start to implement our first test case for iOS device where we will open the Settings app and disable the Location Service on iPhone. As we mentioned above, we will use JUnit as runner, but you can also choose TestNG or just create a standard Java program with the main() function.

Let’s create a before() method with annotation @Before where we will set up all of the necessary things for the desired test case.

Setting up Appium on Mac OS X for iOS virtual devices to test your application

In this post we will introduce the basic setup of Appium to work with iOS devices. We will go through with detailed steps, so you can skip some of those if you are familiar with.

For start you need to install Xcode. Go to the App Store, type Xcode, hit the download button and grab a coffee, it will take some time. Next step is to install Xcode command line tools. Open your default terminal application (Terminal, iTerm, etc.) and enter xcode-select –install. Click on Install button on the presented popup.
Xcode-Select modal
Agree the fine print, wait for the components to be installed and click on Done. Don’t forget to accept the license and agreements of Xcode. Simply start Xcode, accept the licenses and wait for the components to be installed. Now we are able to start our iPhone/iPad simulator so if you want to try it out, switch to your Xcode and choose Xcode/Open Developer Tool/Simulator. The downside is that you will have just iOS 9 installed, and you can’t change it to the older version. Next chapter is to install Appium and required packages.

Quick and dirty test parametrization – JUnit params

Today I want to talk about a little tool which makes the life of us testers a bit easier.
It is called Junit params.

The  following situation happened with me not so long ago:
The dev team lead asked us a favor to make a set of quick and dirty smoke tests which tests different sites and check if some elements are present.
There are of course different approaches, if we are lucky the function is already automated and documented somewhere, and we just have to make it accessible and runnable by others too.