Sunday 19 March 2017

Voice Driven Testing using Perfecto Mobile

Most of the applications today started supporting voice commands either it is a desktop or a mobile.More & more functionalities are being supported by voice commands.

Testing these functionalities is very difficult as it requires audio files which are hard to edit / maintain them whenever required. Perfecto has come up with a better way to test these functionalities.

Steps to test Voice Driven Functionalities:
  1. Enter required text
  2. Convert Text to Audio
  3. Inject the generated Audio to application

  • Convert Text to Audio

                      For Converting the text to Audio, use the Voice RSS API, a free SaaS based library which converts the given text to human voice. Follow the steps provided in the below link:

  • Inject the generated Audio to Device
                     Inject the audio to device / application using the Perfecto's MobileTTSLibrary.One has to set the capabilities, open the app & pass the required text to MobileTTSLibrary. The task of converting the text to Audio, uploading the audio & injecting the audio to the required device is all taken care by MobileTTS library.

Below code will demo 'How simple is to test voice commands in Google app'.

public class VoiceDrivenTest {

public static void main(String[] args) throws MalformedURLException, IOException {
String browserName = "mobileOS";
String host = "demo.perfectomobile.com";
String user = "perfectoUsername";
String perfectoPassword = "Password";
String voiceRSSKey = "APIKey";
//Set the Capabilities
DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY);
capabilities.setCapability("user", user);
capabilities.setCapability("password", perfectoPassword);
capabilities.setCapability("deviceName", "1115FBD16FEF0303");
capabilities.setCapability("automationName", "PerfectoMobile");
setExeIdCap(capabilities, host);

RemoteWebDriver driver = new RemoteWebDriver(new URL("https://" + host + "/nexperience/perfectomobile/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

try {
// Create an Instantiate of MobileTTS object 
MobileTTS mTTS = new MobileTTS(driver, perfectoPassword, voiceRSSKey, LANGUAGE.ENGLISH_US );
// Launch the Google application
launchApp(driver, "com.google.android.googlequicksearchbox");
driver.findElement(By.xpath("//*[@resourceid='com.google.android.googlequicksearchbox:id/clear_or_voice_button']")).click();
// Inject the voice command from the text
mTTS.injectAudioFromText("how is the weather outside today");
} catch (Exception e) {
e.printStackTrace();
} finally {
driver.close();
driver.quit();
}
}
private static void launchApp(RemoteWebDriver driver, String appName){
RemoteExecuteMethod executeMethod = new RemoteExecuteMethod(driver);
Map<String, String> params = new HashMap<String, String>();
params.put("name", appName);
Map<String,String> params1 = new HashMap<String,String>();
params1.put("name", "NATIVE_APP");
try{
executeMethod.execute(DriverCommand.SWITCH_TO_CONTEXT, params1);
driver.executeScript("mobile:application:close", params);
Thread.sleep(1000);
driver.executeScript("mobile:application:open", params);
Thread.sleep(1000);
}
catch(Exception e){ }
}

private static void setExeIdCap(DesiredCapabilities capabilities, String host) throws IOException {
EclipseConnector connector = new EclipseConnector();
String eclipseHost = connector.getHost();

if ((eclipseHost == null) || (eclipseHost.equalsIgnoreCase(host))) {
String executionId = connector.getExecutionId();
capabilities.setCapability(EclipseConnector.ECLIPSE_EXECUTION_ID, executionId);
}
}

}



References:
https://community.perfectomobile.com/series/31278/posts/1126740
http://www.voicerss.org/tts/

No comments:

Post a Comment