最近在论坛上看到有人提问LoadRunner如何对两个字符串进行比较,其脚本中两个字符串进行比较结果总是不一样的。我把问题整理了一下以便注意这个容易被忽略的错误。
脚本如下:
...
lr_save_string( "Hello World!","string1" );
lr_save_string( "Hello World!","string2" );
result = strcmp("string1","string2");
if ( result == 0 )
{
   lr_output_message("the result is 0.");
}
else
{
   lr_output_message("the result is not 0.");
}
大家可以看出脚本那里错了吗?
问题错在result = strcmp("string1","string2");这个上,这样变成了对字符串"string1"和"string2"的比较,而不是对变量的值进行比较,因此比较结果肯定是不一样的。

正确的写法有两种:
result = strcmp(&string1,&string2);
result = strcmp(lr_eval_string("{string1}"),lr_eval_string("{string2}")); 

相关文章:

  • 2021-06-18
  • 2021-12-28
  • 2022-02-14
  • 2022-12-23
  • 2021-08-19
猜你喜欢
  • 2021-10-01
  • 2022-01-11
  • 2022-12-23
  • 2021-10-14
  • 2021-09-03
  • 2022-02-15
相关资源
相似解决方案