2

私はこれが間違ったやり方であることを十分に承知していますが、私はルビーにそれほど精通していません。最善の選択肢はユースケースであると確信していますか?またはループ?

def addInfoToStory(idOfStory, storyTitle, storyPriority, storyEST, storySupporter, storyBugzilla, storyStatus, storyOutcome, storyCustomer, storyNotes)
  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>1).div.double_click
  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>1).div(:class => "formLib1").text_field(:id, 'input').set"#{storyTitle}"
  @browser.send_keys :tab

  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>2).div.double_click
  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>2).div(:class => "formLib1").text_field(:id, 'input').set"#{storyPriority}"
  @browser.send_keys :tab

  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>3).div.double_click
  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>3).div(:class => "formLib1").text_field(:id, 'input').set"#{storyEST}"
  @browser.send_keys :tab

  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>4).div.double_click
  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>4).div(:class => "formLib1").text_field(:id, 'input').set"#{storySupporter}"


  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>5).div.double_click
  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>5).div(:class => "formLib1").text_field(:id, 'input').set"#{storyBugzilla}"
  @browser.send_keys :tab

  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>6).div.double_click
  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>6).div(:class => "formLib1").text_field(:id, 'input').set"#{storyStatus}"
  @browser.send_keys :tab

  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>7).div.double_click
  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>7).div(:class => "formLib1").text_field(:id, 'input').set"#{storyOutcome}"
  @browser.send_keys :tab

  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>8).div.double_click
  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>8).div(:class => "formLib1").text_field(:id, 'input').set"#{storyCustomer}"
  @browser.send_keys :tab

  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>9).div.double_click
  @browser.div(:id => "#{idOfStory}"+"_firstCol").div(:class => "tDetEntry", :index =>9).div(:class => "formLib1").text_field(:id, 'input').set"#{storyNotes}"
  @browser.send_keys :tab
end

フォームに記入するこのプロセスを実行するための最も効率的な方法に関する提案はありますか?

4

1 に答える 1

4

あなたのコードはこれと同等です:

def addInfoToStory(idOfStory, *stories)
  stories.each.with_index do |story, i|
    @browser.div(id: "#{idOfStory}_firstCol").div(class: "tDetEntry", index: i+1).div.double_click
    @browser.div(id: "#{idOfStory}_firstCol").div(class: "tDetEntry", index: i+1).div(class: "formLib1").text_field(:id, "input").set(story)
    @browser.send_keys(:tab) unless i == 3
  end
end
于 2012-09-18T09:34:23.997 に答える