自動化測試 - selenium Q&A

最近在用selenium給項目添加自動化測試模塊,遇到以下問題以及解決辦法,backup,也許以後還會用到。

 

Q1 :  Some elements id is generated automatically ext-gen in JS code, when the script run in the second times, the id recorded in the first time could not be found.

 

A1 : There are two solutions here,

  1. Add fixed id for the elements you are going to test in source code instead of being generated automatically.
  2. Use the parent node to identify a location and then using tag as road map to index to where you want. For example,

Target = ext-gen112

Can be changed into,

Target = //div[@id='testJsonsMenu']/ul/li[3]/a/span

 

We use a fix id testJsonsMenu to identify one location, then go down to find the element in the tree.

 

 

Q2 : Because of network slowness or application performance issue, sometimes, page response was not so quick that popup menu has not come out. So when selenium to run the next step, some element might not be found, missing error occur.

 

A2 : Tow solutions,

  1. Let selenium know the application was not that fast-run. If you are in selenium IDE, you could just drag slider from fast to slow in the main page.
  2. If you are in the programming code, you could set wait() or speed. I like the second one, for example, in java,

selenium .setSpeed( "1000" ); time unit is millisecond,

 

This means every step in your code will be run behind 1 second after the previous step is simulated.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章