質問

I want to dynamically use page objects. Something like this:

text_field(:company_name_field, id: 'company_directory_name')
select_list(:state_select, id: 'company_directory_workflow_state')


def input_text_field (page_object)
    sample_text = Faker::Lorem.paragraph
    $text_array.push(sample_text)
    wait_until{send("#{page_object}_field?")}
    send("#{page_object}_field=", sample_text)
end

But, using a select_index object, instead of a input_field:

def input_select_list(page_object)
    wait_until{send("#{page_object}_select?")}
    x = rand(0..send("#{page_object}_select_element.options.length"))
    send("#{page_object}_select_element.option(#{:index}, #{x})).select")
end

But this is giving me an error of "undefined method `state_select_element.option(index, 1).select'"

How can this be done?

役に立ちましたか?

解決

When using send, the first argument needs to be a single method. send does not break up the state_select_element.option(index, 1).select into 3 method calls.

Since only the first method call state_select_element needs to evaluated from the string, just use send for that. The rest can be called as normal. Applying this to your method gives:

def input_select_list(page_object)
    wait_until{send("#{page_object}?")}
    x = rand(0..send("#{page_object}_element").options.length) - 1
    send("#{page_object}_element").option(:index, x).select
end

However, the option and select methods will give a depreciation warning. To prevent the error, I would probably re-write the method as:

def input_select_list(page_object)
    select = send("#{page_object}_element")
    select.when_present
    select.select(send("#{page_object}_options").sample)
end
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top