-
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.
- Loading branch information
Showing
7 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
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
Binary file not shown.
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,32 @@ | ||
from selenium import webdriver | ||
from selenium.webdriver.chrome.service import Service | ||
from behave import * | ||
import yaml | ||
|
||
def before_all(context): | ||
# Carregue as variáveis do arquivo YAML | ||
with open('config.yml', 'r') as file: | ||
context.config_data = yaml.safe_load(file) | ||
|
||
browserstack=False | ||
def before_scenario(context, scenario): | ||
if browserstack: | ||
desired_capabilities = { | ||
'browserName': 'chrome' | ||
} | ||
context.browser = webdriver.Remote( | ||
desired_capabilities=desired_capabilities, | ||
#command_executor="http://localhost:4444/wd/hub" | ||
) | ||
|
||
context.browser.delete_all_cookies() | ||
context.browser.maximize_window() | ||
else: | ||
service = Service('drivers\chromedriver.exe') | ||
context.browser = webdriver.Chrome(service=service) | ||
context.browser.delete_all_cookies() | ||
context.browser.maximize_window() | ||
|
||
|
||
def after_scenario(context, scenario): | ||
context.browser.quit() |
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,24 @@ | ||
from steps.utils import Utils | ||
from pages.mapeamento import Map | ||
|
||
|
||
class Geral: | ||
def acessar_url(context,url): | ||
context.browser.get(url) | ||
context.browser.maximize_window() | ||
|
||
def login(context,documento,senha): | ||
Utils.find_and_send(context,Map.LOC_DOCUMENTO,documento) | ||
Utils.find_and_click(context,Map.LOC_BOTAO_ENTRAR) | ||
Utils.find_and_send(context,Map.LOC_SENHA,senha) | ||
Utils.find_and_click(context,Map.LOC_CONTINUAR) | ||
|
||
def recusar_modais(context): | ||
Utils.find_and_click(context,Map.LOC_ACEITAR_COOKIES) | ||
Utils.find_and_click(context,Map.LOC_PESQUISA) | ||
Utils.find_and_click(context,Map.LOC_TOUR_GUIADO) | ||
Utils.find_and_click(context,Map.LOC_AVISO) | ||
Utils.find_and_click(context,Map.LOC_MODAL_MODELO) | ||
|
||
def acessou(context): | ||
Utils.find_and_click(context,Map.LOC_TITULO_TOTAL) |
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,25 @@ | ||
from behave import * | ||
from pages.page_geral import Geral | ||
|
||
|
||
@given('que eu esteja na pagina') | ||
def step_user_on_login_page(context): | ||
url = context.config_data.get('url') | ||
Geral.acessar_url(context,url) | ||
|
||
@when('faco login usando o documento') | ||
def step_enter_valid_credentials(context): | ||
username = context.config_data.get('user01') | ||
password = context.config_data.get('password') | ||
|
||
Geral.login(context,username,password) | ||
|
||
|
||
@when('Aceitar cookies e recusar pesquisa e tour') | ||
def step(context): | ||
Geral.recusar_modais(context) | ||
|
||
@then('acessou') | ||
def step(context): | ||
Geral.acessou(context) | ||
|
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 re | ||
from selenium import * | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.common.exceptions import NoSuchElementException | ||
from selenium.webdriver.support import expected_conditions as EC | ||
#from features.environment import browserstack | ||
from selenium.webdriver.common.by import By | ||
from selenium.common.exceptions import TimeoutException | ||
|
||
|
||
class Utils: | ||
|
||
def find_and_click(context, locator_generic, wait_time=60): | ||
try: | ||
element = WebDriverWait(context.browser, wait_time).until(EC.visibility_of_element_located(locator_generic)) | ||
element.click() | ||
except TimeoutException as e: | ||
print(f"Elemento não encontrado dentro do tempo limite de {wait_time} segundos.") | ||
except Exception as e: | ||
print(f"Ocorreu um erro ao clicar no elemento: {e}") | ||
def find_and_send(context, locator_generic, text, wait_time=60): | ||
try: | ||
WebDriverWait(context.browser, wait_time).until(EC.visibility_of_element_located(locator_generic)).send_keys(text) | ||
except Exception as e: | ||
pass | ||
|
||
def substituir_mapeamento(context, locator, texto, regex='%.*%'): | ||
if isinstance(locator, tuple) and len(locator) == 2 and locator[0] == By.XPATH: | ||
xpath = locator[1] | ||
novo_locator = (By.XPATH, re.sub(re.escape(regex), texto, xpath)) | ||
print(novo_locator) | ||
return novo_locator | ||
else: | ||
raise TypeError("O argumento 'locator' não é um objeto By com XPath.") | ||
|
||
#return locator | ||
def find_and_return_text(context, locator, wait_time=60): | ||
try: | ||
wait = WebDriverWait(context.browser, wait_time) | ||
element = None | ||
|
||
try: | ||
element = wait.until(EC.presence_of_element_located((locator))) | ||
except: | ||
element = wait.until(EC.presence_of_element_located((locator))) | ||
|
||
if element: | ||
element_text = element.text | ||
print(element_text) | ||
else: | ||
return None | ||
except Exception as e: | ||
print(f"Erro: {str(e)}") | ||
return None | ||
# def click_elemento(context,locator_generic): | ||
# try: | ||
# context.find_and_click(context, locator_generic) | ||
# except: | ||
# print(f'Não foi encontrado ou não é apresentado na versão mobile/desktop') | ||
|
||
# def limpar_campo(context, locator): | ||
# context.webdriver.execute_script('arguments[0].value = "";', context.achar_elemento(locator)) | ||
|
||
def achar_elemento(context, locator): | ||
try: | ||
return context.webdriver.find_element(*locator) | ||
except: | ||
raise NoSuchElementException() | ||
def resolucao_notebook(context): | ||
context.webdriver.set_window_size(1382, 768) | ||
|
||
def resolucao_desktop(context): | ||
context.webdriver.set_window_size(1940, 1080) | ||
|
||
|
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,7 @@ | ||
Feature: teste | ||
|
||
Scenario: teste | ||
Given que eu esteja na pagina | ||
When faco login usando o documento | ||
When Aceitar cookies e recusar pesquisa e tour | ||
Then acessou |