Here we learn how to configure Graphene and create a simple test using it.
Step 1:
Create a simple maven project.
Step 2:
Add dependencies as below mentioned
Step 3:
Create a Page object class here we take a Google page for page object.
Step 4:
Create Test class which is extends Arquillian class. Here we create a simple test class for google search page.
Step 5:
Craete a testng.xml file.
Step 6:
Craete a arquillian.xml file to store all test related (Arquillian based) configuration.
Code Sample :
pom.xml file :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.automation.arquillian</groupId>
<artifactId>ArquillianTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.org.jboss.arquillian>1.4.0.Final</version.org.jboss.arquillian>
<version.org.jboss.arquillian.drone>2.5.1</version.org.jboss.arquillian.drone>
<version.org.jboss.arquillian.graphene>2.3.2</version.org.jboss.arquillian.graphene>
<version.screenshooter>2.1.0.CR1</version.screenshooter>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>graphene-webdriver</artifactId>
<version>${version.org.jboss.arquillian.graphene}</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
<artifactId>arquillian-testng-standalone</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- Arquillian Core dependencies -->
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${version.org.jboss.arquillian}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Arquillian Selenium dependencies -->
<dependency>
<groupId>org.jboss.arquillian.selenium</groupId>
<artifactId>selenium-bom</artifactId>
<version>3.12.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Arquillian Drone dependencies and WebDriver/Selenium dependencies -->
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-drone-bom</artifactId>
<version>${version.org.jboss.arquillian.drone}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Page Object Class :
package com.automation.pages;
import java.util.List;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
public class GooglePage {
@Drone
private WebDriver driver;
@FindBy(name = "q")
private WebElement searchBox;
@FindBy(css = "input[value='Google Search']")
private WebElement searchbutton;
@FindBy(css = "div.rc")
private List<WebElement> results;
public void searchFor(String searchQuery) {
// Search
searchBox.sendKeys(searchQuery);
Wait<WebDriver> wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(searchbutton));
searchbutton.sendKeys(Keys.ENTER);
wait.until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver input) {
return results.size()>0;
}
});
System.out.println("Result count:" + results.size());
}
}
Data Provider Class :
package com.automation.dataprovider;
import org.testng.annotations.DataProvider;
public class TestDataProviders {
@DataProvider(name = "googleSearch")
public static Object[][] voiceSearchTestData() {
return new Object[][] {
{"Arquillian"},
{"Graphene"},
{"Arquillian Graphene"},
{"Drone"},
{"Arquillian Drone"}
};
}
}
Test Class :
package com.automation.tests;
import java.net.URL;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.graphene.page.Page;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.arquillian.testng.Arquillian;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.automation.dataprovider.TestDataProviders;
import com.automation.pages.GooglePage;
@RunAsClient
public class GoogleTest extends Arquillian {
@Drone
private WebDriver driver;
@ArquillianResource
private URL contextRoot;
@Page
GooglePage googlePage;
@BeforeMethod
public void init() {
driver.get(contextRoot.toString());
driver.manage().window().maximize();
}
@Test(dataProviderClass=TestDataProviders.class,dataProvider="googleSearch")
public void googleSearchTest(String searchText) {
System.out.println(contextRoot);
googlePage.searchFor(searchText);
}
}
arquillian.xml
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.com/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<extension qualifier="webdriver">
<property name="browser">chrome</property>
</extension>
<extension qualifier="graphene">
<property name="url">https://www.google.com/</property>
</extension>
</arquillian>
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="com.ibm.automation.tests.GoogleTest"/>
</classes>
</test>
</suite>
Project Structure :
Step 1:
Create a simple maven project.
Step 2:
Add dependencies as below mentioned
- graphene-webdriver
- testng
- arquillian-testng-standalone
- arquillian-bom
- selenium-bom
- arquillian-drone-bom
Step 3:
Create a Page object class here we take a Google page for page object.
Step 4:
Create Test class which is extends Arquillian class. Here we create a simple test class for google search page.
Step 5:
Craete a testng.xml file.
Step 6:
Craete a arquillian.xml file to store all test related (Arquillian based) configuration.
Code Sample :
pom.xml file :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.automation.arquillian</groupId>
<artifactId>ArquillianTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.org.jboss.arquillian>1.4.0.Final</version.org.jboss.arquillian>
<version.org.jboss.arquillian.drone>2.5.1</version.org.jboss.arquillian.drone>
<version.org.jboss.arquillian.graphene>2.3.2</version.org.jboss.arquillian.graphene>
<version.screenshooter>2.1.0.CR1</version.screenshooter>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>graphene-webdriver</artifactId>
<version>${version.org.jboss.arquillian.graphene}</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
<artifactId>arquillian-testng-standalone</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- Arquillian Core dependencies -->
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${version.org.jboss.arquillian}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Arquillian Selenium dependencies -->
<dependency>
<groupId>org.jboss.arquillian.selenium</groupId>
<artifactId>selenium-bom</artifactId>
<version>3.12.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Arquillian Drone dependencies and WebDriver/Selenium dependencies -->
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-drone-bom</artifactId>
<version>${version.org.jboss.arquillian.drone}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Page Object Class :
package com.automation.pages;
import java.util.List;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
public class GooglePage {
@Drone
private WebDriver driver;
@FindBy(name = "q")
private WebElement searchBox;
@FindBy(css = "input[value='Google Search']")
private WebElement searchbutton;
@FindBy(css = "div.rc")
private List<WebElement> results;
public void searchFor(String searchQuery) {
// Search
searchBox.sendKeys(searchQuery);
Wait<WebDriver> wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(searchbutton));
searchbutton.sendKeys(Keys.ENTER);
wait.until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver input) {
return results.size()>0;
}
});
System.out.println("Result count:" + results.size());
}
}
Data Provider Class :
package com.automation.dataprovider;
import org.testng.annotations.DataProvider;
public class TestDataProviders {
@DataProvider(name = "googleSearch")
public static Object[][] voiceSearchTestData() {
return new Object[][] {
{"Arquillian"},
{"Graphene"},
{"Arquillian Graphene"},
{"Drone"},
{"Arquillian Drone"}
};
}
}
Test Class :
package com.automation.tests;
import java.net.URL;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.graphene.page.Page;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.arquillian.testng.Arquillian;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.automation.dataprovider.TestDataProviders;
import com.automation.pages.GooglePage;
@RunAsClient
public class GoogleTest extends Arquillian {
@Drone
private WebDriver driver;
@ArquillianResource
private URL contextRoot;
@Page
GooglePage googlePage;
@BeforeMethod
public void init() {
driver.get(contextRoot.toString());
driver.manage().window().maximize();
}
@Test(dataProviderClass=TestDataProviders.class,dataProvider="googleSearch")
public void googleSearchTest(String searchText) {
System.out.println(contextRoot);
googlePage.searchFor(searchText);
}
}
arquillian.xml
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.com/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<extension qualifier="webdriver">
<property name="browser">chrome</property>
</extension>
<extension qualifier="graphene">
<property name="url">https://www.google.com/</property>
</extension>
</arquillian>
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="com.ibm.automation.tests.GoogleTest"/>
</classes>
</test>
</suite>
Project Structure :
thank you for providing such nice of article. i am glad to leave a comment except more articles in future. Selenium Training in Chennai
ReplyDeleteThank you for your information. It very nice article.
ReplyDeleteSelenium Training in Pune
Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
ReplyDeletesap training in chennai
sap training in velachery
azure training in chennai
azure training in velachery
cyber security course in chennai
cyber security course in velachery
ethical hacking course in chennai
ethical hacking course in velachery
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeletejava training in chennai
java training in annanagar
aws training in chennai
aws training in annanagar
python training in chennai
python training in annanagar
selenium training in chennai
selenium training in annanagar