A new test automation framework for the community FluentLenium in Java

A new test automation framework for the community FluentLenium in Java

In a recent article I covered the kick start test automation with FluentLenium which is a Java based Selenium wrapper. Test automation tool cannot be used alone, unless its used within a framework.

In this article I will be covering how we can use FluentLenium and develop a test automation framework surrounding it.

First of all I have added the following dependencies to my pom.xml file.

 <dependencies>
	        <dependency>
	            <groupId>org.fluentlenium</groupId>
	            <artifactId>fluentlenium-core</artifactId>
	            <version>3.4.1</version>
	        </dependency>
			<dependency>
			    <groupId>org.fluentlenium</groupId>
			    <artifactId>fluentlenium-testng</artifactId>
			    <version>4.0.0</version>
			</dependency>
			<dependency>
	    		 <groupId>io.qameta.allure</groupId>
	    		 <artifactId>allure-testng</artifactId>
	   			 <version>2.8.1</version>
			</dependency>
	        <dependency>
	            <groupId>org.fluentlenium</groupId>
	            <artifactId>fluentlenium-assertj</artifactId>
	            <version>3.4.1</version>
	        </dependency>
	        <dependency>
	            <groupId>org.seleniumhq.selenium</groupId>
	            <artifactId>selenium-chrome-driver</artifactId>
	            <version>3.14.0</version>
	        </dependency>
	        <dependency>
			    <groupId>com.googlecode.json-simple</groupId>
			    <artifactId>json-simple</artifactId>
			    <version>1.1.1</version>
			</dependency>
	    </dependencies>

Next I created the page objects for my FluentLenium framework.

Login Page Class -

package PageObject;
	

	import java.io.FileNotFoundException;
	import java.io.IOException;
	

	import org.fluentlenium.core.FluentPage;
	import org.fluentlenium.core.annotation.PageUrl;
	import org.fluentlenium.core.domain.FluentWebElement;
	import org.json.simple.parser.ParseException;
	import org.openqa.selenium.support.FindBy;
	import JSON.*;
	@PageUrl("https://demo.guru99.com/v4/")
	

	public class LoginPage extends FluentPage  {
	    JSONReader jsonRead = new JSONReader();
		@FindBy(name="uid")
	    private FluentWebElement userNameInput;
		
		@FindBy(name="password")
	    private FluentWebElement passwordInput;
		
		@FindBy(name="btnLogin")
	    private FluentWebElement loginButton;
		
		public void loginUI() throws FileNotFoundException, IOException, ParseException
		{
			goTo(jsonRead.readJSON("./Data/sel.json", "URL"));
			userNameInput.fill().with(jsonRead.readJSON("./Data/sel.json", "USER"));
			passwordInput.fill().with(jsonRead.readJSON("./Data/sel.json", "PASSWORD"));
			loginButton.click();
		}
	}

Main Page Class -

package PageObject;
	

	import org.fluentlenium.core.FluentPage;
	import org.fluentlenium.core.annotation.PageUrl;
	import org.fluentlenium.core.domain.FluentWebElement;
	import org.openqa.selenium.support.FindBy;
	

	public class MainPage extends FluentPage  {
	

		@FindBy(xpath="https://h2[@class='barone']")
	    private FluentWebElement heading;
	

		
		public String  getHeadingText()
		{
			
			return heading.text();
			
		}
	

	}

The next step I did is to create my own JSON reader method to add the data driven capability.

package JSON;
	import java.io.FileNotFoundException;
	import java.io.FileReader;
	import java.io.IOException;
	import org.json.simple.JSONObject;
	import org.json.simple.parser.JSONParser;
	import org.json.simple.parser.ParseException;
	

	public class JSONReader {
		JSONParser parser = new JSONParser();
		public String readJSON(String file, String tagName) throws FileNotFoundException, IOException, ParseException
		{
			 Object obj = parser.parse(new FileReader(file));
		      JSONObject jsonObject = (JSONObject) obj;
		      return (String) jsonObject.get(tagName);
			
		}
	

	}

For the reporting, I have integrated the Allure dashboard, which generated files for each test run in the allure results folder.

Finally I created my login test using the data driven and page object class methods.

package FluPkg;
	import static org.assertj.core.api.Assertions.assertThat;
	

	import java.io.FileNotFoundException;
	import java.io.IOException;
	import org.fluentlenium.adapter.testng.FluentTestNg;
	

	import org.fluentlenium.core.annotation.Page;
	import org.json.simple.parser.ParseException;
	//import org.junit.Test;
	import org.testng.*;
	import org.testng.annotations.Test;
	

	import PageObject.LoginPage;
	import PageObject.MainPage;
	

	public class FluBasic extends FluentTestNg {
		
		@Page
		LoginPage loginPage;
		@Page
		MainPage mainPage;
		
		 @Test
		    public void google_search() throws FileNotFoundException, IOException, ParseException {
			    loginPage.goTo(this.loginPage);
		        loginPage.loginUI();
		        assertThat(window().title()).contains("Guru99 Bank Manager HomePage");
		        assertThat(this.mainPage.getHeadingText().contains("Guru99 Bank") );
		     
		        
		    }
	}

Couple of hours we are done with the FluentLenium project.... Test automation is awesome.


要查看或添加评论,请登录

Kushan Shalindra Amarasiri的更多文章

社区洞察

其他会员也浏览了