2012-09-18 29 views
2

我完全知道這是錯誤這樣做的方式,但我並不真正熟悉ruby。我很確定最好的選擇是使用大小寫嗎?或循環?這個腳本更有效的方法嗎?

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

你的代碼是相同的:

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 
+1

不完全是。 index = 4處沒有'send_keys'行。不知道這是故意還是複製/粘貼錯誤。 –

+0

@SergioTulentsev Ouups,你是對的。 – sawa

+0

@sawa謝謝你,但是我會列出故事數組作爲哪個故事的字符串輸入到,故事是哪些字符串的數組? – samayres1992

相關問題