Appium-How to send SMS for login verification purpose during automation test

1k views Asked by At

I am using Appium with python script, and I want to test the "Login" process for an app. This app requires inputting your phone number for receiving an SMS with a verification code. You then need to input the verification code to a text field in order to login.

I tried to just simulate inputting my personal phone number into the text field and pressing the send button, but nothing was sent to my phone, and I know this is probably not the right way to fix the problem. So what should I do?

Here are my code segments for this:

        get_start=self.driver.find_element_by_id('com.opentrans.driver:id/get_started')
        get_start.click()
        phone=self.driver.find_element_by_id('com.opentrans.driver:id/phone_number')
        phone.send_keys(15000703051)
        get_code=self.driver.find_element_by_id('com.opentrans.driver:id/send_code')
        get_code.click()

And this is my code for the desired capabilities:

    desired_caps=dict()
    desired_caps['platformName']='Android'
    desired_caps['platformVersion']='4.4'
    desired_caps['deviceName']='LG Nexus 5'
    desired_caps['app']=PATH ('/Users/elaine/Desktop/bin/driver-debug.apk')

    self.driver=webdriver.Remote('http://0.0.0.0:4723/wd/hub',desired_caps)

Thanks in advance!

1

There are 1 answers

0
Eugene On

You can do it using extend support for ADB commands

am start -a android.intent.action.SENDTO -d sms:#{recipient} --es sms_body '#{text}' --ez exit_on_sent true

Please see the details here