开发者

How do I create an object that will have a number at the end that will increment each time it is used?

I am trying to make a variable that I can increment each time after I use it. The $com开发者_运维问答panyLevel os the variable that I need to increment.

count = 20
# Variables (20)
while count > 0
 $levelName = ""; 8.times{$levelName  << (65 + rand(25)).chr}
 $companyLevel = "CLev5"
 browser2.button(:id, "addCompanyLevel").click
 sleep 2
 browser2.text_field(:id, $companyLevel).set $levelName
 $companyLevel += 1
 count -= 1
end

How do I create a variable that will have a number at the end that will increment each time it is used?

Thanks.


Since you already have a count, why does this need to be a variable? why not just do simple string concatenation to create the value you want on the fly

companyLevel = "CLev" + count.to_s

Unless you need to perhaps read up on what an 'array' is?

I'd suggest you purchase and read the book "Everyday Scripting with Ruby" it's a great way to lean the basics of the ruby language and geared towards testers.


This is achieved by creating an object with a property that increments not by creating a variable that increments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜