HOR-3373
+ Fix web entry login bloqued when session_block configuration is enabled. + Include behat test.
This commit is contained in:
152
features/bootstrap/Browser.php
Normal file
152
features/bootstrap/Browser.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
use Behat\Mink\Session;
|
||||
|
||||
/**
|
||||
* Window
|
||||
*/
|
||||
class Browser extends Session
|
||||
{
|
||||
/**
|
||||
* Time to wait before use after selecting an element.
|
||||
* To avoid click or get information about an element that
|
||||
* is still beeing proceesed by javascript.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $waitForJavascriptProcessing=500;
|
||||
|
||||
/**
|
||||
* Get an element by id.
|
||||
*
|
||||
* @param string $id
|
||||
* @return \Behat\Mink\Element\NodeElement
|
||||
*/
|
||||
public function getElementByXpath($xpath, $wait = true)
|
||||
{
|
||||
$wait ? $this->waitFor($xpath) : null;
|
||||
$found = $this->getDriver()->find($xpath);
|
||||
return $found ? $found[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an element by id.
|
||||
*
|
||||
* @param string $id
|
||||
* @return \Behat\Mink\Element\NodeElement
|
||||
*/
|
||||
public function getElementById($id, $wait = true)
|
||||
{
|
||||
$xpath = "//*[@id=".
|
||||
$this->encodeXpathString($id).
|
||||
"]";
|
||||
$wait ? $this->waitFor($xpath) : null;
|
||||
$found = $this->getDriver()->find($xpath);
|
||||
return $found ? $found[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the elements that contains and specific text.
|
||||
*
|
||||
* @param string $textContent
|
||||
* @return \Behat\Mink\Element\NodeElement[]
|
||||
*/
|
||||
public function getElementsByTextContent(
|
||||
$textContent,
|
||||
$base = '//*',
|
||||
$wait = true
|
||||
) {
|
||||
$xpath = $base.
|
||||
"[contains(., ".
|
||||
$this->encodeXpathString($textContent).
|
||||
")]";
|
||||
$wait ? $this->waitFor($xpath) : null;
|
||||
return $this->getDriver()->find($xpath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes and string to be used inside an xpath expression.
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public function encodeXpathString($string)
|
||||
{
|
||||
if (strpos($string, '"') !== false && strpos($string, "'") !== false) {
|
||||
$parts = preg_split(
|
||||
'/(\'|")/', $string, -1,
|
||||
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
|
||||
);
|
||||
$encoded = [];
|
||||
foreach ($parts as $str) {
|
||||
$encoded[] = $this->encodeXpathString($str);
|
||||
}
|
||||
return 'concat('.implode(',', $encoded).')';
|
||||
} elseif (strpos($string, '"') !== false) {
|
||||
return "'".$string."'";
|
||||
} else {
|
||||
return '"'.$string.'"';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until elements defined with a xpath expression are present.
|
||||
*
|
||||
* @param string $xpath
|
||||
* @param int $time
|
||||
*/
|
||||
public function waitFor($xpath, $time = 5000)
|
||||
{
|
||||
$jxpath = json_encode($xpath);
|
||||
$condition = 'document.evaluate('.$jxpath.', document, null, XPathResult.ANY_TYPE, null).iterateNext()!==null';
|
||||
$this->wait($time, $condition);
|
||||
//Wait for javascript event handlers
|
||||
$this->wait($this->waitForJavascriptProcessing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last element that match a text.
|
||||
*
|
||||
* @param string $text
|
||||
* @return \Behat\Mink\Element\NodeElement
|
||||
*/
|
||||
public function getElementByTextContent($text, $cssClass = '')
|
||||
{
|
||||
if ($cssClass) {
|
||||
$base = '//*[contains(@class, '.$this->encodeXpathString($cssClass).')]';
|
||||
} else {
|
||||
$base = '//*';
|
||||
}
|
||||
$tags = $this->getElementsByTextContent($text, $base);
|
||||
return $tags ? $tags[count($tags) - 1] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last element that match a text.
|
||||
*
|
||||
* @param string $text
|
||||
* @return \Behat\Mink\Element\NodeElement
|
||||
*/
|
||||
public function getElementByValue($selector, $value)
|
||||
{
|
||||
$base = '//'.$selector;
|
||||
$tags = $this->getDriver()->find($base);
|
||||
$regexp = '/'.str_replace('\*', '.*', preg_quote($value, '/')).'/';
|
||||
foreach ($tags as $tag) {
|
||||
if (preg_match($regexp, $tag->getValue())) {
|
||||
return $tag;
|
||||
}
|
||||
}
|
||||
return $tags ? $tags[count($tags)-1] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Session ID of WebDriver or `null`, when session not started yet.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getWebDriverSessionId()
|
||||
{
|
||||
return $this->getDriver()->getWebDriverSessionId();
|
||||
}
|
||||
}
|
||||
@@ -1,67 +1,248 @@
|
||||
<?php
|
||||
|
||||
use Behat\Behat\Context\ClosuredContextInterface,
|
||||
Behat\Behat\Context\TranslatedContextInterface,
|
||||
Behat\Behat\Context\BehatContext,
|
||||
Behat\Behat\Exception\PendingException;
|
||||
use Behat\Gherkin\Node\PyStringNode,
|
||||
Behat\Gherkin\Node\TableNode;
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Behat\Hook\Scope\AfterScenarioScope;
|
||||
|
||||
require 'config.php';
|
||||
|
||||
//
|
||||
// Require 3rd-party libraries here:
|
||||
//
|
||||
// require_once 'PHPUnit/Autoload.php';
|
||||
// require_once 'PHPUnit/Framework/Assert/Functions.php';
|
||||
//
|
||||
require_once 'config.php';
|
||||
/**
|
||||
* Features context.
|
||||
* Defines application features from the specific context.
|
||||
*/
|
||||
class FeatureContext extends BehatContext
|
||||
class FeatureContext extends WorkflowTestCase implements Context
|
||||
{
|
||||
/**
|
||||
* Initializes context.
|
||||
* Every scenario gets it's own context object.
|
||||
*
|
||||
* @param array $parameters context parameters (set them up through behat.yml)
|
||||
* @var Browser $browser
|
||||
*/
|
||||
public function __construct(array $parameters)
|
||||
protected $browser;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string $clipboard
|
||||
*/
|
||||
protected $clipboard;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array $parameters
|
||||
*/
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* Initializes context.
|
||||
*
|
||||
* Every scenario gets its own context instance.
|
||||
* You can also pass arbitrary arguments to the
|
||||
* context constructor through behat.yml.
|
||||
*/
|
||||
public function __construct($parameters)
|
||||
{
|
||||
// Initialize your context here
|
||||
$this->useContext('RestContext', new RestContext($parameters));
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/** @AfterScenario */
|
||||
public function after(AfterScenarioScope $scope)
|
||||
{
|
||||
//Close the browser if it was opened.
|
||||
$this->closeTheBrowser();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I run "([^"]*)"$/
|
||||
* @Given a new workspace
|
||||
*/
|
||||
public function iRun($command)
|
||||
public function aNewWorkspace()
|
||||
{
|
||||
exec($command, $result);
|
||||
$this->output = $result;
|
||||
|
||||
$this->setupDB();
|
||||
$this->installLicense(__DIR__.'/../resources/license_*.dat');
|
||||
$this->config(['CFG_UID' => 'getStarted', 'CFG_VALUE' => '1']);
|
||||
$this->setTranslation('ID_INVALID_VALUE_CAN_NOT_BE_EMPTY',
|
||||
'ID_INVALID_VALUE_CAN_NOT_BE_EMPTY({0})');
|
||||
$this->setTranslation('ID_UNDEFINED_VALUE_IS_REQUIRED',
|
||||
'ID_UNDEFINED_VALUE_IS_REQUIRED({0})');
|
||||
$this->setTranslation('ID_WEB_ENTRY_EVENT_DOES_NOT_EXIST',
|
||||
'ID_WEB_ENTRY_EVENT_DOES_NOT_EXIST({0})');
|
||||
$this->setTranslation('ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES',
|
||||
'ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES({0},{1})');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^I should see the file "([^"]*)"$/
|
||||
* @Then Config env.ini with :arg1
|
||||
*/
|
||||
public function iShouldSeeTheFile($fileName)
|
||||
public function configEnvIniWith($arg1)
|
||||
{
|
||||
if (!in_array($fileName, $this->output)) {
|
||||
throw new Exception('File named ' . $fileName . ' not found!');
|
||||
$args = explode("=", $arg1);
|
||||
$name = trim($args[0]);
|
||||
$value = isset($args[1]) ? trim($args[1]) : '';
|
||||
$this->setEnvIni($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Config env.ini without :arg1
|
||||
*/
|
||||
public function configEnvIniWithout($arg1)
|
||||
{
|
||||
$this->unsetEnvIni($arg1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given Import process :arg1
|
||||
*/
|
||||
public function importProcess($arg1)
|
||||
{
|
||||
$this->import(__DIR__.'/../resources/'.$arg1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Go to Processmaker login
|
||||
*/
|
||||
public function goToProcessmakerLogin()
|
||||
{
|
||||
$session = $this->browser;
|
||||
$session->visit($this->getBaseUrl('login/login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Login as :arg1 :arg2
|
||||
*/
|
||||
public function loginAs($arg1, $arg2)
|
||||
{
|
||||
$session = $this->browser;
|
||||
$username = $session->getElementById('form[USR_USERNAME]');
|
||||
$username->setValue('admin');
|
||||
$password = $session->getElementById('form[USR_PASSWORD_MASK]');
|
||||
$password->setValue('admin');
|
||||
$submit = $session->getElementById('form[BSUBMIT]');
|
||||
$submit->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When Inside :arg1
|
||||
*/
|
||||
public function inside($arg1)
|
||||
{
|
||||
$this->browser->switchToIFrame($arg1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Copy :arg1 of :arg2
|
||||
*/
|
||||
public function copyOf($arg1, $arg2)
|
||||
{
|
||||
$element = $this->browser->getElementByXpath($arg2);
|
||||
$this->clipboard = $element->getAttribute($arg1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Double click on :arg1
|
||||
*/
|
||||
public function doubleClickOn($arg1)
|
||||
{
|
||||
$process = $this->browser->getElementByTextContent($arg1);
|
||||
$process->doubleClick();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Right click on :arg1
|
||||
*/
|
||||
public function rightClickOn($arg1)
|
||||
{
|
||||
$this->browser->getElementByTextContent($arg1)->rightClick();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Click on :arg1 inside :arg2
|
||||
*/
|
||||
public function clickOnInside($arg1, $arg2)
|
||||
{
|
||||
$this->browser->getElementByTextContent($arg1, $arg2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Copy value of :arg1 like :arg2
|
||||
*/
|
||||
public function copyValueOfLike($arg1, $arg2)
|
||||
{
|
||||
$this->clipboard = $this->browser->getElementByValue($arg1, $arg2)->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Logout Processmaker
|
||||
*/
|
||||
public function logoutProcessmaker()
|
||||
{
|
||||
$this->browser->visit($this->getBaseUrl('login/login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then open url copied
|
||||
*/
|
||||
public function openUrlCopied()
|
||||
{
|
||||
$this->browser->visit($this->clipboard);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Verify the page does not redirect to the standard \/login\/login
|
||||
*/
|
||||
public function verifyThePageDoesNotRedirectToTheStandardLoginLogin()
|
||||
{
|
||||
$this->assertEquals($this->clipboard, $this->browser->getCurrentUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Verify the page goes to the WebEntry steps
|
||||
*/
|
||||
public function verifyThePageGoesToTheWebentrySteps()
|
||||
{
|
||||
$this->assertLessThan(count($this->browser->getElementsByTextContent('Next Step')), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Open a browser
|
||||
*/
|
||||
public function openABrowser()
|
||||
{
|
||||
$this->browser = $this->openBrowser();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then close the browser
|
||||
*/
|
||||
public function closeTheBrowser()
|
||||
{
|
||||
if ($this->browser) {
|
||||
$sessionId = $this->browser->getWebDriverSessionId();
|
||||
$this->browser->wait(1000);
|
||||
$this->browser->stop();
|
||||
echo "Video available at:\n";
|
||||
echo $this->parameters['webDriverHost']."/grid/admin/HubVideoDownloadServlet?sessionId=".$sessionId;
|
||||
$this->browser = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Browser
|
||||
*/
|
||||
private function openBrowser()
|
||||
{
|
||||
$capabilities = $this->parameters['capabilities'];
|
||||
$capabilities['seleniumProtocol'] = "WebDriver";
|
||||
if (empty($capabilities['browserName'])) {
|
||||
$capabilities['browserName'] = 'chrome';
|
||||
}
|
||||
$driver = new \Behat\Mink\Driver\Selenium2Driver(
|
||||
$capabilities['browserName'],
|
||||
$capabilities,
|
||||
$this->parameters['webDriverHost'].'/wd/hub'
|
||||
);
|
||||
$session = new Browser($driver);
|
||||
$session->start();
|
||||
return $session;
|
||||
}
|
||||
|
||||
//
|
||||
// Place your definition and hook methods here:
|
||||
//
|
||||
// /**
|
||||
// * @Given /^I have done something with "([^"]*)"$/
|
||||
// */
|
||||
// public function iHaveDoneSomethingWith($argument)
|
||||
// {
|
||||
// doSomethingWith($argument);
|
||||
// }
|
||||
//
|
||||
public function __destruct()
|
||||
{
|
||||
$this->closeTheBrowser();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,3 +10,14 @@ $config = array (
|
||||
'refresh_token' => "ade174976fe77f12ecde7c9e1d8307ac495f443e",
|
||||
);
|
||||
|
||||
call_user_func(function() {
|
||||
$phpunit = new DOMDocument;
|
||||
$phpunit->load(__DIR__.'/../../phpunit.xml');
|
||||
|
||||
foreach($phpunit->getElementsByTagName('php') as $php) {
|
||||
foreach($php->getElementsByTagName('var') as $var) {
|
||||
$GLOBALS[$var->getAttribute("name")] = $var->getAttribute("value");
|
||||
}
|
||||
}
|
||||
});
|
||||
require __DIR__.'/../../tests/bootstrap.php';
|
||||
|
||||
Reference in New Issue
Block a user