|
本帖最后由 shanshan3301 于 2013-4-3 23:32 编辑
The Target:
1.Read the string from Excel
2.Parse string into button
3.click every button in string
4.save result from calculator
5.record said result in Excel
6.use JScript to calculator result
7.Record that result to Excel
8.compare result
9.record result into Excel.
ok,let's start:
1.run TestComplete
2.create one Excel 'C:\\MyFile.xlsx'
3.'record secript' calculator
4.use 'Name Mapping' to record the button name
5.create 'Unit1' and copy the code:
function Test1()
{
var page32770;
TestedApps.calc.Run();
page32770 = Aliases.calc.wndCalculator.CalcFrame.page32770;
ParseXls("C:\\MyFile.xlsx");
}
function ParseXls(filename)//read the data from excel
{
var Excel = Sys.OleObject("Excel.Application");
Excel.Workbooks.Open(filename);
var RowCount = Excel.ActiveSheet.UsedRange.Rows.Count;
var ColumnCount = Excel.ActiveSheet.UsedRange.Columns.Count;
for (var i = 1; i <= RowCount; i++)
{
var s = "";
for (var j = 1; j <= ColumnCount; j++)
{
s=VarToString(Excel.Cells(i, j));
Parse(s);
Aliases.calc.wndCalculator.MainMenu.Click("Edit|Copy");
var res = Sys.Clipboard;//get the result from clipboard
s=s+res;//combine string and result
Excel.Cells(i, j)=s;//save the result to Excel
}
}
Excel.Quit();
}
//paring expression
function Parse(exp)
{
for (i=0; i < exp.length; i++)
{
Click(exp.charAt(i));
}
}
//click button
function Click(char)
{
var page32770;
page32770 = Aliases.calc.wndCalculator.CalcFrame.page32770;
switch(char)
{
case '0':
page32770.btn_0.ClickButton();
break;
case '1':
page32770.btn_1.ClickButton();
break;
case '2':
page32770.btn_2.ClickButton();
break;
case '3':
page32770.btn_3.ClickButton();
break;
case '4':
page32770.btn_4.ClickButton();
break;
case '5':
page32770.btn_5.ClickButton();
break;
case '6':
page32770.btn_6.ClickButton();
break;
case '7':
page32770.btn_7.ClickButton();
break;
case '8':
page32770.btn_8.ClickButton();
break;
case '9':
page32770.btn_9.ClickButton();
break;
case '+':
page32770.btn_plus.ClickButton();
break;
case '=':
page32770.btn_eq.ClickButton();
break;
case '(':
page32770.btn_paL.ClickButton();
break;
case ')':
page32770.btn_paR.ClickButton();
break;
case '/':
page32770.btn_div.ClickButton();
break;
case '*':
page32770.btn_product.ClickButton();
break;
case '-':
page32770.btn_minus.ClickButton();
break;
case '.':
page32770.btn_redix.ClickButton();
break;
default:
break;
}
} |
|