function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rahul_sgRahul_sg 

Automating Salesforce testing by using Ruby CUCUMBER

Hello There!

We have started automating our sfdc scripts using Ruby, Watir & Cucumber. The scripts are working fine in our dev sandbox.
Currently we are referencing the records using record name/Id but we afraid once we refresh our sandbox from the production our scripts will stop working.
Can someone please share best practices using the Ruby cucumber tool to 1) generate test records 2) Reference test records in scripts?

Thanks!
KevinPKevinP
Rahul! I've done something like this in the past. Glad to see another Ruby / Cucumber user.

Essentially, I recommend you write a helper class for your Cucumber scripts that utilize the restforce gem (https://github.com/ejholmes/restforce) to create your own test data, before you run your tests. Essentially, i do something like this:
  1. Setup for cucumber tests creates test objects
  2. as objects are created, add them to a object library hash
  3. Run your tests. As you need them, grab id's/names from the library hash
  4. when the test passes, delete the elements of the library hash.
Rahul_sgRahul_sg
Thanks a lot Kevin!
I'll give it a try & will update you.
Dhananjey DeeviDhananjey Deevi
Hi @Kevin and @Rahul - I'm working on  developing a Salesforce test automation using Ruby + Watir . However im being asked for the verification code whenever I try to run the script. How to avoid it. 
Below is my code :
-------------------------------------------------------------
require 'watir'
browser = Watir::Browser.new :chrome
browser.goto 'login.salesforce.com'
browser.text_field(id: 'username').set 'Hello World!'
browser.text_field(id: 'password').set 'Hello World!'
sleep 5
--------------------------------------------------------
Feature: Testing login

  Scenario: Want to login into sfdc
    Given Open chrome browser
    And Enter the url login.salesforce.com
    When I keyin userid and pwd
    Then click Submit

Execution : Cucumber sfdc_login.feature

Filename : sfdc_login.rb
Given("Open chrome browser") do
 # pending # Write code here that turns the phrase above into concrete actions
end

Given("Enter the url login.salesforce.com") do
 # pending # Write code here that turns the phrase above into concrete actions
 @browser.goto "login.salesforce.com"
end

When("I keyin userid and pwd") do
  # pending # Write code here that turns the phrase above into concrete actions
  @browser.text_field(:id=>'username').set "testuser"
  @browser.text_field(:id=>'password').set "pwd"
end

Then("click Submit") do
 # pending # Write code here that turns the phrase above into concrete actions
  sleep 5
end

Please help. 
Regards,
Dhananjey.
Dhananjey DeeviDhananjey Deevi
essentially im just executing the .rb file that has the code ...
require 'watir'
browser = Watir::Browser.new :chrome
browser.goto 'login.salesforce.com'
browser.text_field(id: 'username').set 'Hello World!'
browser.text_field(id: 'password').set 'Hello World!'
sleep 5
As soon as the chrome is launched it is asking for the verfication code even before going to "login.salesforce.com". It might be because of the "Data:" protocol. What should I do to avoid the verification code. I have followed all the standard SFDC articles with respected to avoid the acitivation code , but in vain.
Please help.
Dhananjey DeeviDhananjey Deevi
Was able to resolve it