public function pickOneRoom(\AcceptanceTester $I)
{
$I->wantTo('Pick a available room');
$I->fillField('body > div.mfp-wrap.mfp-close-btn-in.mfp-auto-cursor.mfp-desired-room.mfp-ready > div > div.mfp-content > div > div > div > div.mod-desired-room__filter > div.js-build-desired-choose-room > div.grid.js-desired-room-choose > div > div > div:nth-child(1) > div > input[type="text"]','400');
$this->checkFavRoom($I);
if ($I->see('Sorry try again') == true)
{
$I->fillField('body > div.mfp-wrap.mfp-close-btn-in.mfp-auto-cursor.mfp-desired-room.mfp-ready > div > div.mfp-content > div > div > div > div.mod-desired-room__filter > div.js-build-desired-choose-room > div.grid.js-desired-room-choose > div > div > div:nth-child(1) > div > input[type="text"]','400++');
}
}
This is I have come up with till now. I am new to php and not sure how to attack this Problem.
Problem
User Enters a Room number in a field, if that Room is taken, the sorry Message pops up.
This is what i am trying to achieve.
If the Room Nr. is taken so it has to increase by one and check again if its available. Checking is done by $this->checkFavRoom($I);
. Number starts at 400 and ends at 445. The Problem is adding one number everytime he sees that text, adding one to the field value, is the tricky part.
Any input is welcome. Thank you.
EDIT:
This is what i came up with, the Problem is that it will not do the second FillField, i really am clueless.
$I->wantTo('Pick a available room');
$I->fillField('body > div.mfp-wrap.mfp-close-btn-in.mfp-auto-cursor.mfp-desired-room.mfp-ready > div > div.mfp-content > div > div > div > div.mod-desired-room__filter > div.js-build-desired-choose-room > div.grid.js-desired-room-choose > div > div > div:nth-child(1) > div > input[type="text"]','400');
$this->checkFavRoom($I);
$I->wait(1);
if($I->See('Sorry try again') == false)
{
$this->submit($I);
}
else
{
$I->wait(1);
$I->fillField('body > div.mfp-wrap.mfp-close-btn-in.mfp-auto-cursor.mfp-desired-room.mfp-ready > div > div.mfp-content > div > div > div > div.mod-desired-room__filter > div.js-build-desired-choose-room > div.grid.js-desired-room-choose > div > div > div:nth-child(1) > div > input[type="text"]','402');
$I->wait(5);
$this->checkFavRoom($I);
$this->submit($I);
}
Answer if anyone ever needs it :)
You cannot use an action as a bool like this:
if($I->see('lorum ipsum')){/*do something*/}
You can branch the program flow by using try and catch blocks like this:
<?php
//Using a Codeception action to branch the flow of the script
//This Cept will always pass because the exception is caught
$I = new AcceptanceTester($scenario);
$I->amOnUrl("https://wordpress-bdd.com");
try
{
$I->see("Never for money, always for love.");
echo('This happens if the $I->see works');
}
catch(Exception $e)
{
echo('This happens if the $I->see fails');
}