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:
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:
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:
- Enter required text
- Convert Text to Audio
- Inject the generated Audio to application
- Convert Text to Audio
- Inject the generated Audio to Device
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