1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-27 08:12:47 +01:00
openstamanager/tests/_support/Helper/Acceptance.php

135 lines
3.1 KiB
PHP
Raw Normal View History

2018-08-03 17:19:45 +02:00
<?php
2018-08-03 19:11:45 +02:00
2018-08-03 17:19:45 +02:00
namespace Helper;
// here you can define custom actions
2018-08-03 19:11:45 +02:00
// all public methods declared in helper class will be available in $t
2018-08-03 17:19:45 +02:00
class Acceptance extends \Codeception\Module
{
2018-08-03 19:23:55 +02:00
/**
* Effettua il login dalla pagina principale.
*
* @param string $username
* @param string $password
*/
2018-08-03 19:11:45 +02:00
public function login($username, $password)
{
$t = $this->getAcceptanceModule();
2018-08-04 09:40:03 +02:00
if ($t->loadSessionSnapshot('login')) {
return;
}
2018-08-13 10:01:15 +02:00
// Operazioni di login
2018-08-03 19:11:45 +02:00
$t->amOnPage('/');
$t->fillField('username', $username);
$t->fillField('password', $password);
$this->clickAndWait('Accedi');
2018-08-04 09:40:03 +02:00
2018-08-13 10:01:15 +02:00
// Controlla il completamento del login
2018-08-04 09:40:03 +02:00
$t->see($username, '.user-panel');
$t->saveSessionSnapshot('login');
2018-08-13 10:01:15 +02:00
// Rimozione barra di debug
$t->executeJS('$(".phpdebugbar-close-btn").click()');
2018-08-03 19:11:45 +02:00
}
2018-08-03 19:23:55 +02:00
/**
* Clicca sul pulsante e attende la conclusione del caricamento.
*
* @param $link
* @param $context
*/
2018-08-03 19:11:45 +02:00
public function clickAndWait($link, $context = null)
{
$t = $this->getAcceptanceModule();
$t->click($link, $context);
$t->waitForElementNotVisible('#main_loading');
}
2018-08-03 19:23:55 +02:00
/**
* Clicca sul pulsante e attende la conclusione del caricamento del modal.
*
* @param $link
* @param $context
*/
2018-08-03 19:11:45 +02:00
public function clickAndWaitModal($link, $context = null)
{
$t = $this->getAcceptanceModule();
$this->clickAndWait($link, $context);
$t->waitForElementVisible('.modal');
}
2018-08-04 09:40:03 +02:00
/**
* Clicca sul pulsante dentro il modal.
*
* @param $link
*/
public function clickModalButton($link)
{
$t = $this->getAcceptanceModule();
$this->clickAndWait($link, '.modal-content');
}
/**
* Clicca sul pulsante e attende la conclusione del caricamento del modal SWAL.
*
* @param $link
* @param $context
*/
public function clickAndWaitSwal($link, $context = null)
{
$t = $this->getAcceptanceModule();
$this->clickAndWait($link, $context);
$t->waitForElementVisible('.swal2-modal');
}
/**
* Clicca sul pulsante dentro il modal SWAL.
*
* @param $link
*/
public function clickSwalButton($link)
{
$t = $this->getAcceptanceModule();
$this->clickAndWait($link, '.swal2-buttonswrapper');
}
2018-08-03 19:23:55 +02:00
/**
* Imposta il valore di un select gestito dal framework Select2.
*
* @param $selector
* @param $option
* @param int $timeout seconds. Default to 1
*/
2018-08-03 19:11:45 +02:00
public function select2($selector, $option, $timeout = 5)
{
$select2 = $this->getModule('\Helper\Select2');
$select2->openSelect2($selector);
$select2->selectOptionForSelect2($selector, $option, $timeout);
$select2->closeSelect2($selector);
}
protected function getAcceptanceModule()
{
if (!$this->hasModule('WebDriver')) {
throw new \Exception('You must enable the WebDriver module', 1);
}
2018-08-03 17:19:45 +02:00
2018-08-03 19:11:45 +02:00
return $this->getModule('WebDriver');
}
2018-08-03 17:19:45 +02:00
}