【问题标题】:Oracle OpenScript "Error reading file" when substituting variable替换变量时Oracle OpenScript“读取文件错误”
【发布时间】:2018-01-15 16:25:51
【问题描述】:

我正在使用 Oracle OpenScript 编写 Web 脚本。

我记录了要执行的动作

  • 打开链接
  • 选择下拉菜单
  • 从下拉菜单中选择字段
  • 保存

我现在正尝试用我在资产中创建的 .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 诊断工具,但没有成功。

有人知道吗?

【问题讨论】:

  • 您是否在文件中添加了至少一列和一行数据?您可以使用 excel 或任何文本编辑器。文件必须是纯文本。
  • 是的,当然。我使用的 .csv 是 URL,每列中的 Office,带有标题。我尝试从 OpenScript、Excel 和记事本中创建 .csv,但我总是收到错误消息。 .csv 保存在脚本的文件夹中,并设置为“相对于当前脚本”

标签: java oracle scripting openscript


【解决方案1】:

Oracle 应用测试套件 (OATS) 最支持读取 csv 数据表。 您粘贴的代码只是记录您执行的操作,没有发现任何问题。并且屏幕截图显示错误消息,创建 csv 时可能出现问题。

我可以建议使用 OATS 本身内置的外部 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 {
}
}

【讨论】:

    【解决方案2】:

    我发现使用数据库作为数据提供者更容易。

    通过添加带有必要变量的 CSV 文件,您将能够进行以下替换:

    public void run() throws Exception {    
        getDatabank("databank").getNextDatabankRecord();
        String v_dataFilename = "{{db.databank.filename}}";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-14
      • 2022-11-17
      • 2011-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多