Gitlab - Argos ALM by PALO IT

Commit 0406122b authored by Dainer Acosta's avatar Dainer Acosta

add flow for create user and get user

parent d0077e52
.DS_Store
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
database*
### STS ###
.apt_generated
.classpath
.apt_generated
target
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/logs/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
/.metadata/
# Test automation project with Robot Framework and Java
\ No newline at end of file
<h1>Test automation project with Robot Framework and Java</h1>
<p align="justify">
<img src="https://img.shields.io/static/v1?label=java&message=11&color=turquoise&style=for-the-badge&logo=oracle"/>
<img src="https://img.shields.io/static/v1?label=maven&message=3.9&color=crimson&style=for-the-badge&logo=apachemaven"/>
<img src="https://img.shields.io/static/v1?label=robot&message=framework&color=yellow&style=for-the-badge&logo=robotframework"/>
</p>
## Project description
<p align="justify">
Example project with API tests using RobotFramework with Java and Maven
</p>
## Technical details
<p align="justify">
Although the Robot Framework is based on Python, it can be used to test Java applications. For UI testing in web applications, we use the SeleniumLibrary together with Selenium WebDriver. Selenium WebDriver is compatible with browsers such as Chrome, Firefox, and Safari, allowing UI tests to run in any supported browser. To test APIs or services, we use the Robot Framework's RequestsLibrary. Also, the project is configured to use the Robot Framework Maven plugin. This allows Robot Framework tests to run as part of the Maven build lifecycle. This is especially useful for continuous integration/continuous delivery (CI/CD), where you may want to run your tests automatically as part of your build pipeline.
</p>
## Functionalities
- :heavy_check_mark: CreateUser
- :heavy_check_mark: GetUser
## Pre-requisites
:warning: [Java 11](https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html)
:warning: [Maven](https://maven.apache.org/download.cgi)
:warning: [RobotFramework](https://robotframework.org/)
## Run tests
To run RobotFramework with Maven use the command below:
``````
mvn robotframework:run -D includes=Nome_Tag
``````
## Support URLs
Links to framework documentation
- [Robot Framework HttpRequestLibrary](https://repo1.maven.org/maven2/com/github/marketsquare/robotframework-httprequestlibrary/0.0.19/robotframework-httprequestlibrary-0.0.19.html)
- [Robot Framework Maven Plugin](http://robotframework.org/MavenPlugin/run-mojo.html)
\ No newline at end of file
*** Settings ***
Resource ${EXECDIR}/resources/steps/user/createUser_step.resource
Documentation Tests for PoC Cardif consume API REST in IBM Cloud
*** Test Cases ***
Scenery: Create user success
[Documentation] Test for create user
[Tags] User Create_User
Since you are connected to the API with the config config/http_client_config.json
Get data of user
Send request for create user
So the response status should be "201" and the response body should be "user/response_user_ok.json"
*** Settings ***
Resource ${EXECDIR}/resources/steps/user/getUser_step.resource
Resource ${EXECDIR}/resources/steps/user/createUser_step.resource
Documentation PoC test for cardif consuming services on IBM Cloud
*** Test Cases ***
Scenery: Get a user successfully
[Documentation] Test for create user
[Tags] User Get_User
Since you are connected to the API with the config config/http_client_config.json
Get data of user
Send request for create user
Send request for get user
So the get user response status should be "200" and the response body should be "user/response_user_ok.json"
\ No newline at end of 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.poc.robotframework</groupId>
<artifactId>poc-automation-cardif</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>API Test Automation</name>
<description>Robot version test project</description>
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyy-MM-dd-HHmmss</maven.build.timestamp.format>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<!--
https://mvnrepository.com/artifact/org.robotframework/robotframework -->
<dependency>
<groupId>org.robotframework</groupId>
<artifactId>robotframework</artifactId>
<version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>com.github.marketsquare</groupId>
<artifactId>robotframework-httprequestlibrary</artifactId>
<version>0.0.19</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin</artifactId>
<version>2.1.0</version>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<testCasesDirectory>${project.basedir}/features</testCasesDirectory>
<outputDirectory>${project.basedir}/logs/logAPI${maven.build.timestamp}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
*** Settings ***
Library DateTime
Library OperatingSystem
Library HttpRequestLibrary
Library Collections
Library String
*** Keywords ***
Since you are connected to the API with the config
[Documentation] Function in charge of configuring the connection with the API
[Arguments] ${nome_json}
${json_file_configuracao}= Get File Json ${nome_json}
Set Test Variable ${json_file_configuracao}
Log ${json_file_configuracao}
${header} Create Dictionary Content-type=${json_file_configuracao["contentType"]}
Create Session ${json_file_configuracao["session"]} ${json_file_configuracao["url"]} headers=${header}
Get File Json
[Arguments] ${nome_aquivo}
${arquivo} Get File ${EXECDIR}/resources/data/${nome_aquivo}
${json} Evaluate json.loads($arquivo) json
[Return] ${json}
\ No newline at end of file
{
"url": "https://34.149.53.30.nip.io",
"session": "DummyJson",
"contentType": "application/json"
}
\ No newline at end of file
{
"name": "PoC QA test"
}
\ No newline at end of file
{
"id": "0fc7cdee-05d0-43d0-8918-fcdc8c1f002e",
"name": "PoC QA test"
}
\ No newline at end of file
*** Settings ***
Library br.com.poc.robotframework.api.dummy.user.datafactory.CreateUserDataFactory
Resource ${EXECDIR}/resources/common.resource
*** Variables ***
${path_create_user} /ibm/sharks
*** Keywords ***
Get data of user
[Documentation] Function responsible of get the data for the test
${payload}= Get Payload Valid Create User
Set Test Variable ${payload}
Log ${payload}
Send request for create user
[Documentation] Function responsible for sending data to the endpoint
${response_create_user} Post Request alias=DummyJson uri=${path_create_user} data=${payload}
Set Test Variable ${response_create_user}
Log ${response_create_user}
${id}= Get From Dictionary ${response_create_user.json} id
Set Test Variable ${id}
So the response status should be "${status_code}" and the response body should be "${name_json}"
[Documentation] Function responsible for validating the response
${json_response}= Get File Json ${name_json}
Response Code Should Be DummyJson ${status_code}
${id}= Get From Dictionary ${response_create_user.json} id
Dictionary Should Contain Item ${response_create_user.json} name ${json_response["name"]}
Should Not be Empty "${id}"
\ No newline at end of file
*** Settings ***
Library br.com.poc.robotframework.api.dummy.user.datafactory.CreateUserDataFactory
Resource ${EXECDIR}/resources/common.resource
*** Variables ***
${path_get_user} /ibm/sharks
*** Keywords ***
Send request for get user
[Documentation] Function responsible for sending data to the endpoint
${response_get_user} Get Request alias=DummyJson uri=${path_get_user}/${id}
Set Test Variable ${response_get_user}
Log ${response_get_user}
So the get user response status should be "${status_code}" and the response body should be "${name_json}"
[Documentation] Function responsible for validating the response
${json_response}= Get File Json ${name_json}
Response Code Should Be DummyJson ${status_code}
${id}= Get From Dictionary ${response_get_user.json} id
Should Not be Empty "${id}"
\ No newline at end of file
package br.com.poc.robotframework.api.dummy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class BaseDataFactory {
protected Gson gson;
public BaseDataFactory() {
gson= new GsonBuilder().enableComplexMapKeySerialization().create();
}
}
package br.com.poc.robotframework.api.dummy.user.datafactory;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import br.com.poc.robotframework.api.dummy.BaseDataFactory;
import br.com.poc.robotframework.api.dummy.user.dto.CreateUserDTO;
public class CreateUserDataFactory extends BaseDataFactory {
public CreateUserDataFactory() {
super();
}
public CreateUserDTO getCreateUserDTO() throws FileNotFoundException {
BufferedReader reader = new BufferedReader(new FileReader("resources/data/user/request_create_user.json"));
CreateUserDTO CreateUserDTO;
CreateUserDTO = gson.fromJson(reader, CreateUserDTO.class);
return CreateUserDTO;
}
public String getPayloadValidCreateUser() throws FileNotFoundException {
return gson.toJson(getCreateUserDTO());
}
}
package br.com.poc.robotframework.api.dummy.user.dto;
public class CreateUserDTO {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package br.com.poc.robotframework.api.utils;
public class APIUtils {
}
package br.com.poc.robotframework.api.utils;
public class PropertySet {
public void setSystemProperty(String key, String value) {
System.getProperties().setProperty(key,value);
System.setProperty("webdriver.http.factory", "jdk-http-client");
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment