您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium+log4j+eclipse相關(guān)問題及解決方案
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2015/8/27 17:51:23 ] 推薦標簽:軟件測試工具 功能測試工具

  問題一:
  如何獲取新打開的瀏覽器窗口,用selenium進行UI自動化測試時,經(jīng)常會遇到這個問題,現(xiàn)總結(jié)如下:
  // 存儲現(xiàn)在窗口句柄
  String winHandleBefore = driver.getWindowHandle();
  //跳轉(zhuǎn)到新打開的窗口
  for(String winHandle : driver.getWindowHandles()){
  driver.switchTo().window(winHandle);
  }
  // 執(zhí)行相關(guān)操作
  ...
  // 關(guān)掉當前新的窗口
  driver.close();
  // 跳轉(zhuǎn)到之前的窗口
  driver.switchTo().window(winHandleBefore);
  // 接著進行相關(guān)操作
  問題二:
  在項目中添加log時出現(xiàn)了WARN,如下所示:
  log4j:WARN No appenders could be found for logger .
  log4j:WARN Please initialize the log4j system properly.
  log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  費勁周折也沒找到原因:后在Stack Overflow上找到了答案,希望與君共勉。
  有兩種方法:
  第一種:在賣你代碼中加上如下代碼
  BasicConfigurator.configure();
  第二種:添加如下標準log4j.properties文件到classpath
  # Set root logger level to DEBUG and its only appender to A1.
  log4j.rootLogger=DEBUG, A1
  # A1 is set to be a ConsoleAppender.
  log4j.appender.A1=org.apache.log4j.ConsoleAppender
  # A1 uses PatternLayout.
  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
  問題三:
  eclipse項目報錯如下所示:
  Project 'MyProgram' is missing required library: 'D:Selenium_workspaceMyProgramsrc est esourceselenium-server-standalone-2.45.0.jar'
  The project cannot be built until build path errors are resolved
  原因是項目所在目錄中.classpath文件中存在如下聲明:
 。ㄖ皼]有在maven中添加selenium的依賴,手動添加的selenium的環(huán)境變量,當用maven添加selenium依賴后,將此目錄中的selenium刪除,eclipse找不到手動設(shè)置的seleniumjar包的位置導致出錯。),將此行刪掉問題解決了。
  <classpathentry kind="lib" path="D:/Selenium_workspace/MyProgram/src/test/resource/selenium-server-standalone-2.45.0.jar"/>

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd