Skip to main content

Autonium




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



----------------------------------------------------

Setup

  • Make sure JavaMaven variables are added to path.
  • Open eclipse, create a Maven Project – help
  • After creating Maven project, folder structure looks as shown in image below MavenProject
  • Open pom.xml and add dependency for AutoniumSelenium 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>
      
  • Create config.properties file in resources folder
    ConfigFile_Creation
  • Create testdata and identifiers folders in resources folder
    testdataandidentifiers_Folders
  • Rename src/test/java folder to src/test/xml. Then remove the package and java file present in src/test/xml folder
    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
    1. Config Properties
    2. TestData Properties
    3. 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


  1. Import Autonium class.
  2. Import TestNG classes.
  3. Instantiate Autonium object.
  4. 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.
  1. Get Test Data
  2. Get Identifier Data
  3. Find Element
  4. Find Elements
  5. Select From Drop Down
  6. Deselect From Drop Down
  7. Wait For Element Presence
  8. Wait For Element Visible
  9. 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
    src-test-xml_file
  • 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 AsRun_Eclipse

Running Tests From Windows Command Prompt

    • Open Command PromptRun_cmd1
    • Navigate to Project FolderRun_cmd2
    • 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
    Eclipse_import
  • Select “Existing Maven Project” from menu
    Eclipse_import2
  • Then provide path to extracted pom.xml and click finish
    Eclipse_import3.jpg

----------------------------------------------------------------------------------------------------------

Comments

  1. @Andria BZ Thanks. Will update more information on this in future.

    ReplyDelete
  2. Do 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.
    nebosh course in chennai

    ReplyDelete

Post a Comment

Popular posts from this blog

ExtentReports in Selenium Webdriver

ExtentReports in Selenium Webdriver What is ExtentReport? ExtentReports  is a HTML reporting library for Selenium WebDriver for Java which is extremely easy to use and creates beautiful execution reports. It shows test and step summary, test steps and status in a toggle view for quick analysis Download Download the jar below: Download ExtentReports 1.4 (1623)    Snapshot of Extent report After Executing the Script   Program Steps:  We are going to write three different testcases. Pass Warning Fail TestCase with Pass Result Navigate to http://www.guvi.in Click on Sign-in Enter the credientials Check the URL is correct or not after login   TestCase with Warning Result Verify with the Wrong URL (static String Afterloginfail="http://www.guvi.in/ ")    TestCase with fail Result Click on Menu Select Tech Challenges Verify With wrong URL. Source Code: import  java.io.File; import  j...

API Testing With Selenium WebDriver

REST API Testing Framework We will be creating a simple Rest Testing Framework in Java and JUnit that could be used for any testing scenarios. Rest Testing Framework Overview The framework should be able to execute the basic REST operations (GET, POST, PUT, PATCH, DELETE) and perform the validations on the code, message, headers and body of the response. The completed code can be accessed from my  GitHub account   from where you can collect and make modifications based on your requirements. Design We will be having three classes for the framework (in package com.axatrikx.controller ) RestExecutor  : Performs the HTTP operations using Apache Http Client RestResponse  : A javabean class to hold our response values (code, message, headers, body) RestValidator  : Validates the response with the expected values The package  com.axatrikx.test  holds the test scripts. Note: I will be using ‘ json-server ‘ to f...