I have created a maven project , with cucumber BDD and testNG . However to use testng i need to install the testng pluggin from eclipse help . The problem is my company has blocked usage of such external connections . Is there an alternative for this .
Following are your options.
See if you can get an approval from your company's IT department to whitelist the eclipse plugin download site so that you can install it via eclipse (or) have them download the eclipse plugin jar separately, and you can drop the jar in the dropins folder so that eclipse is aware of it. For more information, please refer to the answers of this stackoverflow question.
If available, resort to using an alternative IDE such as IntelliJ. IntelliJ unlike eclipse, comes pre-installed with the TestNG plugin and should suffice.
You leverage the build tool such as Maven/Ant/Gradle to run your tests from the command prompt. Both Maven and Gradle lets you run even 1 single test also at a given time. So you should be able to easily run tests without the IDE, from the command prompt (which is eventually how your tests would be run in a Continuous Integration environment such as Jenkins)
You create a main() method housing class, which would use the TestNG APIs directly to create tests. So every-time you want to run a TestNG test class or a suite etc., you would merely go back to your runner class, update it with the details and then run via it [ To me this option should be your last resort]
Here's a full fledged sample for option (4), which you should be able to start tweaking for your own use.
public class Practice {
public static void main(String[] args) {
for (String each : new String[]{"A", "B"}) {
runWith(each);
}
}
private static void runWith(String group) {
TestNG testNG = new TestNG();
XmlSuite xmlSuite = new XmlSuite();
xmlSuite.setName("suite");
XmlTest xmlTest = new XmlTest(xmlSuite);
xmlTest.setName("test");
xmlTest.addIncludedGroup(group);
XmlClass clazz = new XmlClass(Practice.class);
clazz.loadClasses();
xmlTest.getClasses().add(clazz);
testNG.setXmlSuites(Collections.singletonList(xmlSuite));
System.out.println(xmlSuite.toXml());
testNG.run();
}
#Test(dataProvider = "SearchProvider", groups = "A")
public void testMethodA(String author, String searchKey) {
System.out.println("testMethodA :" + author + ", " + searchKey);
}
#Test(dataProvider = "SearchProvider", groups = "B")
public void testMethodB(String searchKey) {
System.out.println("testMethodB :" + searchKey);
}
#DataProvider(name = "SearchProvider")
public Object[][] getDataFromDataprovider(ITestContext c) {
Object[][] groupArray = null;
for (String group : c.getIncludedGroups()) {
if (group.equalsIgnoreCase("A")) {
groupArray = new Object[][]{
{"Guru99", "India"},
{"Krishna", "UK"},
{"Bhupesh", "USA"}
};
break;
} else if (group.equalsIgnoreCase("B")) {
groupArray = new Object[][]{
{"Canada"},
{"Russia"},
{"Japan"}
};
}
break;
}
//return groupArray;
return groupArray;
}
}
I am trying to write a plugin which parses the source code of any opened (java) file.
All I have found so far is IResourceChangeListener, but what I need is a Listener for some kind of "onRecourceOpenedEvent".
Does something like that exist?
The nearest you can get to this is to use an IPartListener to list to part events:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener(listener);
In the listener the partOpened tells you about a new part opening:
public void partOpened(IWorkbenchPart part) {
// Is this an editor
if (part instanceof IEditorPart) {
IEditorPart editor = (IEditorPart)part;
// Get file being edited
IFile file = (IFile)editor.getAdapter(IFile.class);
// TODO file is the current file - may be null
}
}
same code is running in firefox but it is not executing in IE9 and displaying the String message "This is the initial start page for the WebDriver server." while no error found on others
public void setUp() throws Exception {
File file = new File("C:/Users/Sunil.Wali/Desktop/Softwares/IEDriverServer_Win32_2.37.0/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
driver = new InternetExplorerDriver();
// driver = new FirefoxDriver();
baseUrl = "https://tssstrpms501.corp.trelleborg.com:12001";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testLogin() throws Exception {
driver.get(baseUrl + "/ProcessPortal/login.jsp");
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("sunil.wali");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("Trelleborg#123");
driver.findElement(By.id("log_in")).click();
driver.findElement(By.id("processPortalUserDropdown")).click();
driver.findElement(By.id("dijit_MenuItem_56_text")).click();
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
Output:-
Started InternetExplorerDriver server (32-bit)
2.37.0.0
Listening on port 31651
Make sure you have same value of Protected Mode settings for each zone. Refere Required Configuration for IE.
UPDATE: setting ignoreZoomSetting and ignoreProtectedModeSettings capabilities to true helps when you don't have access to change settings.
If you are using qaf you can set capabilities as below:
driver.name=iexplorerDriver
iexplorer.additional.capabilities={'ignoreProtectedModeSettings':true,'ignoreZoomSetting':true,'nativeEvents':false,'acceptSslCerts':true}
On IE 7 or higher on Windows Vista or Windows 7, you must set the
Protected Mode settings for each zone to be the same value. The value
can be on or off, as long as it is the same for every zone. To set
the Protected Mode settings, choose "Internet Options..." from the
Tools menu, and click on the Security tab. For each zone, there will
be a check box at the bottom of the tab labeled "Enable Protected
Mode".
Additionally, "Enhanced Protected Mode" must be disabled for IE 10
and higher. This option is found in the Advanced tab of the Internet
Options dialog.
http://code.google.com/p/selenium/wiki/InternetExplorerDriver#Required_Configuration
Also make sure that your zoom is set up to 100%.
Try using an older version of IEDriverServer. I tried to everything like enabling protection mode and zoom on 100% but was still stuck on localhost page. So i downloaded and used an older version of iedriver 3.4 and Voila it worked.
Solution:
Modify the file ..\node_modules\protractor\lib\driverProviders\local.js
/*
* This is an implementation of the Local Driver Provider.
* It is responsible for setting up the account object, tearing
* it down, and setting up the driver correctly.
*
* TODO - it would be nice to do this in the launcher phase,
* so that we only start the local selenium once per entire launch.
* ------Modified by Jonathan Arias mail: jab504#gmail.com-----------
*/
var util = require('util'),
log = require('../logger.js'),
path = require('path'),
remote = require('selenium-webdriver/remote'),
fs = require('fs'),
q = require('q'),
DriverProvider = require('./driverProvider');
var LocalDriverProvider = function(config) {
DriverProvider.call(this, config);
this.server_ = null;
};
util.inherits(LocalDriverProvider, DriverProvider);
/**
* Helper to locate the default jar path if none is provided by the user.
* #private
*/
LocalDriverProvider.prototype.addDefaultBinaryLocs_ = function() {
if (!this.config_.seleniumServerJar) {
log.debug('Attempting to find the SeleniumServerJar in the default ' +
'location used by webdriver-manager');
this.config_.seleniumServerJar = path.resolve(__dirname,
'../../selenium/selenium-server-standalone-' +
require('../../config.json').webdriverVersions.selenium + '.jar');
}
if (!fs.existsSync(this.config_.seleniumServerJar)) {
throw new Error('No selenium server jar found at the specified ' +
'location (' + this.config_.seleniumServerJar +
'). Check that the version number is up to date.');
}
if (this.config_.capabilities.browserName === 'chrome') {
if (!this.config_.chromeDriver) {
log.debug('Attempting to find the chromedriver binary in the default ' +
'location used by webdriver-manager');
this.config_.chromeDriver =
path.resolve(__dirname, '../../selenium/chromedriver');
}
// Check if file exists, if not try .exe or fail accordingly
if (!fs.existsSync(this.config_.chromeDriver)) {
if (fs.existsSync(this.config_.chromeDriver + '.exe')) {
this.config_.chromeDriver += '.exe';
} else {
throw new Error('Could not find chromedriver at ' +
this.config_.chromeDriver);
}
}
}
if (this.config_.capabilities.browserName === 'internet explorer') {
if (!this.config_.IEDriverServer) {
log.debug('Attempting to find the Internet explorer binary in the default ' +
'location used by webdriver-manager');
this.config_.IEDriverServer =
path.resolve(__dirname, '../../selenium/IEDriverServer');
}
// Check if file exists, if not try .exe or fail accordingly
if (!fs.existsSync(this.config_.IEDriverServer)) {
if (fs.existsSync(this.config_.IEDriverServer + '.exe')) {
this.config_.IEDriverServer += '.exe';
} else {
throw new Error('Could not find IEDriverServer at ' +
this.config_.IEDriverServer);
}
}
}
};
/**
* Configure and launch (if applicable) the object's environment.
* #public
* #return {q.promise} A promise which will resolve when the environment is
* ready to test.
*/
LocalDriverProvider.prototype.setupEnv = function() {
var deferred = q.defer(),
self = this;
this.addDefaultBinaryLocs_();
log.puts('Starting selenium standalone server...');
// configure server
if (this.config_.chromeDriver) {
this.config_.seleniumArgs.push('-Dwebdriver.chrome.driver=' +
this.config_.chromeDriver);
}
if (this.config_.IEDriverServer) {
this.config_.seleniumArgs.push('-Dwebdriver.ie.driver=' +
this.config_.IEDriverServer);
}
this.server_ = new remote.SeleniumServer(this.config_.seleniumServerJar, {
args: this.config_.seleniumArgs,
port: this.config_.seleniumPort
});
//start local server, grab hosted address, and resolve promise
this.server_.start().then(function(url) {
log.puts('Selenium standalone server started at ' + url);
self.server_.address().then(function(address) {
self.config_.seleniumAddress = address;
deferred.resolve();
});
});
return deferred.promise;
};
/**
* Teardown and destroy the environment and do any associated cleanup.
* Shuts down the drivers and server.
*
* #public
* #override
* #return {q.promise} A promise which will resolve when the environment
* is down.
*/
LocalDriverProvider.prototype.teardownEnv = function() {
var self = this;
var deferred = q.defer();
DriverProvider.prototype.teardownEnv.call(this).then(function() {
log.puts('Shutting down selenium standalone server.');
self.server_.stop().then(function() {
deferred.resolve();
});
});
return deferred.promise;
};
// new instance w/ each include
module.exports = function(config) {
return new LocalDriverProvider(config);
};
Even I had the same issue . And it started working when I made sure that the two comments over here done properly
Make sure you have same value of Protected Mode settings for each zone
make sure that your zoom is set up to 100%.
Thanks A lot for the above two comments.
usage of 64 bit IEDriverServer fixed this issue for me.
I tried all the capabilities, still failed and at last 64 bit IE server fixed.
Use this below code to resolve the issue of type "This is the initial start page for the WebDriver server". In my machine its working fine.
System.setProperty("webdriver.ie.driver", "\\IEDriverServer.exe path");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
// this line of code is to resolve protected mode issue capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver=new InternetExplorerDriver();
The below code fixed the issue for me.
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capability.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
On windows7 platform I can use System.Speech.Recognition.SpeechRecognitionEngine to convert voice to text.By SpeechRecognitionEngine when the SpeechRecognized event triggered I can get some alternate words,and I can show these word to users for choise.
void engine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (this.SpeechRecognized != null)
{
this.SpeechRecognized(this, new RecognizedResultEventArgs
{
Text = e.Result.Text,
Alternates = new ReadOnlyCollection<string>(e.Result.Alternates.Select(p => p.Text).ToList())
});
}
}
By the way,when I initialise SpeechRecognitionEngine instance,I want to load some specifical word instead of use "DictationGrammar".
My program need to runing on xp platform sometimes.So I want to implament a specific vertion to run on xp operating system by use sapi5.1.
I have readed a portion of sapi 5.1 document,then I get that:in sapi5.1,I can use "command and control" way to do that. but the "Result.Alternates()" method can not be used when I use "command and control".So,how can I achieve the same effect of SpeechRecognitionEngine ?
I tried the following code and there is an com Eception:
public void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
{
ISpeechPhraseProperty oItem;
oItem = Result.PhraseInfo.Properties.Item(0);
if ((System.Decimal)Result.PhraseInfo.GrammarId == grammarId)
{
if (this.SpeechRecognized != null)
{
RecognizedResultEventArgs e = new RecognizedResultEventArgs();
e.Text = oItem.Name;
// The following code throws an exception
ISpeechPhraseAlternates alternates = Result.Alternates(10);
List<string> s = new List<string>();
foreach (ISpeechPhraseAlternate item in alternates)
{
s.Add(item.RecoResult.PhraseInfo.Properties.Item(0).Name);
}
e.Alternates = new ReadOnlyCollection<string>(s);
this.SpeechRecognized(this, e);
}
}
}
Is there any way to get the alternates by use sapi by way of COM?Thank you.
In SAPI (any version), command and control grammars don't have alternates. Only dictation grammars have alternates.
I have a VB.NET application that takes command-line arguments.
It works fine when debugging provided I turn off Visual Studio's ClickOnce security setting.
The problem occurs when I try to install the application on a computer via ClickOnce and try to run it with arguments. I get a crash when that happens (oh noes!).
There is a workaround for this issue: move the files from the latest version's publish folder to a computer's C: drive and remove the ".deploy" from the .exe. Run the application from the C: drive and it will handle arguments just fine.
Is there a better way to get this to work than the workaround I have above?
Thanks!
"Command-line arguments" only work with a ClickOnce app when it is run from a URL.
For example, this is how you should launch your application in order to attach some run-time arguments:
http://myserver/install/MyApplication.application?argument1=value1&argument2=value2
I have the following C# code that I use to parse ClickOnce activation URL's and command-line arguments alike:
public static string[] GetArguments()
{
var commandLineArgs = new List<string>();
string startupUrl = String.Empty;
if (ApplicationDeployment.IsNetworkDeployed &&
ApplicationDeployment.CurrentDeployment.ActivationUri != null)
{
// Add the EXE name at the front
commandLineArgs.Add(Environment.GetCommandLineArgs()[0]);
// Get the query portion of the URI, also decode out any escaped sequences
startupUrl = ApplicationDeployment.CurrentDeployment.ActivationUri.ToString();
var query = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
if (!string.IsNullOrEmpty(query) && query.StartsWith("?"))
{
// Split by the ampersands, a append a "-" for use with splitting functions
string[] arguments = query.Substring(1).Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries).Select(a => String.Format("-{0}", HttpUtility.UrlDecode(a))).ToArray();
// Now add the parsed argument components
commandLineArgs.AddRange(arguments);
}
}
else
{
commandLineArgs = Environment.GetCommandLineArgs().ToList();
}
// Also tack on any activation args at the back
var activationArgs = AppDomain.CurrentDomain.SetupInformation.ActivationArguments;
if (activationArgs != null && activationArgs.ActivationData.EmptyIfNull().Any())
{
commandLineArgs.AddRange(activationArgs.ActivationData.Where(d => d != startupUrl).Select((s, i) => String.Format("-in{1}:\"{0}\"", s, i == 0 ? String.Empty : i.ToString())));
}
return commandLineArgs.ToArray();
}
Such that my main function looks like:
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
var commandLine = GetArguments();
var args = commandLine.ParseArgs();
// Run app
}