# How to test SMS messages with Mailosaur Learn how to use Mailosaur phone numbers to create end-to-end tests that cover identity verification, alerting, promotional messages and more. Using the [Mailosaur API](/docs/api), you can write SMS tests using common frameworks like Cypress, Playwright, Selenium, and Robot Framework, as well as in popular languages, using our [SDKs for SMS testing](/docs/automation). ## How it works Testing SMS messages is as simple as: 1. [Assign a phone number](/docs/sms-testing/phone-numbers) to one of your inboxes. 2. Send SMS messages to that number, just as you normally would. 3. Use the Mailosaur API to create end-to-end tests using the extracted content. ## Testing SMS messages Using Mailosaur's [client libraries](/docs/automation), you can fetch SMS messages with just a few lines of code. The code for [automating SMS tests](/docs/automation) is almost identical to testing emails. ```nodejs const mailosaur = new MailosaurClient('YOUR_API_KEY'); const testStart = new Date(); // Only look for messages after our test began // Send an SMS message to your test number... const message = await mailosaur.messages.get('SERVER_ID', { sentTo: '1234567890' // YOUR_TEST_NUMBER }, { receivedAfter: testStart }); console.log(message.text.body); // "Your order number is 51223" console.log(message.text.codes[0].value); // "51223" ``` ```cypress const testStart = new Date(); // Only look for messages after our test began // Send an SMS message to your test number... cy.mailosaurGetMessage('SERVER_ID', { sentTo: '1234567890' // YOUR_TEST_NUMBER }, { receivedAfter: testStart }).then(message => { cy.log(message.text.body); // "Your order number is 51223" cy.log(message.text.codes[0].value); // "51223" }) ``` ```python from mailosaur import MailosaurClient from mailosaur.models import SearchCriteria from datetime import datetime mailosaur = MailosaurClient("YOUR_API_KEY") test_start = datetime.now() # Only look for messages after our test began # Send an SMS message to your test number... criteria = SearchCriteria() criteria.sent_to = "1234567890" # YOUR_TEST_NUMBER message = mailosaur.messages.get("SERVER_ID", criteria, received_after=test_start) print(message.text.body) # "Your order number is 51223" print(message.text.codes[0].value) # "51223" ``` ```java MailosaurClient mailosaur = new MailosaurClient("YOUR_API_KEY"); Date testStart = new Date(); // Only look for messages after our test began // Send an SMS message to your test number... MessageSearchParams params = new MessageSearchParams(); params.withServer("SERVER_ID") .withReceivedAfter(testStart); SearchCriteria criteria = new SearchCriteria(); criteria.withSentTo("1234567890"); // YOUR_TEST_NUMBER Message message = mailosaur.messages().get(params, criteria); System.out.println(message.text().body()); // "Your order number is 51223" System.out.println(message.text().codes.get(0).value()); // "51223" ``` ```csharp var mailosaur = new MailosaurClient("YOUR_API_KEY"); var testStart = DateTime.Now; // Only look for messages after our test began // Send an SMS message to your test number... var criteria = new SearchCriteria() { SentTo = "1234567890" // YOUR_TEST_NUMBER }; var message = mailosaur.Messages.Get("SERVER_ID", criteria, receivedAfter: testStart); Console.WriteLine(message.Text.Body); // "Your order number is 51223" Console.WriteLine(message.Text.Codes[0].Value); // "51223" ``` ```ruby require 'mailosaur' mailosaur = Mailosaur::MailosaurClient.new("YOUR_API_KEY") test_start = DateTime.now # Only look for messages after our test began # Send an SMS message to your test number... criteria = Mailosaur::Models::SearchCriteria.new() criteria.sent_to = "1234567890" # YOUR_TEST_NUMBER message = mailosaur.messages.get("SERVER_ID", criteria, received_after: test_start) print(message.text.body) # "Your order number is 51223" print(message.text.codes[0].value) # "51223" ``` ```php require_once('vendor/autoload.php'); use Mailosaur\MailosaurClient; use Mailosaur\Models\SearchCriteria; $mailosaur = new MailosaurClient('YOUR_API_KEY'); $testStart = new \DateTime(); // Only look for messages after our test began // Send an SMS message to your test number... $criteria = new SearchCriteria(); $criteria->sentTo = '1234567890'; // YOUR_TEST_NUMBER $message = $mailosaur->messages->get('SERVER_ID', $criteria, 10000, $testStart); print($message->text->body); // "Your order number is 51223" print($message->text->codes[0]->value); // "51223" ``` ```go m := mailosaur.New("YOUR_API_KEY"); testStart := time.Now(); // Only look for messages after our test began // Send an SMS message to your test number... params := &mailosaur.MessageSearchParams { Server: "SERVER_ID", ReceivedAfter: testStart, } criteria := &mailosaur.SearchCriteria { SentTo: "1234567890", // YOUR_TEST_NUMBER } message, err := m.Messages.Get(params, criteria) if (err != nil) { t.Error(err) } if message != nil { fmt.Println(message.Text.Body); // "Your order number is 51223" fmt.Println(message.Text.Codes[0].Value); // "51223" } ``` > [!LINK](/docs/sms-testing/phone-numbers) > ### Test phone numbers > Learn to test SMS functionality with Mailosaur. Request, cost, and allocate mobile phone numbers for testing. > [!LINK](/docs/sms-testing/replying) > ### Replying to SMS messages > Enhance your SMS testing capabilities by simulating user replies. Utilize Mailosaur's reply function for a comprehensive SMS testing solution.