Skip to content

Alfresco/alfresco-tas-utility

Repository files navigation


Build Status

Table of Contents

Synopsis

This is the home of the TAS( Test Automation System)- Utility project. It is based on Apache Maven, compatible with major IDEs and is using also Spring capabilities for dependency injection.

As a high level overview, this project contains a couple of functionalities useful for automation testing as:

  • reading/defining test environment settings (e.g. alfresco server details, authentication, etc.)
  • utilities (creating files,folders)
  • test data generators (for site, users, content, etc)
  • helpers (i.e. randomizers, test environment information)
  • test reporting capabilities
  • test management integration (at this point we support integration with Test Rail (v5.2.1)
  • Health checks (verify if server is reachable, if server is online)
  • Generic Internal-DSL (Domain Specific Language)

(take a look also on this page: we will try to keep it up to date with the latest features based on each release)

Using a centralized location (Nexus), everyone will be able to reuse this individual interfaces in their own projects, adding new functionalities, extending also the automation core functionalities - that will be shared across teams.

Back to Top ^

Prerequisite

(tested on unix/non-unix destribution)

  • Java 17.
  • Maven 3.3 installed and configure according to Windows OS or Mac OS.
  • Configure Maven to use Alfresco alfresco-internal repository following this Guide. We are using also the internal-snapshot repository, so here it is the full settings.xml file
<settings>
  <profiles>
    <profile>
      <id>alfresco-internal</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>alfresco-internal</id>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
          <name>Alfresco Internal Repository</name>
          <url>https://artifacts.alfresco.com/nexus/content/groups/internal/</url>
        </repository>
        <repository>
            <id>alfresco-internal-snapshots</id>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <name>Alfresco Internal Snapshots Repository</name>
            <url>https://artifacts.alfresco.com/nexus/content/groups/internal-snapshots/</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>alfresco-internal</id>
          <name>Alfresco Internal Repository</name>
          <url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
        </pluginRepository>
      </pluginRepositories>
    </profile>
</profiles>
  <servers>
      <server>
        <id>alfresco-internal</id>
        <username>Your_LDAP_Login</username>
	    <password>Your_LDAP_Password</password>      
      </server>
      <server>
          <id>alfresco-internal-snapshots</id>
          <username>Your_LDAP_Login</username>
	      <password>Your_LDAP_Password</password>  
     </server>
  </servers>
</settings>
  • Your favorite IDE as Eclipse or InteliJ.
  • Access to Nexus repository.
  • Access to Git TAS repository.
  • Git client for your operating system. (we recommend SourceTree - use your google account for initial setup).
  • Getting familiar with Basic Git Commands.
  • Getting familiar with Maven.
  • Getting familiar with Spring.

Back to Top ^

Installation (if you want to contribute or run tests from your local machine)

  • Open your Git client and clone the repository of this project.
  • You can do this also from command line (or in your terminal) adding:
# this command will cloen the utility project locally
$ git clone https://git.alfresco.com/tas/alfresco-tas-utility.git 

# this clone will have the latest changes from repository. If you want to checkout a specific version released, take a look at the [Change Log](docs/CHANGELOG.md) page
$ cd alfresco-tas-utility
# this command will checkout the remove v1.0.0 tagged repository and create locally a new branch v1.0.0
$ git checkout tags/v1.0.0 -b v1.0.0 
  • Install and check if all dependencies are downloaded (in your downloaded repository run the following commands:)
$ mvn clean install -DskipTests
# you should see one [INFO] BUILD SUCCESS message displayed

Back to Top ^

Package Presentation

This project uses a simple maven project archetype:

├── src
│   ├── main
│   │   ├── java
│   │   │   └── org
│   │   │       └── alfresco
│   │   │           └── utility
│   │   │               ├── data # helpers for creating Sites/Files, Users, etc)
│   │   │               │   (...)
│   │   │               ├── dsl  #contains all the interfaces, abstract classes that will be available for all protocols, apis
│   │   │               │   ├──(...)
│   │   │               ├── exception # custom exception
│   │   │               │   (...)
│   │   │               ├── extension # utilities that will handle testing of Extension Points
│   │   │               │   ├── ExtensionPointTestSuite.java
│   │   │               │   ├── ExtentionPointTestUtility.java
│   │   │               ├── model #modeling generic objects that will be reused in test
│   │   │               │   ├── FileModel.java
│   │   │               │   ├── FileType.java
│   │   │               │   ├── FolderModel.java
│   │   │               │   └── UserModel.java
│   │   │               │   └── (...)
│   │   │               ├── network # network based helpers
│   │   │               │   └── (...)
│   │   │               ├── report #handling reporting (i.e. listeners for generating html reports, steps)
│   │   │               │   └── (...)
│   │   │               └── testrail # TestRail integration utils
│   │   │               │   └── (...)
│   │   └── resources
│   |     └── shared-resources  #here you can add any files/configuration files that you want to be avaiable in projects that will consume tas.utility
│   └── test
│       ├── java
│       │   └── org
│       │       └── alfresco
│       │           └── utility #testing classes/sample code
│       │               ├── (...)
│       └── resources
│           ├── default.properties #one place where you defined all settings like what alfresco server to use, credentials, etc.
│           ├── log4j.properties
│           ├── testdata #placeholder for holding test data
│           │   └── (...)

Back to Top ^

High Level Concepts

DSL

The tas.utility has built-in one internal Domain Specific Language (DSL) for handling data creation, for oferring a common way of using protocols, api's. This DSL is made available in src/main/java/org/alfresco/utility under "dsl" package.

As you see above there are available a couple of methods for:

  • defining current test user or getting current user used in test:

      .usingUser(UserModel testUser)
      .getCurrentUser()
  • or even admin (as defined in default.properties):

      .usingAdminUser()
  • specifying current space (like root folder, data dictionary, or a particular site:

      .usingRoot()
      .usingSite(String siteId)
      .usingSite(SiteModel testSite)
      (...)
  • or specifying a particular resource (like file/folder):

      .usingResource(String fileNameOrFolderName)
      .usingResource(ContentModel content)
      (...)

    The advantage of this approach is that you can combine this DSL in a logical order as the steps of a test like:

      .usingAdminUser().usingSite("mySite").usingResource("myFile")
      (...)

    This will tell us, that we will use resource file "myFile", with admin user from ("/Sites/mySite/documentLibrary"). This is a general overview of the DSL, so each protocol that will implement this DSL will have the same method signature.

Models

I assume you already notice a couple of *Model variables, like UserModel or SiteModel, ContentModel, etc. This is another concept that we will use in the tas framework. All methods of the DSL will accept this generic methods that are available in src/main/java/org/alfresco/utility under "models" package.

Having this implementation, we can all use the same approach, the same models when we define and create new tests.

Protocol(s)

If we are talking about protocols like (CIFS, WebDav, FTP, etc.) for them we have another DSL

Thiw will add the implementation of generic DSL, plus new utilities that will ease our life (like building paths to a particular location, assertions, JMX configuration, etc)

See bellow as example, the implementation of WebDavWrapper (we call it wrapper, because is a class around a standard library: in this case jackrabbit.apache for testing WebDav)

(This is a project that is consuming tas.utility found also on http://git.alfresco.com)

Back to Top ^

Sample Usage

In your maven project, in your pom.xml file add the following dependency

<dependency>
			<groupId>org.alfresco.tas</groupId>
			<artifactId>utility</artifactId>
			<version>${tas.utility.version}</version>
</dependency>

(where ${tas.utility.version} is the latest verion released on Nexus internal) You can also take a look on our changelog page for more details.

NOTE: you can also browse the samples folder for simple maven projects that is consuming this library. Just import this existing Maven project in your IDE (if you are using Eclipse follow this guide)

Configure your maven project to use tas.utility

NOTE: you can also browse the samples folder for simple maven projects that is consuming this library. Just import this existing Maven project in your IDE (if you are using Eclipse follow this guide)

  • if you have one simple maven project created, you must add Spring bean capabilities to interact with tas.utility project

    • add dependency to your pom.xml (as indicated above) - no need for spring bean dependencies, this are downloaded automatically from tas.utility
    • import resources in src/test/resources/<your-test-context.xml> (see one example here)
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    	xsi:schemaLocation="http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.0.xsd
              http://www.springframework.org/schema/data/mongo
              http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
              http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    
    	<context:annotation-config />
    	<context:component-scan base-package="org.alfresco" />
    
    	<import resource="classpath:dataprep-context.xml" />
    	<import resource="classpath*:alfresco-tester-context.xml" />
    </beans>
  • copy default.properties to your src/test/resources folder, updating the settings as you want (see one example here).

    • notice that we have properties for server configuration. These are pointing to localhost as default, but feel free to point to any alfresco server that you have already installed (version >=5.1)

      # Alfresco HTTP Server Settings
      alfresco.scheme=http
      alfresco.server=127.0.0.1
      alfresco.port=8080
  • create a simple TestNG test for testing the autowired bean capabilities. (see one example here)

     @ContextConfiguration("classpath:alfresco-smtp-context.xml")
     public abstract class MyTestIsAwesome extends AbstractTestNGSpringContextTests{
     	@Autowired
         protected ServerHealth serverHealth;
    
     	@Test
         public void checkAlfrescoServerIsOnline() throws Exception
     	{
         	serverHealth.assertServerIsOnline();
     	}
     }
  • optional add your default log4j file. You can use this example.

  • if settings from default.properties are properly set, after running this test you should see Build Success message.

  • in case you are using the default settings that points to localhost (127.0.0.1) and you don't have Alfresco installed on your machine, you will see one exception thrown by the tests as:

    org.alfresco.utility.exception.ServerUnreachableException: Server {127.0.0.1} is unreachable.

Naming Conventions

Please read the following Wiki page

How to write a test

  • we are using TestNG framework to drive our test, so please feel free to take a look on official documentation if you are not yet familiarized with this.

  • to view a simple class that is using this utility, just browse on samples/consuming-tas-utility

    • notice the class definition and inheritance value:
        @ContextConfiguration("classpath:alfresco-test-context.xml")
        public class SampleTest extends AbstractTestNGSpringContextTests 
    • each utility (from package presentation above) can be annotated with @Autowired keyword in your test in order to initialize it.
    • as a convention, before running your test, check if the test environment is reachable and your alfresco test server is online. (this will stop the test if the server defined in your property file is not healthy)
        @BeforeClass(alwaysRun = true)
        public void environmentCheck() throws Exception {
    	    serverHealth.assertServerIsOnline();
        }
    • each test name should express cleary what will do:
        @Test
        public void adminShouldCreateFolderInSite()
        {
            (...)
        }
        
        @Test
        public void adminCannotCreateSameFolderTwice()
        {
            (...)
        }
    • Use the assertions provided by this utility (see the "data" package)
        FolderModel myFolder = FolderModel.getRandomFolderModel();
        //here we create a new content in the root location of alfresco
        dataContent.usingRoot().createFolder(myFolder);
        
        // here we assert that folder exist 
    	dataContent.assertContentExist(myFolder);

How to create new data (files/folder)

  • configure your project to use spring (as highlighted above)

  • in your test file add:

    @Autowired
    protected DataContent dataContent;
    
    @Test
    public void creatingFolderInRepoLocation()
    {
    /*
    *this call will create folder  'myTest' under '/Sites/mySite/documentLibrary' location
    * using default admin user specified in default.properties file
    */
    dataContent.usingSite("mySite").createFolder("myTest")
    
    /*
    *this call will create folder 'myTest2' under '/' root folder
    * using default admin user specified in default.properties file
    */
    dataContent.usingRoot().createFolder("myTest2")
    }
    
    @Test
    public void creatingFolderInRepoLocationWithCustomUsers()
    {
    /*
    *this call will create folder  'myTest' under '/Sites/mySite/documentLibrary' location
    * using default user'testUser'
    */
    
    FolderModel myFolder = FolderModel.getRandomFolderModel();
    dataContent.usingUser(testUser).usingSite("mySite").createFolder(myFolder)
    
    /*
    *this call will create folder 'myTest2' under '/' root folder
    * using user testUser
    */
    FolderModel myFolder = FolderModel.getRandomFolderModel();
    dataContent.usingUser(testUser).usingRoot().createFolder(myFolder)
    }
  • remember models defined above in the package presentation ? Those models can be used in the utilities presented above. So 'testUser' for example is a UserModel class that can be defined as:

    UserModel testUser = new UserModel("testUserName", "testUserPassword")

    We also have some generators that will ease your code style:

    // this will create a new UserModel class using the default admin user defined in default.properties file
    UserModel testUser = dataContent.getAdminUser();
    // this will create a new random user in repository and return a new UserModel class
    @Autowired
    DataUser dataUser;
    //(...)
    UserModel testUser = dataUser.createRandomTestUser();

How to create a new site

  • configure your project to use spring (as highlighted above)
  • in your test file add:
    @Autowired
    protected DataSite dataSite
    
    @Test
    public void createSite()
    {
    	// this will create a new public random site using admin (no user provided as we see bellow)
    	dataSite.createPublicRandomSite()
      UserModel testUser = dataUser.createRandomTestUser();
      dataSite.createPublicRandomSite()
    }

Back to Top ^

How to run tests

-using TestNG Suite

  • If you are using Eclipse, and you already configured Eclipse to use TestNG pluging, just right click on the testNG class that you created (something similar to SampleTest.java) select Run As - TestNG Test You should see your test passed:

-from command line

  • In terminal or CMD, navigate (with CD) to root folder of your project (you can use the sample project):

    Based on pom.xml setting, the default suite that is executed is pointing to xml <suiteXmlFile>src/test/resources/sanity-suite.xml</suiteXmlFile> Please analyse this xml file! Notice that only tests that are marked with "sanity" within package "org.alfresco.sample" are executed.

    In terminal now type:

    mvn test    

Back to Top ^

Test Results

We already executed a couple of tests using command line as indicated above. Sweet! Please take a look at sanity-suite.xml one more time. You will see there that we have one listener added:

<listener class-name="org.alfresco.utility.report.HtmlReportListener"></listener>

This will tell our framework, after we run all tests, to generate one HTML report file with graphs and metrics.

Take a look at the targe/reports folder (created after running the tests, path that is also configured in default.properties). Open the report.html file.

Playing with this report, you will notice that you will be able to: * search tests cases by name * filter test cases by errors, labels, groups, test types, date when it was executed, protocol used, etc. * view overall pass/fail metrics of current test suite, history of tests execution, etc.

Starting from utility 1.0.9 you are able to:

  • see why some tests are skipped. Maybe to environment test configuration.

    Each test skipped has a proper message displayed.

  • filter tests that are failing with BUGS label, or the tests that are failing and are not annotated with BUGS (in the report first select the Fail tests, then select group ALL). Each test has this "ALL" group defined.

Back to Top ^

Test Rail Integration

Alfresco is using now https://alfresco.testrail.net (v5.3.0.3601). We wanted to minimize the manual interaction as much as we can, so if we will have one automated test that is executed, that test (if test rail integration is enabled) should be automatically uploaded in Test Rail under a specific section that you defined. We are not stopping here, the execution status, the stack trace of error, steps that executed at runtime, all this information are automatically published to this Test Case Management tool.

Configuration

In order to use Test Rail Integration you will need to add a couple of information in default.properties file: (the document is pretty self exmplanatory)

# Example of configuration:
# ------------------------------------------------------
# testManagement.endPoint=https://alfresco.testrail.com/
# testManagement.username=<yourusername-that-you-connect-to-testrail>
# testManagement.apiKey=<api-key>
# testManagement.project=<id-of-your-project 
# testManagement.testRun=<test-run-name>

For generating a new API Key take a look at the official documentation, TestRail APIv2

  • testManagement.project= <id-of-your-project this is the ID of the project where you want to store your test cases. If you want to use Alfresco ONE project in TestRail, open that project and notice the URL, after "/overview/1" link you will see the ID of the project (1 in this case) If you want to use TAS Project you will notice the ID 7, so "testManagement.project=7"
  • "testManagement.testRun=" this represents the name of the Test Run from your project.
  • In Test Rail, navigating to Test Runs & Results, create a new Test Run and include all/particular test cases. If this test run name is "Automation", update testManagement.testRun= Automation. All test results will be updated only on this test run at runtime as each test is executed by TAS framework.

How to enable Test Rail Integration?

We wanted to simplify the Test Rail integration, so we used listeners in order to enable/disable the integration of Test Rail.

  • first configure your default.properties as indicated above

  • now on your TestNG test, add the @TestRail annotation, so let's say you will have this test:

     @Test(groups="sample-tests")  
     public void thisAutomatedTestWillBePublishedInTestRail() 
     {
     }

    add now @TestRail integration with manadatory field section. This means that this tests annotated, will be uploaded in TestRail:

    @Test(groups="sample-tests")
    @TestRail(section = { "demo", "sample-section" })
    public void thisAutomatedTestWillBePublishedInTestRail() 
    {
    }

    The section field, represents an array of strings, the hierarcy of sections that SHOULD be found on TestRail under the project you've selected in default.properties. Follow the TestRail user-guide for more information regarding sections. In our example we created in Test Rail one root section "demo" with a child section: "sample-section" (you can go further and add multiple section as you wish)

  • now, lets add the listener, the TestRailExecutorListener that will handle this TC Management interation. This listener can be added at the class level or suite level (approach that we embrace) So edit your sanity-suite.xml file and add the following under tag

    <listeners>
    	<listener class-name="org.alfresco.utility.testrail.TestRailExecutorListener"></listener>     
     (...)
    </listeners>

    Let's also add a group under <test name="Sanity Demo Test"> so the sanity-suite.xml will look like: This will go through "org.alfresco.sample" package and run ALL the tests that are marked with java groups="sample-tests" - so we want to run only the sample above.

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
      <suite name="Suite" parallel="classes">
      	<listeners>
      		<listener class-name="org.alfresco.utility.report.HtmlReportListener"></listener>
      		<listener class-name="org.alfresco.utility.testrail.TestRailExecutorListener"></listener>
      	</listeners>
      	<test name="Sanity Demo Test">
      		<groups>
      			<run>
      				<include name="sample-tests"></include>
      			</run>
      		</groups>
      		<packages>
      			<package name="org.alfresco.sample"></package>
      		</packages>
      	</test>
      </suite> <!-- Suite -->

    Righ click on sanity-suite.xml file and run it, or just "mvn test" from root if this sample project. After everithing passes, go in Test Rail, open your project and navigate to "Test Cases" section. Notice that under demo/sample-section, you will see "thisAutomatedTestWillBePublishedInTestRail" test case published. If you defined also the "testManagement.testRun" correctly, you will see under Test Runs, the status of this case marked as passed.

    The @TestRail annotation offers also other options like:

    • "description" this is the description that will be updated in Test Rail for your test case
    • "testType", the default value is set to Functional test
    • "executionType", default value is set to ExecutionType.REGRESSION, but you can also use ExecutionType.SMOKE, ExecutionType.SANITY, etc

    Take a look at TestRailIntegrationTest.java file

Back to Top ^

Reference

  • For any improvements, bugs, please use Jira - TAS project.
  • Setup the environment using docker

Contributors

As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other... more.

:octocat: Please also take a look at the following [Workflow] (https://git.alfresco.com/tas/alfresco-tas-utility/wikis/workflow-process) process.

Releasing

Any commit done on this project should be automatically executed by TAS Build Plan If the build passes, then you didn't broke anything.

If you want to perform a release, open TAS-Utility Bamboo Build. Run the Default stage and if it passes, then manually perform the Release stage (this will auto-increment the version in pom.xml)

License

TBD