2014年5月30日 星期五

Selenium - 如何移動『滑鼠』至隱藏的元件


今天偷到一點時間,繼續來研究selenium(再不研究會不敢改client了@@)。

遇到一個問題,例如這種常見的隱藏選單列:(圖片打馬賽克請見諒)

 MenuA,MenuB,MenuC是母選單,實際功能的子選單需將滑鼠移到各個母選單上才會在下方出現子選單:


今天我需要selenium模擬滑鼠移到其中的母選單『MenuB』,該怎麼做呢?
請參考如下片段:

        
 WebDriver _driver;
 //....
 WebElement element1 = _driver.findElement(By.xpath("//span[@id='MenuB']"));
 builder.moveToElement(element1).perform(); 

如上述,只要找到MenuB 母選單的element後,執行moveToElement()就可以了。

Cucumber - 使用時無法執行@Before 與 @After



最近開始嘗試使用cucumber + selenium,但測試的時候發現無法順利執行被
@Before或@After annotation標注的function,

原來當我們使用cucumber時,這些annotation的import位置為:

import cucumber.api.java.After;

import cucumber.api.java.Before;

而非JUNIT的
org.junit.After
org.junit.Before


雖然是小問題但沒想到還真要花些時間找呢~

2014年5月6日 星期二

JBOSS - web.xml中讀取環境變數

參考:JBOSS顧問

 如果我想要在web.xml設定環境變數可讀取,該怎麼做呢?參考以下的web.xml
  < web-app>
   
       
            log4jConfigLocation
            ${jboss.home.dir}/ap-config/xxxx/log4j.properties
      
   
  </ web-app>
如上述,我們希望在web.xml中指定log4j.properties的外部路徑,但需要使用環境變數讀取(避免不同客戶端機器安裝位置不同產生問題),
但在預設的JBOSS安裝是無法直接讀取的,修改方式很簡單,這裡以使用standalone的方式說明(若是使用domain就依照方式更改domain.xml就可)

找到${JBOSS_HOME}/standalone/configuration/standalone.xml,並找到以下片段(//profile/spec-descriptor-property-replacement):

        
            false
            true
        

重點就是spec-descriptor-property-replacement這個了,改成true,應該就可以順利運作了~

p.s跟有雄厚資金的客戶配合還是有好處的,因為他們有錢請顧問@@

2014年5月5日 星期一

Mybatis - if test dynamic sql出現 org.apache.ibatis.exceptions.PersistenceException : ###Error querying database. Cause: java.lang.NumberFormatException: For input string: "

參考:test expression throws NumberFormatException

今天使用mybatis if test出現個問題,原先使用如下:

 < select id="selectTable" parametertype="hashmap" resulttype="hashmap">
  select * from TABLE 
  
    
    < where>
      < if test="type == 'M' or type=='C' "> 
    
    ColA=#{volue} 
    < / if>
    < / where>  
        
  
 </ select> 

但卻出現了:

com.XXXX.util.exception.MIException: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.NumberFormatException: For input string: "M"

### Cause: java.lang.NumberFormatException: For input string: "M"

這就奇怪了,明明欲檢測的M與C應該是string怎會被轉換為number做檢查呢?
原來是"(雙引號)與'(單引號)解析的問題,改成如下:
 
< select id="selectTable" parametertype="hashmap" resulttype="hashmap">
  select * from TABLE 
  
  < where>
    < if test='type == "M" or type=="C" '> 
    
    ColA=#{volue} 
    < / if>
    < / where>        
  
</ select>
      

正常運作~ p.s話說就算使用了plugin貼xml語法還是會不正常啊...所以空格這種就自行刪除吧

2014年5月4日 星期日

JBOSS - 使用log4j失敗問題..

參考:Use my log4j under jboss 6

自從昨天移到JBOSS上後又發生怪問題...就是log問題。

因為客戶需求有各種不同的log,因此我利用點空閑時間將原本的log拆出區分為多個logger,
但怪問題發生了:

logger會時好時壞!!??

以下為我的log4j.properties:


log4j.rootLogger=DEBUG,total

log4j.appender.total=org.apache.log4j.FileAppender
log4j.logger.com.xxxx.mi.web.servlet.query=DEBUG,AOPLOG
log4j.logger.com.xxxx.mi.web.esb.util=DEBUG,AESBLOG
log4j.logger.com.xxxx.mi.web.omicard=DEBUG,AOMICARDLOG
log4j.logger.com.xxxx.mi.web.sql.mybatis=TRACE,ADBLOG


所謂的時好時壞就是,rootLogger一定是正常的,然而我其他定義的logger(如上com.xxxx.mi.web.servlet,logger.com.xxxx.mi.web.esb.util..這些),有時正常有時卻無法正確記錄,而且每次重啟jboss後正常或不正常的logger都不一定,
一開始以為是我的log4j.properties有問題,然而嘗試了半天實在找不到錯誤...後來看到以上參考網站,試者在tomcat上使用...果然tomcat一切正常,就只有jboss不正常。

後來找了些文章,好像jboss本身有自帶log,因此會衝突(?),先依照參考網站解決方式如下:


  1. 在META-INF下新增jboss-deployment-structure.xml,內容如下:

  2. 
      
        
            
            
        
      
    
    
  3. 更改JBOSS的設定:更改${JBOSS_HOME}/bin/standalone.bat(這裡使用win) 新增啟動參數-Dorg.jboss.as.logging.per-deployment=false:
    先找到以下這段:
    rem Setup JBoss specific properties 
    set "JAVA_OPTS=-Dprogram.name=%PROGNAME% %JAVA_OPTS% "
    


    更改為:
    rem Setup JBoss specific properties 
    set "JAVA_OPTS=-Dprogram.name=%PROGNAME% %JAVA_OPTS% -Dorg.jboss.as.logging.per-deployment=false"
    
  4. 重新啟動jboss,如果先前log4j的其餘部分沒有問題,應該就可以正常運作囉~~
這問題搞了我一天多....進度又整個延宕.............!@&^^$!@$@#

2014年5月3日 星期六

ESAPI - java.lang.reflect.InvocationTargetException....java.lang.ClassCastException: org.owasp.esapi.reference.Log4JLogger ...

參考: How to resolve the error "java.lang.reflect.InvocationTargetException"

今天ESAPI又出現了這個似曾相似(前篇)的錯誤:

org.owasp.esapi.errors.ConfigurationException: java.lang.reflect.InvocationTargetException HTTPUtilities class (org.owasp.esapi.reference.DefaultHTTPUtilities) CTOR threw exception.
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:129)
at org.owasp.esapi.ESAPI.httpUtilities(ESAPI.java:121)
at..
.....
Caused by: java.lang.ClassCastException: org.owasp.esapi.reference.Log4JLogger cannot be cast to org.owasp.esapi.Logger
at org.owasp.esapi.reference.Log4JLogFactory.getLogger(Log4JLogFactory.java:88)
at org.owasp.esapi.ESAPI.getLogger(ESAPI.java:154)
at org.owasp.esapi.reference.DefaultHTTPUtilities.<init>(DefaultHTTPUtilities.java:112)
at org.owasp.esapi.reference.DefaultHTTPUtilities.getInstance(DefaultHTTPUtilities.java:68)
... 40 more

不同的是,此次root exception為:
java.lang.ClassCastException: org.owasp.esapi.reference.Log4JLogger

這...真是太匪夷所思了,這段code我可是改都沒改,且出錯的為esapi內部,而且TestCode又都運作正常全綠燈(確定有測試到這段!!),卻在實際環境上報錯,所以應該可以『很合理』的猜出是與『環境』有關造成的錯誤而非code(TestCode告訴我一定不是我code寫錯~~
),最後找到以上參考網站,看到此段:

By chance, do you happen to have an instance of Apache Tomcat already running, or do you also have Microsoft Outlook running while you are trying to startup Tomcat? If so, shut down Outlook, start Tomcat, then restart Outlook. I've had problems in the past with conflicts like this.

的確,因為我今天才把war從tomcat搬到jboss上,而原先的tomcat還在運作中(同一台機器),因此只要把tomcat給關了,移除掉原先deploy的webapp,再重啟jboss就可以順利運作了~~

p.s:話說這個標籤該分類到哪呢?好像分類在esapi也不太對....?

JBOSS - 無法從外部IP連線

參考:Jboss only works on localhost:8080 ,but doesnt reply when called by ip


今天嘗試安裝JBOSS(畢竟案子其實根本不是用tomcat,每次都要改web.xml有點煩),
安裝很簡單,直接下載後執行 ${JBOSS_HOME}/bin/standalone.bat

但這時候卻發現,除非我連上server本機使用瀏覽器瀏覽,從外部都不行(確定防火牆已開),原來是還要設定以下:


修改${JBOSS_HOME}/standalone/configuration/standalone.xml

找到以下這段

    <interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
        </interface>
        <interface name="public">
            <inet-address value="${jboss.bind.address:127.0.0.1}"/>
        </interface>

  </interfaces>

將其中的name="public"裡面的value改為:
<inet-address value="${jboss.bind.address:0.0.0.0}"/>

就可以了,同樣的管理console如果也要能外連,更改name="management"就可以了。

p.s最近文章有點少啊...所以有點拿文章亂充數了@@