I have used both Global and Static variables to make the value available in second call . but it gives me same error .
public function iCheckTimeStampofAjaxAndLite($Version,$Date)
{
$node = $this->getMainContext()->getSession()->getPage()->find('css', $Date);
print_r("Count:" .sizeof($node)); echo "\n";
$DateText=(string)$node->getText();
if ($Version=='Ajax'){
static $AjaxDate;
$AjaxDate=$DateText;
print_r("AjaxDate:" .$AjaxDate); echo "\n";
return;
}
else{
if ($AjaxDate==$DateText){
print_r("DateText:" .$DateText); echo "\n";
return;
}
else{
throw new Exception("Both Date are not Same");
}
}
}
1st call -> iCheckTimeStampofAjaxAndLite("Ajax","1.50pm");
2nd call -> iCheckTimeStampofAjaxAndLite("Lite","3.50pm");
Output : (Notice: Undefined variable: AjaxDate)
Declare your private $ajaxDate
in your class:
private $ajaxDate;
Also change:
//...
else{
if ($AjaxDate=$DateText){
print_r("DateText:" .$DateText); echo "\n";
return;
}
//...
into
//...
else if ($AjaxDate==$DateText){
print_r("DateText:" .$DateText); echo "\n";
return;
}
//...
You should not use static
for this, using properties of the class is much nicer.
You'll end up with something like this:
class FeatureContext
{
private $ajaxDate;
// ...
public function iCheckTimeStampofAjaxAndLite($Version,$Date)
{
// ...
$this->ajaxDate = ...; // set the ajax date
var_dump($this->ajaxDate); // use the ajax date
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.