About Autonium
- Autonium is a test automation framework for web applications.
- This framework is built by using Java and Selenium.
- It uses Maven project structure.
- Easy to understand and use it.
- Having basic idea on Java, Selenium, Maven and TestNG is good enough to start with Autonium.
- Let’s start Automation with Autonium
---------------------------------------------------
Advantages
- Provides support to all major browsers – Firefox, Chrome, IE and Safari.
- Capability of executing scripts on Remote Machines by using Selenium Server.
- Users can make use of Selenium Web driver methods and Autonium methods.
- Autonium simplifies Test data management. Test data can be read from properties files.
- Scripts can be developed without hard coding test data .
- Identifiers can also be read from properties files and hard coding of identifiers can be avoided.
- Test data and Identifier values are stored in the form of key/value pairs in properties file.
- Detailed Test case report with Pass/Fail status will be generated for all test runs.
- Autonium provides single wrappers for common methods like Find Element, Drop down selection and Wait.
- No more dependency on multiple methods for drop down selection, finding elements and explicit waits on webpage etc.
Selenium Web driver code:
//Creating driver
WebDriver driver = new FirefoxDriver();
//Finding Element
driver.findElement(By.id("continents"));
driver.findElement(By.xpath("//select[@class='cardNumber']"));
//Selecting from drop down
WebElement webElement = driver.findElement(By.id("dropdown"));
Select se = new Select(webElement);
se.selectByIndex(2);
//Explicit Wait
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("continents")));
Autonium code:
//Creating driver
Autonium driver = new Autonium();
//Finding Element
driver.findElement("id:continents");
driver.findElement("xpath://select[@class='cardNumber']");
//Selecting from drop down
driver.selectFromDropDown("id:dropdown","index:4");
//Explicit Wait
driver.waitForElementPresence("id:continents", 60);
-----------------------------------------------------
Pre-Requisites
- Basic knowledge on Java, Selenium, Maven and TestNG
- Download and Install Java
- Download Maven and Install Maven
- Download and Install eclipse – you can use other IDE’s like IntelliJ IDEA
----------------------------------------------------
Setup
- Make sure Java, Maven variables are added to path.
- Open eclipse, create a Maven Project – help
- After creating Maven project, folder structure looks as shown in image below
- Open pom.xml and add dependency for Autonium, Selenium and TestNG
- Selenium
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.53.0</version> </dependency>
- TestNG
<dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.9.8</version> <scope>test</scope> </dependency>
- Autonium
<dependency> <groupId>org.selenium</groupId> <artifactId>autonium</artifactId> <version>1.1</version> </dependency> <!--Add below repository dependencies to fetch Autonium jar from bintray. We will soon move project to Maven central. --> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>bintray-autonium-maven</id> <name>bintray</name> <url>http://dl.bintray.com/autonium/maven</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <snapshots> <enabled>false</enabled> </snapshots> <id>bintray-autonium-maven</id> <name>bintray-plugins</name> <url>http://dl.bintray.com/autonium/maven</url> </pluginRepository> </pluginRepositories>
- Selenium
- Create config.properties file in resources folder
- Create testdata and identifiers folders in resources folder
- Rename src/test/java folder to src/test/xml. Then remove the package and java file present in src/test/xml folder
- This finishes the setup for Autonium and you are ready to write Test cases. We will see how to write test cases in the following tutorials.
---------------------------------------------------------------------------------------------------------
Properties Files
Autonium uses properties files to maintain test data, identifiers and configuration.
- Configuration properties file name should be config.properties
- There is no restriction with file name for test data and identifiers files.
- Test project can have any number of test data and identifier properties files but it should have only one config.properties file.
- Now we shall see how to use these properties file
- Config Properties
- TestData Properties
- Identifiers Properties
Config Properties
- Create config file under Resources folder and this file is mandatory to run test scripts.
- Config file should be named as “config.properties”
- Values can be entered in config file as mentioned below.
BASE_URL = https://bitbucket.org/ Environment = q1 Browser = SeleniumServer = SeleniumPort =
- BASE_URL, Environment, Browser, SeleniumServer and SeleniumPort are default fields for config.properties file.
- Variables in config.properties are case sensitive.
- We cannot run tests without these fields in config file. Except BASE_URL all fields can be empty.
- BASE_URL is mandatory and value should be provided in config file.
- Accepted Browser values
FIREFOX - firefox or ff GOOGLE CHROME - chrome or googlechrome or gc INTERNET EXPLORER - ie or iehta or internetexplorer or iexplore SAFARI - safari
- Default browser will be Firefox (if Browser value is not given in config file)
- Environment value is used to get test data from properties files in testdata folder.
- SeleniumServer is an IP Address or Host Name of remote machine where test scripts can be executed (Selenium Stand alone server should be running on remote machine).
- SeleniumPort is port on which selenium server is running. If Selenium Port is not provided by default it will be set to 4444.
TestData Properties
- Create Test data folder under resources folder in your project. Name should be “testdata”.
- Test data folder is not required to run scripts unless the data is read from test data files.
- To store any test data create a .properties file and save key/value pairs in test data file.
- Test data file name should be <environment>.properties
- Sample Test data file names:
q1.properties q2.properties staging.properties live.properties
- Syntax for test data values in q1.properties file:
username = admin password = admin
- To read value from Test data use the following method:
public String getTestData(String propertyName) { .... }
- This method returns parameter value as String from <environment>.properties test data file.
driver.getTestData("username");
- When above method is called, username value from q1.properties file will be returned.
- Test case will fail with respective error message if file is not found or property not listed in test data file.
Identifiers Properties
- Create a “identifiers” folder under resources directory to maintain files for storing Identifier values.
- Identifiers folder is not mandatory to run scripts unless identifier values are read from identifier files.
- Create a .properties file and store key/value pairs for identifiers.
- Syntax for values in identifiers file is given below:
loginLink = //a[text()='Log In'] searchButton = id:search
- To read values from Identifiers file use following method:
public String getIdentifierData(String fileName, String propertyName) { ... }
- Above method returns value of identifier from file based on argument passed to it.
driver.getIdentifierData("homepage", "loginLink");
- After calling above method, loginLink value from homepage.properties file in identifiers folder will be returned.
- Appropriate error will be shown while trying to read values from identifier file which does not exist.
------------------------------------------------------------------------------------------------
Writing Scripts
- Import Autonium class.
- Import TestNG classes.
- Instantiate Autonium object.
- Write Test Cases.
Sample code to search for “Selenium” on Google:
//importing Autonium class
import org.selenium.autonium.Autonium;
//importing testng classes
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
public class App
{
//Declaring Autonium object
Autonium driver;
//Test Case
@Test
public void v()
{
//Initializing Autonium object
driver = new Autonium();
//Calling Webdriver Method using Autonium Object
driver.autoniumDriver.get("http://www.google.com");
driver.autoniumDriver.manage().window().maximize();
//autonium Wrapper method
driver.findElement("name:q").sendKeys("Selenium");
driver.findElement("//button[@value='Search']/span").click();
}
@AfterClass
public void closeDriver() {
driver.autoniumDriver.quit();
}
}
---------------------------------------------------
Autonium Methods
Below are Autonium Methods which will help in automating tests easily.
- Get Test Data
- Get Identifier Data
- Find Element
- Find Elements
- Select From Drop Down
- Deselect From Drop Down
- Wait For Element Presence
- Wait For Element Visible
- Get Http Status Code
Get Test Data
- This method returns value of given property (key) from environment file present in “src/main/resources/testdata” folder.
- Fails the test case if File not present in testdata folder or Property not present in file.
- Method Signature
public String getTestData(String propertyName) { ... }
- For more details click here
Get Identifier Data
- This method returns value of given property (key) from given identifiers file present in “src/main/resources/identifiers” folder.
- Fails the test case if File not present in Identifiers folder or Property not present in file.
- Method Signature
public String getIdentifierData(String fileName, String propertyName) { ... }
- For more details click here
Find Element
- This method returns corresponding WebElement for the identifier passed as an argument.
- Fails the test case if element not found.
- Method Signature
public WebElement findElement(String identifier){ ... }
- Allowed arguments for this method are :
id: Element Id cn: Element Class Name css: Element CSS Selector name: Element name lt: Element Link Text plt: Element Partial Link Text tname: Element Tag Name xpath: Element XPath can be directly used without preceding it with "xpath:"
- Method usage with allowed arguments:
//To find element based on Id driver.findElement("id:username"); //To find element based on xpath driver.findElement("//input[@id='username']"); driver.findElement("xpath://input[@id='username']"); //To find element based on Class Name driver.findElement("cn:login"); //To find element based on CSS Selector driver.findElement("css:#username"); //To find element based on Name Attribute driver.findElement("name:login"); //To find element based on Link Text driver.findElement("lt:Login Link"); //To find element based on Partial Link Text driver.findElement("plt:Login"); //To find element based on Tag Name driver.findElement("tname:a");
Find Elements
- This method returns list of WebElements related to the identifier passed as an argument.
- Fails the test case if element not found.
- Method Signature
public List <WebElement> findElements(String identifier) { ... }
- Allowed arguments for this method are :
id: Element Id cn: Element Class Name css: Element CSS Selector name: Element name lt: Element Link Text plt: Element Partial Link Text tname: Element Tag Name xpath: Element XPath can be directly used without preceding it with "xpath:"
- Method usage with allowed arguments:
//To get elements list based on Id driver.findElements("id:username"); //To get elements list based on xpath driver.findElements("//input[@id='username']"); driver.findElement("xpath://input[@id='username']"); //To get elements list based on Class Name driver.findElements("cn:login"); //To get elements list based on CSS Selector driver.findElements("css:#username"); //To get elements list based on Name Attribute driver.findElements("name:login"); //To get elements list based on Link Text driver.findElements("lt:Login Link"); //To get elements list based on Partial Link Text driver.findElements("plt:Login"); //To get elements list based on Tag Name driver.findElements("tname:a");
Select From Drop Down
- This method selects value from drop down based on index/value/visible text.
- Fails the test case if element or SelectValue is not found
- Method Signature
public void selectFromDropDown(String identifier, String selectValue) { ... }
- Allowed arguments for identifier are same as for Find Element method.
- Allowed arguments for selectValue are :
value: Value to be selected from drop down vtext: Visible text to be selected from drop down index: Index to be selected from drop down
- Method usage with allowed arguments
//To select from drop down based on index driver.selectFromDropDown("id:continents","index:1"); //To select from drop down based on value driver.selectFromDropDown("id:continents","value:Asia"); //To select from drop down based on visible text driver.selectFromDropDown("id:continents","vtext:Europe");
Deselect From Drop Down
- This method deselects value from drop down based on index/value/visible text.
- Fails the test case if element or DeSelectValue is not found
- Method Signature
public void deSelectFromDropDown(String identifier, String deSelectValue){ ... }
- Allowed arguments for identifier are same as for Find Element method.
- Allowed arguments for deSelectValue are :
value: Value to be deselected from select vtext: Visible text to be deselected from select index: Index to be deselected from select
- Method usage with allowed arguments
//To deselect from select based on index driver.deSelectFromDropDown("id:continents","index:1"); //To deselect from select based on value driver.deSelectFromDropDown("id:continents","value:Asia"); //To deselect from select based on visible text driver.deSelectFromDropDown("id:continents","vtext:Europe");
Wait For Element Presence
- Waits until element specified with identifier appears on current page.
- Fails if timeout expires before the element appears.
- Method signature
public void waitForElementPresence(String identifier, int timeOutInSeconds) { ... }
- Allowed arguments for identifier are same as for Find Element method.
- timeOutInSeconds is integer value.
- Method usage with allowed arguments
//Waits 60 seconds for "continents" on web page driver.waitForElementPresence("id:continents", 60);
Wait For Element Visible
- Waits until element specified with identifier is visible.
- Fails if timeout expires before the element is visible.
- Method signature
public void waitForElementVisible(String identifier, int timeOutInSeconds) { ... }
- Allowed arguments for identifier are same as for Find Element method.
- timeOutInSeconds is integer value.
- Method usage with allowed arguments
//Waits 60 seconds for "continents" visibility on web page driver.waitForElementVisible("id:continents", 60);
Get Http Status code
- Fetches Http/Https status code for the required request.
- Fails if the URL is not provided correctly or URL cannot be reached.
- Method signature
public int getHttpStatusCode(String urlString){ ... }
- Allowed values for urlString are
https://autonium.wordpress.com http://www.seleniumhq.org/
- Method usage with allowed arguments
//Returns Http status code for given urlString driver.getHttpStatusCode("https://autonium.wordpress.com");
------------------------------------------------------------------------------------------------------------------------------
Running Scripts
- Create a XML file in src/test/xml folder
- Include the class to be executed in created xml file – Should use Qualified Class Name
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name = "sample"> <test name = "sample1"> <classes> <class name="org.autonium.qa.autonium_sample.App"/> </classes> </test> </suite>
- Add below code in your pom.xml
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <configuration> <suiteXmlFiles> <suiteXmlFile>src\test\xml\test.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> </plugins> </build>
Running Tests From Eclipse
- Right click on the pom.xml select Maven Install from Run As
Running Tests From Windows Command Prompt
- Open Command Prompt
- Navigate to Project Folder
- Running without arguments
mvn install
- Running with arguments
mvn install -DBrowser=gc mvn install -DSeleniumServer=127.0.0.1 [Use Remote Machine IP or Machine Name] mvn install -DSeleniumPort=4444 mvn install -DBASE_URL=http://www.google.com #Running with multiple arguments mvn install -DBrowser=ie -DSeleniumServer=127.0.0.1 -DBASE_URL=http://www.google.com
-----------------------------------------------------------------------------------------------------------------------------
Sample Project
You can find Sample project HERE.
- Download the Zip file and extract it.
- Open eclipse, from File menu select Import
- Select “Existing Maven Project” from menu
- Then provide path to extracted pom.xml and click finish
----------------------------------------------------------------------------------------------------------
@Andria BZ Thanks. Will update more information on this in future.
ReplyDeleteDo you mind if I quote a couple of your posts as long as I provide credit and sources back to your blog? My blog is in the same niche as yours, and my users would benefit from some of the information you provide here.
ReplyDeletenebosh course in chennai
Great job.... Awesome list, just starting a blog and this is going to be a massive help. Thank you!
ReplyDeleteSoftware Testing Training
QTP Training in Chennai
Selenium Training in Chennai
LoadRunner Training in Chennai
JMeter Training in Chennai
Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
ReplyDeleteAutomation anywhere Training in Chennai | Best Automation anywhere Training in Chennai
uipath training in chennai | Best uipath training in chennai
Blueprism Training in Chennai | Best Blueprism Training in Chennai
No Problem.Thanks a lot.
DeleteThanks.
ReplyDelete