using System;
using System.Speech.Recognition;
using System.Threading;
//using System.Speech.Synthesis;
namespace Voice_Recognation
{
class Program
{
static void Main(string[] args)
{
SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine();
recEngine.SetInputToDefaultAudioDevice();
Choices commands = new Choices();
commands.Add(new string[] { "say Hi", "say Hello"});
GrammarBuilder gb = new GrammarBuilder();
gb.Append(commands);
Grammar g = new Grammar(gb);
recEngine.LoadGrammarAsync(g);
recEngine.SpeechRecognized += recEngine_SpeechRecognized;
Console.WriteLine("Starting asynchronous recognition...");
recEngine.RecognizeAsync(RecognizeMode.Multiple);
// Wait 30 seconds, and then cancel asynchronous recognition.
Thread.Sleep(TimeSpan.FromSeconds(30));
// or
// while(true);
}
// Create a simple handler for the SpeechRecognized event
static void recEngine_SpeechRecognized (object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine("Speech recognized: {0}", e.Result.Text);
switch(e.Result.Text){
case "say Hello":
Console.WriteLine("you said hi");
break;
default:
break;
}
}
}
}
通过右键单击xml文件“Run as testNG suite”执行脚本时,浏览器会打开,但控制台中会立即显示错误。
任何人都可以指导我是否需要降级浏览器,如果是这样的话,selenium 3版本的支持版本是什么。
错误日志:
Browser: Firefox 50 version
Selenium Jar files : 3.0.1 jar
OS: Windows 7 enterprise 64 bit
以下是我在上课前的[TestNG] Running:
C:\Users\raghuveer.amajala\AppData\Local\Temp\testng-eclipse-1646049448\testng-customsuite.xml
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
true,"v":"1.0","st":1478328645000}},"winreg-app-user":{"ocplugin@webex.com":{"d":"C:\\Program Files (x86)\\WebEx\\Productivity Tools","e":false,"v":"2.0","st":1485264359732,"mt":1463471846535}},"app-global":{"{972ce4c6-7e08-4474-a285-3208198ce6fd}":{"d":"C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","e":true,"v":"50.0","st":1478328645000}},"winreg-app-global":{"{D19CA586-DD6C-4a0a-96F8-14644F340D60}":{"d":"C:\\Program Files (x86)\\Common Files\\McAfee\\SystemCore","e":false,"v":"15.4.0","st":1477288713580,"mt":1476678768866}}}
1485322859314 addons.xpi DEBUG No changes found
1485322859325 addons.xpi DEBUG Registering manifest for C:\Program Files (x86)\Mozilla Firefox\browser\features\aushelper@mozilla.org.xpi
1485322859326 addons.xpi DEBUG Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\browser\features\aushelper@mozilla.org.xpi
1485322859331 addons.xpi DEBUG Calling bootstrap method startup on aushelper@mozilla.org version 1.0
1485322859333 addons.xpi DEBUG Registering manifest for C:\Program Files (x86)\Mozilla Firefox\browser\features\e10srollout@mozilla.org.xpi
1485322859334 addons.xpi DEBUG Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\browser\features\e10srollout@mozilla.org.xpi
1485322859343 addons.xpi DEBUG Calling bootstrap method startup on e10srollout@mozilla.org version 1.5
1485322859344 addons.xpi DEBUG Registering manifest for C:\Program Files (x86)\Mozilla Firefox\browser\features\firefox@getpocket.com.xpi
1485322859345 addons.xpi DEBUG Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\browser\features\firefox@getpocket.com.xpi
1485322859349 addons.xpi DEBUG Calling bootstrap method startup on firefox@getpocket.com version 1.0.5
1485322859360 addons.xpi-utils DEBUG Starting async load of XPI database C:\Users\RAGHUV~1.AMA\AppData\Local\Temp\anonymous8881786919455687854webdriver-profile\extensions.json
1485322859362 addons.xpi DEBUG Registering manifest for C:\Program Files (x86)\Mozilla Firefox\browser\features\webcompat@mozilla.org.xpi
1485322859362 addons.xpi DEBUG Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\browser\features\webcompat@mozilla.org.xpi
1485322859365 addons.xpi DEBUG Calling bootstrap method startup on webcompat@mozilla.org version 1.0
1485322859367 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1485322859367 addons.manager DEBUG Provider finished startup: XPIProvider
1485322859367 addons.manager DEBUG Starting provider: LightweightThemeManager
1485322859367 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1485322859368 addons.manager DEBUG Provider finished startup: LightweightThemeManager
1485322859368 addons.manager DEBUG Starting provider: GMPProvider
1485322859386 addons.manager DEBUG Registering shutdown blocker for GMPProvider
1485322859386 addons.manager DEBUG Provider finished startup: GMPProvider
1485322859386 addons.manager DEBUG Starting provider: PluginProvider
1485322859387 addons.manager DEBUG Registering shutdown blocker for PluginProvider
1485322859387 addons.manager DEBUG Provider finished startup: PluginProvider
1485322859387 addons.manager DEBUG Completed startup sequence
1485322859726 addons.xpi-utils DEBUG Async JSON file read took 0 MS
1485322859726 addons.xpi-utils DEBUG Finished async read of XPI database, parsing...
1485322859728 addons.xpi-utils DEBUG Successfully read XPI database
1485322859739 addons.manager DEBUG Starting provider: <unnamed-provider>
1485322859739 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
1485322859740 addons.manager DEBUG Provider finished startup: <unnamed-provider>
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
1485322859848 addons.manager DEBUG Starting provider: PreviousExperimentProvider
1485322859849 addons.manager DEBUG Registering shutdown blocker for PreviousExperimentProvider
1485322859849 addons.manager DEBUG Provider finished startup: PreviousExperimentProvider
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at Registration.Registration_webdriver.SetUp(Registration_webdriver.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)`
方法。
setup()
答案 0 :(得分:0)
selenium尝试使用当前安装在您计算机上的firefox。这个可能比你的硒版本支持的更新。要解决此问题,您可以下载兼容的firefox版本并将其传递到DesiredCapabilities中。阅读受支持的firefox版本selenium changelog总是有帮助的。
DesiredCapabilities capabilities = new DesiredCapabilities();
// linux
capabilities.setCapability(FirefoxDriver.BINARY, "/path/to/your_firefox/firefox-bin");
// win
capabilities.setCapability(FirefoxDriver.BINARY, "C:\\path\\to\\your_firefox\\firefox.exe");
WebDriver webdriver = new FirefoxDriver(capabilities);
答案 1 :(得分:0)
刚刚降级到firefox 47.0.1并禁用更新。每当firefox更新到版本50时,我都会遇到这个问题。(在selenium 2.x和3.x上测试的问题)。
请查看here