Ruby Watir webdriver testing - how to loop through user/password
Yes, you could loop through key-value pairs by doing this:
logins = { 'username1' => 'password1', 'username2' => 'password2' } #And so on for your 5 accounts.
logins.each_pair do |user, pass|
b = Watir::Browser.new
b.goto 'https://localhost/mywebapp'
b.text_field(id:'username').set user
b.text_field(id:'password').set pass
b.button(id: 'submitBtn').click
end
An alternative would be to load the login details from a CSV file.
watir: How do I enter a value in a form, without submitting the form with watir?
I could tell you more if you posted relevant HTML or link (if page is public), but my guess is that entering password fires JavaScript event that submits the form. Access is denied.
could mean that there is a frame, and IE does not allow access to it (http://wiki.openqa.org/display/WTR/Frames).
Maybe this would help:
ie.text_field(:name, "j_password").value=("password")
Using Watir I can't get a test to verify text in a username field
Text fields, specifically input
elements, do not have a text node. As a result, you will get an empty string when using the text
method on a text field. Similarly, there will be no text when calling browser.text
.
The text you see in the text field is actually the value of the value
attribute. You have to check that attribute instead. For example, you can use the value
method:
browser.text_field(text: 'superuser').value.include? 'superuser'
Ruby/Watir disable Save password prompt
Using Preferences
You are setting the preferences correctly. The problem is that you're running into a bug in Selenium-WebDriver - https://github.com/SeleniumHQ/selenium/issues/7917.
Until the fix is released, you'll need to use Strings for the preferences instead of Symbols:
options.add_preference("credentials_enable_service", false)
options.add_preference("password_manager_enabled", false)
Note that you don not need to create the Selenium Options directly. You can let Watir do this for you:
browser = Watir::Browser.new(
:chrome,
options: {
options: {"excludeSwitches" => ["enable-automation", "load-extension"]},
args: ["ignore-certificate-errors", "disable-infobars", '--disable-features=RendererCodeIntegrity'],
prefs: {"credentials_enable_service" => false, "password_manager_enabled" => false}
}
)
Using Incognito
Alternatively, instead of setting preferences, you could use incognito mode:
options = Selenium::WebDriver::Chrome::Options.new(
options: {"excludeSwitches" => ["enable-automation", "load-extension"]},
args: ["incognito", "ignore-certificate-errors", "disable-infobars"]
)
Related Topics
How to Allow Binary File Download Using Grape API
Activeadmin Forbiddenattributeserror
Rails 4 Strong Parameters Failing When Creating Instances in Rails Console
Ruby Sandboxing VS. Integrating a Scripting Language
Memorable Name Generator Gem for Ruby
Alias_Method and Class_Methods Don't Mix
Unicode Characters in Ruby 1.9.3 Irb with Rvm
"Certificate Verify Failed" Error When Installing Ruby Gems on Windows
Ruby on Rails 4 - What Authentication Gem to Use
How to Install a Gem Globally Without Sudo Using Rbenv
Memory Usage Increase with Ruby 2.1 Versus Ruby 2.0 or 1.9
How to Pass a Variable to a Layout
Are There Any Ruby Orms Which Use Cursors or Smart Fetch