The SMS Library
/* @provengo summon sms */
javascript
The SMS library helps using one-time passwords (OTP) sent via SMS/text messages in automated tests.
This library requires an active account on Twilio, with a registered mobile number. |
Example
In the example below, we use the SMS library to save an OTP (one-time-password) sent as part of identification process.
// @provengo summon sms (1)
// @provengo summon selenium
const sms = new SmsSession("OTP", {"token": "twilio-token", "sid": "twilio-sid"}) (2)
const session = new SeleniumSession("dave"); (3)
bthread( "automator", function(){
session.start("https://test.hal.com");
session.click("//a[contains(text(),'Sign In')]");
session.writeText("//input[@id='username']", "dave");
session.writeText("//input[@id='password']", "dave-pass");
session.click("//button[@id='connect']"); (4)
sms.storeOtp("otpValue", {"phone": "+12345678901"}); (5)
session.writeText("//input[@id='otp']", "@{otpValue}"); (6)
session.click("//button[@id='connect']")
.
.
.
session.close(); (7)
});
javascript
-
Importing the SMS and selenium libraries.
-
Defining a SMS session.
-
Defining a new selenium session (no browser window opened yet).
-
This button should initiate sending an OTP to the phone number registered with Twilio.
-
Save the OTP digits sent to phone in previous step, as
otpValue
in run time value. -
Use run time value
otpValue
as OTP to log into the site.
Methods
smsSession.storeOtp(varName, data)
Saves the OTP found in the most recent SMS message under the runtime variable varName
.
varName
-
String. name for the otp variable that will store on rtv variable.
data
-
Object containing extra data about the incoming sms.
sender
-
Optional string. The phone number the otp sms message was sent from. If omitted, Provengo will search all incoming messages. regardless of sending number.
msecInterval
-
Optional number. Duration (in milliseconds) of the interval between messages search attempts.
maxAttempts
-
Optional number. How many times should Provengo search the OTP SMS, before giving up and marking the test as failed.