2013-02-19 295 views
3

在硒IDE中,我已经构建了一个测试用例,其中一个数组变量存储值。我用while循环来打印这些数组变量。selenium IDE循环通过数组变量

enter image description here

在这里,我曾用 “getEval | myArray的[0]”,打印的第一个值是'PostgreSQL的。但该值未列出。没有错误发生。

[info] Executing: |getEval | myarray = new Array('postgresql','mysql'); | | 
[info] script is: myarray = new Array('postgresql','mysql'); 
[info] Executing: |getEval | index=0; | | 
[info] script is: index=0; 
[info] Executing: |while | index < myarray.length; | | 
[info] Executing: |getEval | myarray[0] | mynewvalue | 
[info] script is: myarray[0] 
[info] Executing: |echo | ${mynewvalue} | | 
[info] echo: ${mynewvalue} 
[info] Executing: |getEval | index++; | | 
[info] script is: index++; 
[info] Executing: |endWhile | | | 
[info] Executing: |while | index < myarray.length; | | 
[info] Executing: |getEval | myarray[0] | mynewvalue | 
[info] script is: myarray[0] 
[info] Executing: |echo | ${mynewvalue} | | 
[info] echo: ${mynewvalue} 
[info] Executing: |getEval | index++; | | 
[info] script is: index++; 
[info] Executing: |endWhile | | | 
[info] Executing: |while | index < myarray.length; | | 

现在再次在相同的测试情况下,我已经改变了 “getEval | myArray的[0]” 为“getEval | myArray的[$ {索引}]通过循环索引列出数组值

enter image description here

现在我得到以下错误:

[info] Executing: |getEval | myarray = new Array('postgresql','mysql'); | | 
[info] script is: myarray = new Array('postgresql','mysql'); 
[info] Executing: |getEval | index=0; | | 
[info] script is: index=0; 
[info] Executing: |while | index < myarray.length; | | 
[info] Executing: |getEval | myarray[${index}] | mynewvalue | 
[info] script is: myarray[${index}] 
[error] Threw an exception: missing ] in index expression 

所有我需要的是回声打印“的PostgreSQL”和“mysql的”是独立的新线 我是硒新的很新,可以帮助我解决这个问题。

回答

6

这为我做的伎俩,希望它可以帮助别人太...

enter image description here

[info] Executing: |storeEval | new Array("postgresql","mysql"); | myarray 
[info] script is: new Array("postgresql","mysql"); 
[info] Executing: |getEval | index=0; 
[info] script is: index=0; 
[info] Executing: |while | index < storedVars['myarray'].length; 
[info] Executing: |storeEval | index | temp 
[info] script is: index 
[info] Executing: |echo | javascript{storedVars['myarray'][storedVars['temp']]} 
[info] echo: postgresql 
[info] Executing: |getEval | index++; 
[info] script is: index++; 
[info] Executing: |endWhile | | | 
[info] Executing: |while | index < storedVars['myarray'].length; | 
[info] Executing: |storeEval | index | temp | 
[info] script is: index 
[info] Executing: |echo | javascript{storedVars['myarray'][storedVars['temp']]} 
[info] echo: mysql 
[info] Executing: |getEval | index++; | | 
[info] script is: index++; 
[info] Executing: |endWhile | | | 
[info] Executing: |while | index < storedVars['myarray'].length; 

这里是HTML源上面的剪切和粘贴:

<tr> 
<td>storeEval</td> 
<td>new Array(&quot;postgresql&quot;,&quot;mysql&quot;);</td> 
<td>myarray</td> 
</tr> 
<tr> 
<td>getEval</td> 
<td>index=0;</td> 
<td></td> 
</tr> 
<tr> 
<td>while</td> 
<td>index &lt; storedVars['myarray'].length</td> 
<td></td> 
</tr> 
<tr> 
<td>storeEval</td> 
<td>index</td> 
<td>temp</td> 
</tr> 
<tr> 
<td>echo</td> 
<td>javascript{storedVars['myarray'][storedVars['temp']]}</td> 
<td></td> 
</tr> 
<tr> 
<td>getEval</td> 
<td>index++;</td> 
<td></td> 
</tr> 
<tr> 
<td>endWhile</td> 
<td></td> 
<td></td> 
</tr>