I am running a test suite in Soap UI where I am trying to call one ruby script from groovy script. The step is getting executed successfully but still the script is not able to move on to the next step as it gives this error after running.
Have searched in google about this error, but found no proper resolution. Moreover the error itself is not very explanatory.
Will appreciate any kind of help.
Below is the groovy script which is calling "ap-v4-batch_DEV_QA.rb" ruby script.
This ruby script opens a browser and performs the task successfully and closes the browser. We expect the step to be marked as Passed so that it can move on to the next step, but it gives the error mentioned at the bottom.
Groovy Script:
String script = "webdriver/v4/ap-v4-batch_DEV_QA.rb";
String argv0 = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("GLOB_DefaultIP");
String argv1 = "com.wupay.batch.process.tasks.PaymentFileParsingTask_RunOnce";
String argv2 = "";
String argv3 = "";
String argv4 = "";
/* Nothing needs to be modified below */
String commandLine = "ruby " + com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("GLOB_ScriptLocation") + "/" + script + " " + argv0 + " " + argv1 + " " + argv2 + " " + argv3 + " " + argv4;
log.info("Running command line: " + commandLine);
java.lang.Runtime runtime = java.lang.Runtime.getRuntime();
java.lang.Process p = runtime.exec(commandLine);
def propertyStep = testRunner.testCase.getTestStepByName("Properties");
java.io.BufferedReader stdInput =
new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream()));
java.io.BufferedReader stdError =
new java.io.BufferedReader(new java.io.InputStreamReader(p.getErrorStream()));
String s = null;
String e = null;
StringBuffer eb = new StringBuffer();
while ((e = stdError.readLine()) != null) {
eb.append(e);
log.error("Ruby: " + e);
}
while ((s = stdInput.readLine()) != null) {
log.info("Ruby: " + s);
if(s.startsWith("#prop")) {
String[] propSplit = s.split(":", 3);
testRunner.testCase.setPropertyValue(propSplit[1], propSplit[2]);
}
}
p.waitFor();
log.info("Ruby: exit value " + p.exitValue());
if(eb.length() > 0) {
throw new Exception(eb.toString());
}
Error:
java.lang.Exception: C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in require':require "watir-webdriver"is deprecated. Please, userequire "watir". java.lang.Exception: C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:inrequire': require "watir-webdriver" is deprecated. Please, use require "watir". error at line: 57
I have finally resolved the issue.
The issue was that ruby script was not accepting require "watir-webdriver".
I installed watir and replaced require "watir-webdriver" with require "watir".
now I am not getting the above mentioned error.
Thanks anyways!
Regards,
Faraz
Related
I am working on a jsx (extendscript project) in which I am calling a VBS snippet with app.doScript. I cannot get the email_cc and email_cc2 recipients to show up as cc; they are stuck in the main "To" sending. I will not know in advance whether they exist in the users' address book, so I am adding them as recipients than trying to set their Type.
var vbs = 'Dim objOutl\r';
vbs += 'Set objOutl = CreateObject("Outlook.Application")\r';
vbs += 'Set objMailItem = objOutl.CreateItem(olMailItem)\r';
vbs += 'objMailItem.Display\r';
vbs += 'strEmailAddress = "' + email_address + '"\r';
vbs += 'objMailItem.Recipients.Add strEmailAddress\r';
vbs += 'strSubject = "' + the_subject + '"\r';
vbs += 'objMailItem.Subject = strSubject\r';
vbs += 'objMailItem.Body = "' + the_bodytext + '"\r';
if (email_cc && email_cc != "") {
vbs += 'Set cc1Recipient = objMailItem.Recipients.Add ("' + email_cc + '")\r';
if (email_cc2 && email_cc2 != "") {
vbs += 'Set cc2Recipient = objMailItem.Recipients.Add ("' + email_cc2 + '")\r';
vbs += 'cc1Recipient.Type = olCC\r';
vbs += 'cc2Recipient.Type = olCC\r';
}
else {
vbs += 'cc1Recipient.Type = olCC\r';
}
}
if (has_attachment) {
vbs += 'objMailItem.Attachments.Add "' + pdf_file + '"\r';
}
Check out the following points:
Try to use the fully qualified name in the code with the enum name, for example:
OlMailRecipientType.olCC
Use the Resolve method which attempts to resolve a recipient object against the address book. It returns true if the recipient was resolved.
Call the Save method to apply changes made through the OOM. Sometimes it makes sense to close the item, switch to another Outlook item, and then come back to check out results. Outlook caches changes and doesn't propagate changes made using the OOM immediately.
Read more about these methods and properties in the How To: Fill TO,CC and BCC fields in Outlook programmatically article.
I am trying to execute a groovy script on a unix environnement but i have an issue, I don't know how to write a shell script that could execute the script under :
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.servicelayer.search.FlexibleSearchService;
import de.hybris.platform.servicelayer.search.SearchResult;
import com.galerieslafayette.pcm.model.model.product.RmsProductModel ;
final FlexibleSearchService flexibleSearchService = spring.getBean("flexibleSearchService");
final ModelService modelService = spring.getBean("modelService");
new File("/tmp/productsToUpdate.csv").splitEachLine(";") {fields ->
criteria = fields[1]
if (fields[2]?.trim()) {
criteria += "</p><p>" + fields[2]
}
if (fields[3]?.trim()) {
criteria += "</p><p>" + fields[3]
}
criteria = "<p>" + criteria + "</p>"
updateProduct(fields[0], criteria)
}
def updateProduct(ugProduct, criteria) {
SearchResult<RmsProductModel> result = flexibleSearchService.search("select {pk} from {RmsProduct} where {ug}=?ugCode", ["ugCode":ugProduct]);
if(result.getResult().get(0) != null){
RmsProductModel rmsProduct = result.getResult().get(0);
String temp = rmsProduct.getProduct().getDescription(Locale.FRANCE);
rmsProduct.getProduct().setDescription(temp + criteria, Locale.FRANCE)
modelService.save(rmsProduct.getProduct());
}
}
I tried to find on the web how to do so, but i only find subject on how to run shell in a groovy and not the opposite.
I am a beginner on unix and don't know the command line or if i need a specifique addition on my environnement or if vanilla shell could do it
I am using Jmeter for API automation, I am writing result pass or fail in CSV file.
I am unable to overwrite old result data, Every time I run the test cases it's appending with old result data.
I use Beanshell Post processor for writing in CSV file.
import java.io.file;
import org.apache.jmeter.services.FileServer;
ActualResponseCode = prev.getResponseCode();
if (vars.get("ExpectedResponse").equals(vars.get("ActualResponse")))
{
if(vars.get("ExpectedResponseCode").equals(prev.getResponseCode()))
{
prev.setSuccessful(true);
Result = "Pass";
ErrorMessage = "No Error";
}
else
{
Result = "Fail";
ErrorMessage = "ResponseCode not matching";
}
}
else
{
prev.setSuccessful(false);
Result = "Fail";
ErrorMessage = "ResponseData is not matching";
}
f = new FileOutputStream("C://Users//a622821//Desktop//apache-jmeter-3.2//API_AUTOMATION//TestResult_Post.csv", true);
p = new PrintStream(f);
p.println(vars.get("TestCase") + "," + vars.get("API_Endpoint") + "," + vars.get("ExpectedResponseCode") + "," + ActualResponseCode + "," + Result + "," + ErrorMessage);
p.close();
f.close();
Basically when you write to file you can overrid file by using boolean false as second parameter to FileWriter constructor
File file = ....
new FileWriter(file, false);
If you have several calls for beanshell I suggest create Beanshell sampler which will be called in start of the test and will override the file (create empty file):
import java.io.file;
f = new FileOutputStream("C://Users//a622821//Desktop//apache-jmeter-3.2//API_AUTOMATION//TestResult_Post.csv", false);
p = new PrintStream(f);
p.close();
f.close();
If you must use same beanshell you need a variable flag, so add variable firstTime with value true
In Beanshell use it to set the flag by firstTime variable:
import java.io.file;
import org.apache.jmeter.services.FileServer;
ActualResponseCode = prev.getResponseCode();
if (vars.get("ExpectedResponse").equals(vars.get("ActualResponse")))
{
if(vars.get("ExpectedResponseCode").equals(prev.getResponseCode()))
{
prev.setSuccessful(true);
Result = "Pass";
ErrorMessage = "No Error";
}
else
{
Result = "Fail";
ErrorMessage = "ResponseCode not matching";
}
}
else
{
prev.setSuccessful(false);
Result = "Fail";
ErrorMessage = "ResponseData is not matching";
}
firstTime = vars.get("firstTime");
flag = true;
if ("true".equals(firstTime)) {
flag = false;
vars.put("firstTime", "false");
}
f = new FileOutputStream("C://Users//a622821//Desktop//apache-jmeter-3.2//API_AUTOMATION//TestResult_Post.csv", flag);
p = new PrintStream(f);
p.println(vars.get("TestCase") + "," + vars.get("API_Endpoint") + "," + vars.get("ExpectedResponseCode") + "," + ActualResponseCode + "," + Result + "," + ErrorMessage);
p.close();
f.close();
Test Plan variable:
Don't use scripting to write anything to files, JMeter is able to store literally anything into its .jtl results file so I would recommend rather configuring it to store what you need there rather than trying to create an extra results file in such a weird manner as:
Beanshell is not the best scripting option, if you need to go for scripting consider using JSR223 Test Elements and Groovy language instead
If you are writing something into a file make sure you put aforementioned JSR223 Elements under the Critical Section Controller
So I would suggest switching to either Response Assertion or JSR223 Assertion instead of the PostProcessor. If required you can tell JMeter to store assertion failure message by adding the next line to user.properties file (located in the "bin" folder of JMeter installation, however I think it defaults to true in any case)
jmeter.save.saveservice.assertion_results_failure_message=true
Check out Scripting JMeter Assertions in Groovy - A Tutorial for more details.
I am using JMeter to test some of the functionality on my site. Through using the Save Responses to a file element, I have been able to successfully issue a request to download a pdf through JMeter. However, I am curious if there is an assertion to check that a file has actually downloaded (and if possible, is in the format I specified!). I know I can simply look at the file, but I'm hoping to make this more automated. I have checked "Save Successful Responses Only," but I want to ensure a response has actually been saved.
I think you need to use a Beanshell Assertion for this.
Example code to check file presence, size and content type is below:
File file = new File("/path/to/downloaded/file");
//check file existence
if (!file.exists())
{
Failure = true;
FailureMessage = "File " + file.getName() + " does not exist";
}
//check file size
long expectedSize = SampleResult.getBodySize();
long actualSize = file.length();
if (expectedSize != actualSize)
{
Failure = true;
FailureMessage = "Actual file size differs from expected. Expected: " + expectedSize + " and got: " + actualSize ;
}
//check content type
String expectedType = SampleResult.getContentType();
String actualType = file.toURI().toURL().openConnection().getContentType();
if (!expectedType.equals(actualType))
{
Failure = true;
FailureMessage = "Response types are different. Expected: " + expectedType + " and got: " + actualType;
}
See How to Use JMeter Assertions in 3 Easy Steps guide for more information on JMeter Assertions superpower.
I have a script that is rather simple, it boots up WinSCP and checks the directory for a file that starts with "TSA". If the file exists, it exits, if it does not exist, it transfers over a new file.
Its up and running on my Windows 7 machine, that is where i created it - but when i transfer it over to my server [windows server 2003] it never finds the file.
My script:
var FILEPATH = "../zfinance/TSA";
// Session to connect to
var SESSION = "someplace#somewhere.com";
// Path to winscp.com
var WINSCP = "c:\\program files\\winscp\\winscp.com";
var filesys = WScript.CreateObject("Scripting.FileSystemObject");
var shell = WScript.CreateObject("WScript.Shell");
var logfilepath = filesys.GetSpecialFolder(2) + "\\" + filesys.GetTempName() + ".xml";
var p = FILEPATH.lastIndexOf('/');
var path = FILEPATH.substring(0, p);
var filename = FILEPATH.substring(p + 1);
var exec;
// run winscp to check for file existence
exec = shell.Exec("\"" + WINSCP + "\" /log=\"" + logfilepath + "\"");
exec.StdIn.Write(
"option batch abort\n" +
"open \"" + SESSION + "\"\n" +
"ls \"" + path + "\"\n" +
"exit\n");
// wait until the script finishes
while (exec.Status == 0)
{
WScript.Sleep(100);
WScript.Echo(exec.StdOut.ReadAll());
}
if (exec.ExitCode != 0)
{
WScript.Echo("Error checking for file existence");
WScript.Quit(1);
}
// look for log file
var logfile = filesys.GetFile(logfilepath);
if (logfile == null)
{
WScript.Echo("Cannot find log file");
WScript.Quit(1);
}
// parse XML log file
var doc = new ActiveXObject("MSXML2.DOMDocument");
doc.async = false;
doc.load(logfilepath);
doc.setProperty("SelectionNamespaces",
"xmlns:w='http://winscp.net/schema/session/1.0'");
doc.setProperty("SelectionLanguage", "XPath");
var nodes = doc.selectNodes("//w:file/w:filename[starts-with(#value, '" + filename + "')]");
if (nodes.length > 0)
{
WScript.Echo("File found");
WScript.Quit(0);
}
else
{
WScript.Echo("File not found");
WScript.Quit(1);
}
After much investigation, i think i've found the piece of code that does not function properly:
// parse XML log file
var doc = new ActiveXObject("MSXML2.DOMDocument.6.0");
doc.async = false;
doc.load(logfilepath);
doc.setProperty("SelectionNamespaces",
"xmlns:w='http://winscp.net/schema/session/1.0'");
The only problem is, i have no idea why. The log file at this point should be written over with the xml code, but this does not happen.
Thanks in advance for any help.
And the answer is........... WinSCP on Windows Server 2003 was WAY out of date. So out of date that the log was completely different from one version to the next. Updated and VIOLA! Problem solved. Thanks for your help.
Maybe you need to install MSXML2.DOMDocument.6.0
http://msdn.microsoft.com/en-us/library/windows/desktop/cc507436%28v=vs.85%29.aspx
If you open up regedit and look for "MSXML2.DOMDocument.6.0" does it find it? If so maybe security settings for the script need to be set in order to be able to create an activeX object.
What can you see when you put some stuff in try catch?
try{
//stuff
}catch(e){
WScript.Echo(e.message);
}