Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
phpunit_Selenium2中的全局变量_Php_Selenium_Phpunit - Fatal编程技术网

phpunit_Selenium2中的全局变量

phpunit_Selenium2中的全局变量,php,selenium,phpunit,Php,Selenium,Phpunit,我有一个数组,其中的名称用于生成表单中的随机名称,我想在多个函数中使用它 class TestMyTest extends PHPUnit_Extensions_Selenium2TestCase { public function setUp() { $this->setHost('localhost'); $this->setPort(4444); $this->setBrowser("firefox"); $this->setBrowserUrl("xxxxxxxx

我有一个数组,其中的名称用于生成表单中的随机名称,我想在多个函数中使用它

class TestMyTest extends PHPUnit_Extensions_Selenium2TestCase {
public function setUp()
{
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowser("firefox");
$this->setBrowserUrl("xxxxxxxxxxxxxxxxxx");
}
    public $firstNameArray = array(
    "Howard",
    "Sheldon",
    "Leonard",
    "Rajesh"
    );

    public $lastNameArray = array(
    "Wolowitz",
    "Cooper",
    "Hofstadter",
    "Koothrappali"
    );


public function testCreateNewCustomer()
{

    $name = rand(0,count($firstNameArray));
    $this->byId('customer-name')->value($firstNameArray[$name].' '.$lastNameArray[$name]);
    $random_phone_nr = rand(1000000,9999999);   
    $this->byId('customer-phone')->value('070'.$random_phone_nr);
    $this->byId('customer-email')->value($firstNameArray[$name].'.'.$lastNameArray[$name].'@testcomp.com');
}

这会在声明$name variabel的行中出现错误“Undefined variable:firstNameArray”。我不想在我想使用的每个函数中都声明相同的数组。那么我该如何解决这个问题呢?

它不是一个全局变量,而是一个类/实例变量:

$this->byId('customer-name')->value($this->firstNameArray[$name].' '.$this->lastNameArray[$name]);
$this->byId('customer-email')->value($this->firstNameArray[$name].'.'.$this->lastNameArray[$name].'@testcomp.com');
编辑

对不起,我错过了另一个参考:

$name = rand(0,count($this->firstNameArray)-1);

我仍然收到一个错误,但在同一行上有一个不同的错误“无法访问空属性”。是的,我知道,当然我用$FIRSTNAMEARRY pressent编辑了所有行到$this->$FIRSTNAMEARRY。您的rand()应该在0到count-1之间,而不是在0到count之间抱歉,如果我使用固定数字,因为我不知道数组有多大,现在我得到了老警告,“Undefined variable”哦,对不起,错过了你删除了数组名前面的变量防御,顺便说一句,为什么?为什么它使用$this->firstNameArray byt而不是$this->$firstNameArray;?为什么要通过类变量使用此数据?我认为你应该考虑使用DATAL提供程序(),或者简单地把这个日期放在测试方法中。