2017-08-08 147 views
1

我正在用Oracle OpenScript編寫Web腳本。Oracle OpenScript在讀取變量時出現「讀取文件錯誤」

我記錄進行

行動
  • 打開鏈接
  • 選擇下拉菜單
  • 選擇從區域下拉菜單
  • 保存

和我m現在嘗試替換鏈接以從資產中創建的.csv變量打開,但我收到「錯誤讀取文件」消息。

SCREENSHOT

下面是完整的代碼:

import oracle.oats.scripting.modules.basic.api.*; 
import oracle.oats.scripting.modules.browser.api.*; 
import oracle.oats.scripting.modules.functionalTest.api.*; 
import oracle.oats.scripting.modules.utilities.api.*; 
import oracle.oats.scripting.modules.utilities.api.sql.*; 
import oracle.oats.scripting.modules.utilities.api.xml.*; 
import oracle.oats.scripting.modules.utilities.api.file.*; 
import oracle.oats.scripting.modules.webdom.api.*; 

public class script extends IteratingVUserScript { 
@ScriptService oracle.oats.scripting.modules.utilities.api.UtilitiesService 
utilities; 
@ScriptService oracle.oats.scripting.modules.browser.api.BrowserService 
browser; 
@ScriptService 
oracle.oats.scripting.modules.functionalTest.api.FunctionalTestService ft; 
@ScriptService oracle.oats.scripting.modules.webdom.api.WebDomService web; 

public void initialize() throws Exception { 
    browser.launch(); 
} 

/** 
* Add code to be executed each iteration for this virtual user. 
*/ 
public void run() throws Exception { 
    beginStep("[1] No Title (/hotelconfig.html)", 0); 
    { 
     web.window(2, "/web:window[@index='0' or @title='about:blank']") 
       .navigate(
         "URL"); 
     { 
      think(0.093); 
     } 
    } 
    endStep(); 
    beginStep("[2] Working... (/wia)", 0); 
    { 
     web.window(4, "/web:window[@index='0' or @title='about:blank']") 
       .navigate(
         "URL"); 
     web.window(
       5, 
       "/web:window[@index='0']") 
       .waitForPage(null); 
     { 
      think(6.198); 
     } 
     web.selectBox(
       6, 
       "/web:window[@index='0']/web:document[@index='0']/web:form[@index='0']/web:select[(@id='office_id' or @name='office_id' or @index='10') and multiple mod 'False']") 
       .selectOptionByText(
         "Office"); 
     { 
      think(2.636); 
     } 
     web.button(
       7, 
       "/web:window[@index='0']/web:document[@index='0']/web:form[@index='0']/web:input_submit[@name='save' or @value='Save' or @index='0']") 
       .click(); 
    } 
    endStep(); 
    beginStep(
      "[3] Intranet - Property info - *Hotel Settings - *Hotel configuration (/hotelconfig.html)", 
      0); 
    { 
     web.window(
       8, 
       "/web:window[@index='0']") 
       .waitForPage(null); 
    } 
    endStep(); 

} 

public void finish() throws Exception { 
} 
} 

我在網上看了看,Oracle的社區,但我無法找到一個解決。 我也嘗試運行OpenScript診斷工具,但沒有運氣。

任何人有任何想法?

+0

你添加數據的至少一列一列到你的文件嗎?您可以使用Excel或任何文本編輯器。文件必須是純文本。 – glenschler

+0

是的,當然。我使用的.csv是每個列中的URL,Office,幷包含標題。我試圖從OpenScript中,從Excel和記事本中創建.csv,但我總是得到錯誤。 .csv保存在腳本的文件夾中,並設置爲「相對於當前腳本」 – Luca

回答

1

Oracle應用測試套件(OATS)最好支持csv數據表閱讀。 你粘貼的代碼只是記錄你執行,沒有看到任何問題。屏幕截圖顯示錯誤消息,創建csv時可能出錯。

我可以建議外部Excel的讀者,這是燕麥本身內置 http://www.testinghive.com/category/oracle-application-testing-suite-tips/

//Define Sheet name to be read, and provide comma seperated to read multiple sheets 
String sheetName = "Sheet1"; 
//Mention excel sheet path 
String strFile= "C:\\Demo\\test.xls"; 

//Defined array list to add Sheets to read 
List sheetList = new ArrayList(); 
sheetList.add(sheetName); 
// Iports Sheet1 
datatable.importSheets(strFile, sheetList, true, true); 
//get rowcount 
info("Total rows :"+datatable.getRowCount()); 
int rowcount=datatable.getRowCount(); 
//Loop to read all rows 
for (int i=0;i<rowcount;i++) 
{ 
//Set current row fromw here you need to start reading, in this case start from first row 
datatable.setCurrentRow(sheetName, i); 
String strCompany=(String) datatable.getValue(sheetName,i,"Company"); 
String strEmpFName=(String) datatable.getValue(sheetName,i,"FirstName"); 
String strEmpLName=(String) datatable.getValue(sheetName,i,"LastName"); 
String strEmpID=(String) datatable.getValue(sheetName,i,"EmpID"); 
String strLocation=(String) datatable.getValue(sheetName,i,"Location"); 

//prints first name and last name 
System.out.println("First Name : "+strEmpFName+", Last Name : "+strEmpLName); 

//Sets ACTIVE column in excel sheet to Y 
String strActive="Y"; 
datatable.setValue(sheetName, i, datatable.getColumn(sheetName, datatable.getColumnIndex("Active")), strActive); 

} 

//Updates sheet with updated values ie ACTIVE column sets to Y 
datatable.exportToExcel("C:\\Demo\\test1.xlsx"); 

} 

public void finish() throws Exception { 
} 
}