怪事!!
我按照Winrunner的中文用户说明学习,在用Sample applications-->flight 4A做练习时,检查其票数乘以其单价是否等于总价时,结果没有通过;而我将语句 if(tickets*price == total)修改成if(tickets*price < total)时,却能通过。请问各位高手,我是哪里出了问题。我录制的脚如下:(我之前有做过同样的练习,结果是成功的,后来被我不小心删除了,等我再做时就老是通不过了,不知道哪里出了问题?我用的是7.6版本的)# Fax Order No. 3
set_window ("Fax Order No. 3", 2);
menu_select_item ("File;Open Order...");
# Open Order
set_window ("Open Order", 0);
button_set ("Order No.", ON);
edit_set ("Edit_1", "3");
button_press ("OK");
# Fax Order No. 3
set_window ("Fax Order No. 3", 3);
menu_select_item ("File;Fax Order...");
# Fax Order No. 3_1
set_window("Fax Order No. 3_1", 1);
static_get_text("# Tickets:(static)",tickets);
static_get_text("Ticket Price:(static)",price);
static_get_text("Total:(static)",total);
if(tickets*price == total)
tl_step("total",0,"total is correct.");
else
tl_step("total",1,"total is incorrect.");
set_window ("Fax Order No. 3_1", 2);
button_press ("Cancel"); tickets是int,但price的值是“$123”,就是因为钱前面的单位造成的,你应该首先将字符串前面的金钱单位去掉之后再作比较就好了,使用函数substr(),修改如下:
# Fax Order No. 3
set_window ("Fax Order No. 3", 2);
menu_select_item ("File;Open Order...");
# Open Order
set_window ("Open Order", 0);
button_set ("Order No.", ON);
edit_set ("Edit_1", "3");
button_press ("OK");
# Fax Order No. 3
set_window ("Fax Order No. 3", 3);
menu_select_item ("File;Fax Order...");
# Fax Order No. 3_1
set_window("Fax Order No. 3_1", 1);
static_get_text("# Tickets:(static)",tickets);
static_get_text("Ticket Price:(static)",price);
static_get_text("Total:(static)",total);
#add
price=substr(price,2);
total=substr(total,2);
#add end
if(tickets*price == total)
tl_step("total",0,"total is correct.");
else
tl_step("total",1,"total is incorrect.");
set_window ("Fax Order No. 3_1", 2);
button_press ("Cancel"); 谢谢wenlaqing给我的解答,可是我按照上面的修改还是没有通过。price的单位在哪里修改啊?脚本里没有体现出来 但是我昨天晚上是实现了的阿,怎么会了,像这样的情况你可以在变量赋了值后用report_msg()函数来查看一下tickets,price和total它们的值就可以看出问题,相信这样能够解决。
不知道你的代码还有什么问题,继续讨论。 # Fax Order No. 3_1
set_window("Fax Order No. 3_1", 1);
static_get_text("# Tickets:(static)",tickets);
static_get_text("Ticket Price:(static)",price);
static_get_text("Total:(static)",total);
你取值取错了, static_get_text是返回静态文本对象的内容 谢谢各位的解答,已经成功了,是我取值错了。不过还有个问题:取值错了为什么改成小于又能通过呢? 楼主, 把你成功的完整CODE 贴出来吧, 大家共享一下. 成功代碼如下,我只是改變了取值而已:
# Fax Order No. 3
set_window ("Fax Order No. 3", 2);
menu_select_item ("File;Open Order...");
# Open Order
set_window ("Open Order", 0);
button_set ("Order No.", ON);
edit_set ("Edit_1", "3");
button_press ("OK");
# Fax Order No. 3
set_window ("Fax Order No. 3", 3);
menu_select_item ("File;Fax Order...");
# Fax Order No. 3_1
set_window("Fax Order No. 3_1", 1);
edit_get_text("# Tickets:",tickets);
edit_get_text("Ticket Price:",price);
edit_get_text("Total:",total);
if(tickets*price == total)
tl_step("total",0,"total is correct.");
else
tl_step("total",1,"total is incorrect.");
set_window ("Fax Order No. 3_1", 2);
button_press ("Cancel"); 原来这样,我昨天用的是obj_get_text(),学习中!你用report_msg就可以看到变量所取的值,就知道为什么改为<=就对了的原因
页:
[1]