Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
michield committed Jan 7, 2024
1 parent c3963a4 commit 1d5d9a8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 167 deletions.
196 changes: 60 additions & 136 deletions tests/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
<?php
use Behat\Mink\Exception\DriverException;
use Behat\Mink\Selector\Xpath\Escaper;
use WebDriver\Element;
use \Behat\Mink\Element\NodeElement;
use WebDriver\Exception\NoSuchElement;
use WebDriver\Exception\UnknownCommand;
use WebDriver\Exception\UnknownError;
use WebDriver\Exception;
use WebDriver\Key;
use WebDriver\WebDriver;
use WebDriver\Exception\UnexpectedAlertOpen;

use Behat\Behat\Context\Context;

use Behat\Mink\Exception\ExpectationException;
use Behat\MinkExtension\Context\MinkContext;
use Behat\MinkExtension\Context\RawMinkContext;

use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception\ResponseTextException;
use Behat\Mink\Exception\ElementNotFoundException;
use WebDriver\Exception\StaleElementReference;
use Behat\Behat\Tester\Exception\PendingException;


//
// Require 3rd-party libraries here:
//
// require_once 'PHPUnit/Autoload.php';
// require_once 'PHPUnit/Framework/Assert/Functions.php';
//
use Behat\MinkExtension\Context\MinkContext;

/**
* Features context.
Expand Down Expand Up @@ -85,6 +56,7 @@ public function __call($method, $parameters)
'The "%s()" method does not exist.', $method
));
}

/**
* Everyone who tried Behat with Mink and a JavaScript driver (I use
* Selenium2Driver with phantomjs) has had issues with trying to assert something
Expand Down Expand Up @@ -116,6 +88,7 @@ protected function throwExpectationException($message)
{
throw new ExpectationException($message, $this->getSession());
}

/**
* @When something long is taking long but should output :text
*/
Expand All @@ -139,17 +112,7 @@ public function doSomethingNotThereYet()
$button->click();
});
}
//
// Place your definition and hook methods here:
//
// /**
// * @Given /^I have done something with "([^"]*)"$/
// */
// public function iHaveDoneSomethingWith($argument)
// {
// doSomethingWith($argument);
// }
//

/**
* @Given /^I have logged in as an administrator$/
*/
Expand Down Expand Up @@ -197,13 +160,15 @@ public function iFillInWithAValidUsername($arg1)
{
$this->fillField($arg1, $this->params['admin_username']);
}

/**
* @When I fill in :arg1 with a valid password
*/
public function iFillInWithAValidPassword($arg1)
{
$this->fillField($arg1, $this->params['admin_password']);
}

/**
* @When /^I fill in "([^"]*)" with an email address$/
*/
Expand All @@ -212,6 +177,7 @@ public function iFillInWithAnEmailAddress($fieldName)
$this->data['email'] = '[email protected]'; // at some point really make random
$this->fillField($fieldName, $this->data['email']);
}

/**
* @Given I fill in :arg1 with :arg2 emails
*/
Expand All @@ -224,34 +190,14 @@ public function iFillInWithEmails($arg1, $arg2)
$this->fillField($arg1, $content);
}


/**
* @Given /^I should see the email address I entered$/
*/
public function iShouldSeeTheEmailAddressIEntered()
{
$this->assertSession()->pageTextContains($this->data['email']);
}
/**
* @Given /^No campaigns yet exist$/
*/
public function iHaveNotYetCreatedCampaigns()
{
// Count the number of campaigns in phplist_message table
$result = mysqli_fetch_assoc(
mysqli_query(
$this->db,'
select
count(*) as count
from
phplist_message;
')
);
$campaignCount = $result['count'];
if ($campaignCount > 0) {
$this->throwExpectationException('One or more campagins already exist');
}
}

/**
* @Given /^I have subscriber with email "([^"]*)"/
*/
Expand All @@ -260,14 +206,6 @@ public function iHaveSubscriber($email)
$this->clickLink('S');
}

/**
* @return mysqli
*/
public function getMysqli()
{
return $this->db;
}

/**
* @var array $params
* @return string
Expand Down Expand Up @@ -304,34 +242,19 @@ public function iWaitForTheAjaxResponse()
$this->getSession()->wait(5000, '(0 === jQuery.active)');
}

/**
* @When I switch to iframe :arg1
*/
public function iSwitchToIframe($arg1)
{ $arg1=$this->find("css",'cke_wysiwyg_frame cke_reset');
$this->getSession()->switchToIFrame($arg1);

}

/**
* Go back to main document frame.
*
* @When (I )switch to main frame
*/
public function switchToMainFrame()
{
$this->getSession()->getDriver()->switchToDefaultContent();
}

/**
* @Then I click on :arg1
*/
public function iClickOn($arg1)
{ $arg1= $this->find("css",'submit btn btn-primary');
$this->getSession()->click($arg1);
{
$arg1= $this->find("css",'submit btn btn-primary');
$this->getSession()->click($arg1);
}
/**

/**
* @When I enter text :arg1
*
* requires the CKEDITOR, which is not there by default
*/
public function iEnterText($arg1)
{
Expand All @@ -340,10 +263,11 @@ public function iEnterText($arg1)
(function(){
CKEDITOR.instances.message.setData( '<p>This is the editor data.</p>' ); })();
JS;
//$this->getSession()->executeScript("document.body.innerHTML = '<p>".$arg1."</p>'");}
$this->getSession()->evaluateScript($script);
//$this->getSession()->executeScript("document.body.innerHTML = '<p>".$arg1."</p>'");}
$this->getSession()->evaluateScript($script);
}
/**

/**
* @Then I should read :arg1
*/
public function iShouldRead($arg1)
Expand All @@ -353,32 +277,31 @@ public function iShouldRead($arg1)
CKEDITOR.instances.message.getData();})();
JS;
$this->getSession()->evaluateScript($script);
$this->getSession()->evaluateScript($script);
}
/**

/**
* @Then :arg1 checkbox should be checked
*/

/**

/**
* @Then /^Radio button with id "([^"]*)" should be checked$/
*/
public function RadioButtonWithIdShouldBeChecked($sId)
{
$elementByCss = $this->getSession()->getPage()->find('css', 'input[type="radio"]:checked#'.$sId);
// if (!$elementByCss) {
// throw new Exception('Radio button with id ' . $sId.' is not checked');
// }
}

/**
public function RadioButtonWithIdShouldBeChecked($sId)
{
$elementByCss = $this->getSession()->getPage()->find('css', 'input[type="radio"]:checked#'.$sId);
}

/**
* @When I switch back from iframe
*/
public function iSwitchBackFrom($name=null)
{
$this->getSession()->getDriver()->switchToIframe(null);
}

/**
/**
* @Then I switch to other iframe :arg1
*/
public function iSwitchToOtherIframe($arg1)
Expand All @@ -399,7 +322,7 @@ public function iMouseOver($arg1)
$findName->mouseOver();
}
}
/**
/**
* @Given I click over :arg1
*/
public function iClickOver($arg1)
Expand All @@ -410,45 +333,45 @@ public function iClickOver($arg1)
}

/**
* @Given I write :text into :field
*/
public function iWriteTextIntoField($text, $field)
{
$field = $this->getSession()
->getDriver()
->getWebDriverSession()
->element('xpath', '//*[@id="edit_list_categories"]/div/input');
$field->postValue(['value' => [$text]]);
}
* @Given I write :text into :field
*/
public function iWriteTextIntoField($text, $field)
{
$field = $this->getSession()
->getDriver()
->getWebDriverSession()
->element('xpath', '//*[@id="edit_list_categories"]/div/input');
$field->postValue(['value' => [$text]]);
}


/**
* @Given I go back
*/
/**
* @Given I go back
*/
public function iGoBack()
{
$this->getSession()->getDriver()->back();
}

/**
* @When I confirm the popup
*/
/**
* @When I confirm the popup
*/
public function iConfirmThePopup()
{
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
}

/**
* @Given I go back to :arg1
*/
/**
* @Given I go back to :arg1
*/
public function iGoBackTo($page)
{
$this->getSession()->getDriver()->back();
}

/**
* @Then The header color should be black
*/
/**
* @Then The header color should be black
*/
public function theDivContextMenuBlockMenuColorShouldBeBlack()
{

Expand All @@ -464,12 +387,13 @@ public function theDivContextMenuBlockMenuColorShouldBeBlack()
throw new Exception();
}
}
/**
* @Then I should see :message on popups
*/

/**
* @Then I should see :message on popups
*/
public function iShouldSeeOnPopups($message)
{ return $message == $this->getSession()->getDriver()->getWebDriverSession()->getAlert_text();

{
return $message == $this->getSession()->getDriver()->getWebDriverSession()->getAlert_text();
}

}
29 changes: 0 additions & 29 deletions tests/features/bootstrap/ScreenshotContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,6 @@ public function takeAScreenshot()
print sprintf("Screenshot is available :\n%s", $url);
}

protected function getScreenshotUrl($filename)
{
if (!self::$wsendUser) {
self::$wsendUser = $this->getWsendUser();
}

exec(sprintf(
'curl -F "uid=%s" -F "filehandle=@%s" %s 2>/dev/null',
self::$wsendUser,
$filename,
'https://wsend.net/upload_cli'
), $output, $return);

return $output[0];
}

protected function getWsendUser()
{
// create a wsend anonymous user
$curl = curl_init('https://wsend.net/createunreg');
curl_setopt($curl, CURLOPT_POSTFIELDS, 'start=1');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$wsendUser = curl_exec($curl);
curl_close($curl);

return $wsendUser;
}

protected function getScreenshotFilename()
{
$filename = $this->scenarioTitle;
Expand Down
2 changes: 0 additions & 2 deletions tests/features/bootstrap/SubscriberContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ public function iHaveList($name, $owner = null, $description=null)

}



/**
* @Given /I want to send campaign with title "(.*)"/
*/
Expand Down

0 comments on commit 1d5d9a8

Please sign in to comment.