Is it possible to click on multiple links from a single command in ruby watir

StackOverflow https://stackoverflow.com/questions/21721561

  •  10-10-2022
  •  | 
  •  

Вопрос

I have a cucumber statement which looks like this,Then i navigate to "page_name": "page1> page2> page3"

where page_name is a dummy variable to put the name of the page to which I am navigating to. The other argument is the path which has to be followed to reach the required page. I cannot hard code the path as it is of lenght 4 sometimes. I am using a .yml file to give the hrefs for the respective names.

Ex: page1= link1,
page2= link2,
page3= link3

Is it possible to write a single ruby function to do this?

Это было полезно?

Решение

Yes, it would be possible. You could:

  1. Get the path "page1> page2> page3" from the Cucumber step
  2. Split the path on the "> "
  3. Iterate through the path to:
    1. Get the href from the yml file
    2. Click on that link

For example, this might look like:

Then /i navigate to ".*": ".*"/ do |page_name, path|
  path.split('> ').each do |page|
    # Determine which link to click (assuming that the yml file gives you respective hrefs)
    href = get_link_from_yml(page)  # (You will need to create this method)

    # Click the link
    @browser.link(:href => href).click
  end
end
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top