-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Primeiro commit do Projeto de Testes Funcionais Automatizados de API …
…REST em Robot Framework desenvolvido para a squad Black List do Qa.Coders Academy
- Loading branch information
0 parents
commit 195fd0e
Showing
12 changed files
with
541 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
.github/workflows/workflow-blacklist-academy-api-robot-requests.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Pipeline Testes Automatizados API REST ERP Qa.Coders Academy Robot Framework | ||
# executa o workflow toda vez que for realizado um push ou pull-request no repositório | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
# permite também executar esse workflow manualmente na aba "Actions" do GitHub | ||
workflow_dispatch: | ||
|
||
jobs: | ||
robot-api-rest: | ||
# agente de execução/runner | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Passo 1 - Obter cópia do código-fonte do repositório | ||
uses: actions/checkout@v3 | ||
|
||
- name: Passo 2 - Redirecionar os conteúdos de "secrets.USER_ENV", para os fixtures "user.json", etc | ||
run: | | ||
echo '${{ secrets.USER_ENV }}' > ./resources/fixtures/user.json | ||
- name: Passo 3 - Instalar python versão 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.8' | ||
|
||
- name: Passo 4 - Instalar dependências do projeto | ||
run: | | ||
pip install -r requirements.txt | ||
- name: Passo 5 - Executar testes automatizados de API REST no ambiente da squad "Black List" e Gerar reports html e xml | ||
run: robot -d ./reports ./tests/* | ||
|
||
- name: Passo 6 - Armazenar reports html e xml | ||
uses: actions/upload-artifact@v3 | ||
# expressão condicional para que sempre seja executado independentemente dos resultados dos steps anteriores | ||
if: ${{ always() }} | ||
with: | ||
name: robot-api-rest-reports-html-xml | ||
path: ./reports | ||
# armazena por 30 dias | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
__pycache__ | ||
*.xml | ||
*.html | ||
*.log | ||
resources/fixtures/*.json | ||
!resources/fixtures/*.example.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
# Projeto de Testes Funcionais Automatizados de API REST | Robot Framework | RequestsLibrary | Python :test_tube: | ||
--- | ||
# :information_source: Introdução | ||
Esse projeto "blacklist-academy-api-robot" é executado no ambiente da squad "Black List" de ["API REST"](https://black-list.qacoders.dev.br) do "ERP do Qa.Coders Academy", com o objetivo de praticarmos ainda mais testes funcionais automatizados de API REST em Robot Framework, RequestsLibrary, Python e GitHub Actions. | ||
|
||
|
||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[^.]* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
robotframework==6.1.1 | ||
robotframework-pythonlibcore==4.3.0 | ||
robotframework-requests==1.0a10 | ||
requests==2.31.0 | ||
python-dateutil==2.9.0.post0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
*** Settings *** | ||
Documentation Arquivo base com inicializações | ||
Library RequestsLibrary | ||
Library helpers.py | ||
Resource env.resource | ||
Variables environments/${ENV}.json | ||
|
||
|
||
*** Variables *** | ||
${URI} ${base_uri} | ||
|
||
|
||
*** Keywords *** | ||
Criar sessão | ||
${headers} Create Dictionary Content-Type=application/json | ||
Create Session alias=APIBlackList url=${URI} headers=${headers} disable_warnings=1 | ||
|
||
Carregar user fixture | ||
${user_fixture} Carregar Fixture user | ||
Set Test Variable ${USER_FIXTURE} ${user_fixture} | ||
|
||
Obter mail user sysadmin estático | ||
Set Test Variable ${MAIL_SYSADMIN} ${USER_FIXTURE['sysadmin_valido']['mail_valido']} | ||
|
||
Obter password user sysadmin estático | ||
Set Test Variable ${PASSWORD} ${USER_FIXTURE['sysadmin_valido']['password_valida']} | ||
|
||
Obter dados user sydadmin estático | ||
Carregar user fixture | ||
Obter mail user sysadmin estático | ||
Obter password user sysadmin estático | ||
|
||
POST login (SYSADMIN) e obter token | ||
[Arguments] ${mail} ${password} | ||
${body} Create Dictionary | ||
... mail=${mail} | ||
... password=${password} | ||
Log ${body} | ||
|
||
Criar sessão | ||
|
||
${response_post_login_sysadmin} POST On Session | ||
... alias=APIBlackList | ||
... url=/api/login | ||
... json=${body} | ||
... expected_status=200 | ||
|
||
Set Local Variable ${JSON_DATA_POST_LOGIN_SYSADMIN} ${response_post_login_sysadmin.json()} | ||
Set Test Variable ${TOKEN_SYSADMIN} ${JSON_DATA_POST_LOGIN_SYSADMIN['token']} | ||
|
||
Gerar fullName user admin dinâmico | ||
${fullName} Gerar Full Name | ||
Set Test Variable ${FULL_NAME} ${fullName} | ||
|
||
Gerar mail user admin dinâmico | ||
${mailAdmin} Gerar Mail User | ||
Set Test Variable ${MAIL_ADMIN} ${mailAdmin} | ||
|
||
Gerar cpf user admin dinâmico | ||
${cpf} Gerar Cpf | ||
Set Test Variable ${CPF} ${cpf} | ||
|
||
Obter password e confirmPassword estáticas user admin dinâmico | ||
Set Test Variable ${PASSWORD_CONFIRM_PASSWORD} ${USER_FIXTURE['admin_valido']['password_confirmPassword_validas']} | ||
|
||
Gerar e obter dados user admin dinâmico | ||
Gerar fullName user admin dinâmico | ||
Gerar mail user admin dinâmico | ||
Gerar cpf user admin dinâmico | ||
Obter password e confirmPassword estáticas user admin dinâmico | ||
|
||
POST user (ADMIN), obter id e mail | ||
[Arguments] ${fullName} ${mail} ${cpf} ${password_confirmPassword} | ||
${body} Create Dictionary | ||
... fullName=${fullName} | ||
... mail=${mail} | ||
... accessProfile=ADMIN | ||
... cpf=${cpf} | ||
... password=${password_confirmPassword} | ||
... confirmPassword=${password_confirmPassword} | ||
Log ${body} | ||
|
||
Criar sessão | ||
|
||
${headers} Create Dictionary Authorization=${TOKEN_SYSADMIN} | ||
|
||
${response_post_user_admin} POST On Session | ||
... alias=APIBlackList | ||
... url=/api/user | ||
... headers=${headers} | ||
... json=${body} | ||
... expected_status=201 | ||
|
||
Set Local Variable ${JSON_DATA_POST_USER_ADMIN} ${response_post_user_admin.json()} | ||
Set Test Variable ${ID_ADMIN} ${JSON_DATA_POST_USER_ADMIN['user']['_id']} | ||
Set Test Variable ${MAIL_ADMIN} ${JSON_DATA_POST_USER_ADMIN['user']['mail']} | ||
|
||
POST login (ADMIN) e obter token | ||
[Arguments] ${mail} ${password} | ||
${body} Create Dictionary | ||
... mail=${mail} | ||
... password=${password} | ||
Log ${body} | ||
|
||
Criar sessão | ||
|
||
${response_post_login_admin} POST On Session | ||
... alias=APIBlackList | ||
... url=/api/login | ||
... json=${body} | ||
... expected_status=200 | ||
|
||
Set Local Variable ${JSON_DATA_POST_LOGIN_ADMIN} ${response_post_login_admin.json()} | ||
Set Test Variable ${TOKEN_ADMIN} ${JSON_DATA_POST_LOGIN_ADMIN['token']} | ||
|
||
POST login (SYSADMIN), POST user (ADMIN), POST login (ADMIN) e obter tokens | ||
Obter dados user sydadmin estático | ||
POST login (SYSADMIN) e obter token mail=${MAIL_SYSADMIN} password=${PASSWORD} | ||
Gerar e obter dados user admin dinâmico | ||
POST user (ADMIN), obter id e mail | ||
... fullName=${FULL_NAME} | ||
... mail=${MAIL_ADMIN} | ||
... cpf=${CPF} | ||
... password_confirmPassword=${PASSWORD_CONFIRM_PASSWORD} | ||
POST login (ADMIN) e obter token mail=${MAIL_ADMIN} password=${PASSWORD_CONFIRM_PASSWORD} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*** Settings *** | ||
Documentation Arquivo com variável global de ambiente padrão | ||
|
||
*** Variables *** | ||
${ENV} black-list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"base_uri": "https://black-list.qacoders.dev.br" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"sysadmin_valido": { | ||
"mail_valido": "informar-mail-user-sysadmin-valido", | ||
"password_valida": "informar-password-user-sysadmin-valido" | ||
}, | ||
"admin_valido": { | ||
"password_confirmPassword_validas": "informar-password-confirmPassword-user-admin-valido" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import random, json | ||
|
||
def gerar_numeros_aleatorios(qtde_numeros): | ||
possible = "0123456789" | ||
text = ''.join(random.choice(possible) for _ in range(qtde_numeros)) | ||
|
||
return text | ||
|
||
def mod(dividendo, divisor): | ||
return round(dividendo - (dividendo // divisor) * divisor) | ||
|
||
def gerar_cpf(): | ||
rnd = lambda n: round(random.random() * n) | ||
n = [rnd(9) for _ in range(9)] | ||
|
||
d1 = 11 - mod(sum([n[i] * (10 - i) for i in range(9)]), 11) | ||
d1 = 0 if d1 >= 10 else d1 | ||
|
||
d2 = 11 - mod(d1 * 2 + sum([n[i] * (11 - i) for i in range(9)]), 11) | ||
d2 = 0 if d2 >= 10 else d2 | ||
|
||
return f"{''.join(map(str, n))}{d1}{d2}" | ||
|
||
def gerar_cnpj(): | ||
n1 = gerar_numeros_aleatorios(1) | ||
n2 = gerar_numeros_aleatorios(1) | ||
n3 = gerar_numeros_aleatorios(1) | ||
n4 = gerar_numeros_aleatorios(1) | ||
n5 = gerar_numeros_aleatorios(1) | ||
n6 = gerar_numeros_aleatorios(1) | ||
n7 = gerar_numeros_aleatorios(1) | ||
n8 = gerar_numeros_aleatorios(1) | ||
n9 = '0' | ||
n10 = '0' | ||
n11 = '0' | ||
n12 = '1' | ||
|
||
d1 = int(n12)*2 + int(n11)*3 + int(n10)*4 + int(n9)*5 + int(n8)*6 + int(n7)*7 + int(n6)*8 + int(n5)*9 + int(n4)*2 + int(n3)*3 + int(n2)*4 + int(n1)*5 | ||
d1 = 11 - mod(d1, 11) | ||
d1 = 0 if d1 >= 10 else d1 | ||
|
||
d2 = d1*2 + int(n12)*3 + int(n11)*4 + int(n10)*5 + int(n9)*6 + int(n8)*7 + int(n7)*8 + int(n6)*9 + int(n5)*2 + int(n4)*3 + int(n3)*4 + int(n2)*5 + int(n1)*6 | ||
d2 = 11 - mod(d2, 11) | ||
d2 = 0 if d2 >= 10 else d2 | ||
|
||
return f"{n1}{n2}{n3}{n4}{n5}{n6}{n7}{n8}{n9}{n10}{n11}{n12}{d1}{d2}" | ||
|
||
def gerar_full_name(): | ||
full_name = "ADMIN Blacklist" | ||
|
||
return full_name | ||
|
||
def gerar_mail_user(): | ||
mail = "admin.blacklist" + gerar_numeros_aleatorios(6) + "@qacoders.com" | ||
|
||
return mail | ||
|
||
def gerar_corporate_name(): | ||
corporate_name = "Teste Company Blacklist " + gerar_numeros_aleatorios(6) | ||
|
||
return corporate_name | ||
|
||
def gerar_mail_company(): | ||
mail = "teste.company.blacklist" + gerar_numeros_aleatorios(6) + "@qacoders.com" | ||
|
||
return mail | ||
|
||
def gerar_service_description(): | ||
service_description = "Teste Descrição Serviço Company Blacklist " + gerar_numeros_aleatorios(6) | ||
|
||
return service_description | ||
|
||
def carregar_fixture(nome_fixture): | ||
with open(f'resources/fixtures/{nome_fixture}.json', 'r', encoding='utf-8') as fixture: | ||
return json.load(fixture) |
Oops, something went wrong.