Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
GCarin1 committed Nov 13, 2023
1 parent 4ed798c commit 4d2a9e3
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,7 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

config.yml
browserstack.yml
mapeamento.py
Binary file added drivers/chromedriver.exe
Binary file not shown.
32 changes: 32 additions & 0 deletions features/environment.py
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()
24 changes: 24 additions & 0 deletions features/pages/page_geral.py
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)
25 changes: 25 additions & 0 deletions features/steps/step_geral.py
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)

75 changes: 75 additions & 0 deletions features/steps/utils.py
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)


7 changes: 7 additions & 0 deletions features/teste.feature
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

0 comments on commit 4d2a9e3

Please sign in to comment.