How to store dynamic value and reuse in Webdriver Ruby test

拈花ヽ惹草 提交于 2020-01-03 07:16:08

问题


I'm writing a ruby webdriver test that needs to store a dynamic value such as an order ID to use later on in the text. I think I need to extract the value from the string and then store it as a variable to call for future use.

The string looks like this and I just need to extract/store the numeric value.

<span class="receiptNum hidden-xs">Receipt #: 12303430</span>

Any tips or examples on how to extract that value and create a variable for future use would be great!


回答1:


To extract the text (only numbers) out of the this element, try using the following code:

@numbers = @driver.find_element(:css=>'receiptNum').text.scan(\d+)

Currently I am saving this number in an instance variable which can be used again in the same test as it will flow around with the test object till the test finishes.

Other option include saving it in a temp txt file and reading from it when required.

Note: Fetching data now and using it later is not a good practice, try not to use this very frequently.

Hope it helps!!!



来源:https://stackoverflow.com/questions/43457167/how-to-store-dynamic-value-and-reuse-in-webdriver-ruby-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!