I am revisiting a page to create a new record instead of editing a record and I need to ensure that all the field values have been cleared out. (the page is shared between the different actions so I need to make sure the right action produces the right result).
How can I assert that all input fields are clear from data after reset (selenium-ruby-cucumber)
-
Seems like a good question which I've attempted to improve despite close squad mafia– Michael DurrantCommented May 25, 2018 at 0:04
-
How is this question 'unclear' ? This question is like the definition of clarity– Michael DurrantCommented May 25, 2018 at 9:47
Add a comment
|
1 Answer
Step 0. Set up Webdriver.
require 'rubygems'
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
Step 1. Set a variable for finding values found_values= false
Step 2. Get an array of all the input elements inputs= driver.find_elements('input')
# all('input') if using Capybara btw
Step 3. Iterate through them, e.g.
inputs.each |field| do
field.value <> '' && found_values= true
break if found_values
end
Step 4. expect(found_values).to be false
Note:
irb(main):001:0> a=2 && b=3
=> 3
irb(main):002:0> p b
3
=> 3
-
1Hi Michael! How should your pseudo-code be treated? The line inside "do..end" looks like a pure logical expression (except "break") representing some boolean result, however "do" implies some action taken. It seems here is a mix of conditions, assigning value to a variable and breaking the loop, however that is not obvious. Commented May 24, 2018 at 20:13
-
1Hi @AlexeyR. Thanks. Updated a bit,. The && will get found_values set to true based on condition. I moved the break to the next link based on found_values value Commented May 24, 2018 at 23:47
-
-
that is just about using
all
. Without capybara usefind_elements
as shown Commented May 27, 2018 at 11:11