2013-02-19 459 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>