Trigger Automated Test from Testrail to Ranorex - ranorex

Anyone had also worked with TestRail(maybe by a click of a button) trigger automated test run in Ranorex and return the result/s back to testrail.
Would it be possible to share to us the steps you made and maybe a sample code.
Can you highlight how you run multiple test case in Ranorex.
Thanks!

I have used TestRails API binding for .NET (http://docs.gurock.com/testrail-api2/bindings-dotnet) for writing a simple C# file in Ranorex.
The idea is to have a test run with tests in TestRail and Ranorex posting to TestRail about the success of the test execution of these tests.
var testCase = TestCase.Current.Parameters["test_case"];
var runID = TestSuite.Current.Parameters["run_id"];
if (String.IsNullOrEmpty(testCase))
{
Report.Failure("Test case '" + TestCase.Current.Name + "' has no test case id defined !");
return;
}
if (String.IsNullOrEmpty(runID))
{
Report.Failure("Test suite '" + TestSuite.Current.Name + "' has no run id defined !");
return;
}
APIClient client = new APIClient("https://<your_server>");
client.User = "<user>";
client.Password = "<api_key>";
var data = new Dictionary<string, object>
{
{ "status_id", 1 }, // 1 = successful
{ "comment", "test case executed in Ranorex" }
};
JObject r = (JObject) client.SendPost("add_result_for_case/" + runID + "/" + testCase, data);
Ranorex.Report.Info(r.ToString());
This posts the result for one case to Ranorex (therefore the add_result_for_case method. The runID is a parameter I give in command line when I execute the suite and each test case in Ranorex corresponds to one test case in TestRail and must hold the test case id.
Take a look at http://docs.gurock.com/testrail-api2/start about what possibilities the TestRail api offers

Related

Azure DevOps Server 2019 Programmatially copy test case error Exception: 'TF237124: Work Item is not ready to save'."

I'm able to copy most test cases with this code (trying to copy shared steps to be part of the test case itself) but this one will not copy but I can not see any error message as to why - could anyone suggest anything else to try. See output from Immediate windows. Thanks John.
?targetTestCase.Error
null
?targetTestCase.InvalidProperties
Count = 0
?targetTestCase.IsDirty
true
?targetTestCase.State
"Ready"
?targetTestCase.Reason
"New"
foreach (ITestAction step in testSteps)
{
if (step is ITestStep)
{
ITestStep sourceStep = (ITestStep)step;
ITestStep targetStep = targetTestCase.CreateTestStep();
targetStep.Title = sourceStep.Title;
targetStep.Description = sourceStep.Description;
targetStep.ExpectedResult = sourceStep.ExpectedResult;
//Copy Attachments
if (sourceStep.Attachments.Count > 0)
{
string attachmentRootFolder = _tfsServiceUtilities.GetAttachmentsFolderPath();
string testCaseFolder = _tfsServiceUtilities.CreateDirectory(attachmentRootFolder, "TestCase_" + targetTestCase.Id);
//Unique folder path for test step
string TestStepAttachementFolder = _tfsServiceUtilities.CreateDirectory(testCaseFolder, "TestStep_" + sourceStep.Id);
using (var client = new WebClient())
{
client.UseDefaultCredentials = true;
foreach (ITestAttachment attachment in sourceStep.Attachments)
{
string attachmentPath = TestStepAttachementFolder + "\\" + attachment.Name;
client.DownloadFile(attachment.Uri, attachmentPath);
ITestAttachment newAttachment = targetTestCase.CreateAttachment(attachmentPath);
newAttachment.Comment = attachment.Comment;
targetStep.Attachments.Add(newAttachment);
}
}
}
targetTestCase.Actions.Add(targetStep);
targetTestCase.Save();
}
Since this code works for most test cases, this issue may come from the particular test case. In order to narrow down the issue, please try the following items:
Run the code on another client machine to see whether it works.
Try to modify this particular test case using the account API uses, to see whether it can be saved successfully.
Try validate the WorkItem prior to save. The validate() method will return an arraylist of invalid fields.

Schedule Jenkins job using Jenkins Rest API

I have a Jenkins job which is scheduled for a specific time. I want to modify that timing programmatically.
I tried to modify the build by installing Schedule Build plugin and modify it using http://jenkins_url/job/jobname/build?delay=3344sec. But this will put the job in quiet period which holds the java thread. I'm looking to modify the Schedule entry without putting it to quiet period.
You can use the Build Triggers -> Build periodically job configuration option. Use that to specify the exact time for starting a new build.
If you need to change that time, use the Jenkins REST API to...
programmatically retrieve the job configuration in XML format, then
modify the scheduling time in that configuration (see below)
re-post the new job configuration
In bash, this can be done with a one-liner (using curl and sed) to modify the XML section below (the example schedules a run for noon, Feb 29):
[...]
<triggers>
<hudson.triggers.TimerTrigger>
<spec>00 12 29 02 * </spec>
</hudson.triggers.TimerTrigger>
</triggers>
[...]
Note:
as a plus you wouldn't depend on any supplementary plugins
caveat: you cannot specify a year in the schedule -- so if you need to schedule builds more than one year in advance then you need some magic on top.
I can't get it to work, but the source code for the plugin references a "schedule" url action and a "date" param.
I tried something like:
http://localhost:8080/job/jobname/job/develop/schedule?date=2020-02-20
Which it didn't reject but I can't see a build.
below is the source code of the action performed when the button is pressed to schedule:
var newRequest = function() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
var sumbitScheduleRequest = function(absoluteUrl, quietPeriodInSeconds, isJobParameterized){
if(isJobParameterized){
// if job has parameters, redirect to build page, so user can set parameters
window.location = absoluteUrl + "build?delay=" + quietPeriodInSeconds + "sec";
}else{
// if job has NO parameters, submit build directly
var csrfCrumb;
var csrfRequest = newRequest();
csrfRequest.onreadystatechange = function() {
if (csrfRequest.readyState === 4) {
if (csrfRequest.status === 200 || csrfRequest.status === 201) {
csrfCrumb = JSON.parse(csrfRequest.responseText);
} else {
// csrf might be deactivated
}
// do the actual submit
var xmlhttp = newRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState === 4) {
if (xmlhttp.status === 200 || xmlhttp.status === 201) {
window.location = absoluteUrl;
return false;
} else {
window.location = absoluteUrl;
return false;
}
}
};
xmlhttp.open("POST", absoluteUrl + "build?delay=" + quietPeriodInSeconds + "sec", true);
if (csrfCrumb) {
xmlhttp.setRequestHeader(csrfCrumb.crumbRequestField, csrfCrumb.crumb)
}
xmlhttp.send();
}
};
csrfRequest.open('GET', rootURL + '/crumbIssuer/api/json', false);
csrfRequest.send();
}
}

UFT 12.02 QTP integration with TFS

I am looking for UFT and TFS integration (Run test from TFS like we did with HPQC)
I search on google but no help . If anyone know how to do this please let me know steps.
Thanks
You can use Generic Test to call QTP during the testing in TFS. Make sure QTP is installed on the test agent. See the code here for reference:
QTP TFS Generic Test Integration.
One more link for reference: Executing remote QTP scripts via Test Agents and Test Controllers.
Take a look at a solution from OpsHub.
More details:
Announcement:
http://blogs.msdn.com/b/visualstudioalm/archive/2013/05/16/enabling-seamless-integration-with-team-foundation-server-microsoft-test-professional-and-hp-alm-with-opshub-v5-3.aspx
Video:
http://opshub.com/ohrel/Resources/Videos/QTP_MTM_Video/QTP_MTM_Video.mp4
Case study:
https://customers.microsoft.com/Pages/CustomerStory.aspx?recid=17218
Take a look into this code:
import QTObjectModelLib dll from C:\Program Files (x86)\HP\Unified Functional Testing\bin location to your solution.
public void Fn_QTP()
{
qtApp.Launch();
qtApp.Visible = true;
qtApp.Options.Run.RunMode = "Fast";
qtApp.Options.Run.StepExecutionDelay = 0;
qtApp.Options.Run.ViewResults = false;
qtApp.Test.Settings.Run.OnError = "Stop";
//iterate for all test cases under selected module
// oTestSuiteDict : this dictionary conatins all the testsuites from TFS which meant to be executed.
//keys have their ID's
foreach (var item in oTestSuiteDict.Keys)
{
foreach (var TestCase in oTestSuiteDict[item].Keys)
{
Console.WriteLine("Executing TestCase : {0}", TestCase);
//update the XML file and upload in QTP
//this XML file is used to provide the data to QTP as a environment variables.
Fn_UpdateXMLFile(item, TestCase);
//Open the test Case
string scriptPath = #"path of script that will be opened in QTP (Action)";
qtApp.Open(scriptPath, true, false);
// Get a reference to the test object
qtTest = qtApp.Test; // Get reference to test object opened/created by application
qtTest.Settings.Run.OnError = "NextStep";
//check if the library is already associated.
if (qtTest.Settings.Resources.Libraries.Find(#"library path") == 1)
{
qtTest.Settings.Resources.Libraries.RemoveAll();
}
qtTest.Settings.Resources.Libraries.Add(#"Library Path");
//Console.WriteLine("Library is associated with Test");
// Get a reference to the Results Object for test results location
QTObjectModelLib.RunResultsOptions qtRRO = new QTObjectModelLib.RunResultsOptions();
// Run the test
//creates and start the instance of Stopwatch just to track the time period of testcase execution.
Stopwatch stopwatch = Stopwatch.StartNew();
qtTest.Run(qtRRO, true, null); // run the test
stopwatch.Stop();
string oTime = stopwatch.Elapsed.ToString();
oTestCaseTime.Add(TestCase, oTime);
string ostatus = qtTest.LastRunResults.Status;
oResults.Add(TestCase, ostatus);
qtTest.Close(); // Close the test
}
}
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(qtTest); // Cleanly release COM object
qtTest = null; // set object to null
//break;
//qtApp.Quit(); // Quit QTP
GC.Collect(); // Garbage collect
GC.WaitForPendingFinalizers(); // Wait for GC
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(qtApp); // Cleanly release COM Object
qtApp = null; // set to null
}
// Fn_UpdateXMLFile : function to update environment variables for qtp
//module name : the testsuite name(contains list of testcases); testcasename : testcases listed in modulename(test suite)
public void Fn_UpdateXMLFile(string modulename,string testcasename)
{
string oPath = #"path of xml file";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(oPath);
XmlNodeList nodes = xmlDoc.SelectNodes("Environment/Variable/Value");
nodes[0].InnerText = modulename;
nodes[1].InnerText = testcasename;
xmlDoc.Save(oPath);
}
//format of XML file :
<Environment>
<Variable>
<Name>ModuleName</Name>
<Value>ToolsMenu</Value>
</Variable>
<Variable>
<Name>""</Name>
<Value>""</Value>
</Variable>
</Environment>

Google AdWords Script AdGroupBidModifierService

I found this script at Google AdWords Script API. https://developers.google.com/adwords/api/docs/guides/adgroup-bid-modifiers
But I get error at line 2: "Missing ; before statement (line 3)". I can't seem to find the problem.
// Get the AdGroupBidModifierService.
AdGroupBidModifierServiceInterface bidModifierService = adWordsServices.get(session, AdGroupBidModifierServiceInterface.class);
// Create selector.
Selector selector = new Selector();
selector.setFields(
new String[] {"CampaignId", "AdGroupId", "Id", "BidModifier"});
selector.setPaging(new Paging(0, 10));
// Make a 'get' request.
AdGroupBidModifierPage page = bidModifierService.get(selector);
// Display bid modifiers.
if (page.getEntries() != null) {
for (AdGroupBidModifier modifier : page.getEntries()) {
String value = (modifier.getBidModifier() == null) ?
"unset" : String.valueOf(modifier.getBidModifier())
System.out.println("Campaign ID " + modifier.getCampaignId()
+ ", AdGroup ID " + modifier.getAdGroupId()
+ ", Criterion ID " + modifier.getCriterion().getId()
+ " has ad group level modifier: " + value);
}
} else {
System.out.println("No bid modifiers were found.");
}
Anyone else experienced problem with this code? Also is it possible to get it to work with AdWords.App?
First: You can not use Java code in AdWords Scripts, you must use javascript. See more about Adwords Scripts in: https://developers.google.com/adwords/scripts/
Second: You can not get the CPC for old dates, just the current CPC bid
Are you doing this as part of a Java application, or within the Google AdWords script editor?
If the latter, that's the problem. The Google Script editor works off Google Script (which is essentially JavaScript)

Parse REST Request in SOAPUI Mock Service

I am trying to achieve a very simple goal in soapui
I have created a mock rest service in soapui that I can return static content from if the last resource matches a file name. problem is:
I use Spring RESTTemplate to make a REST call ala:
http://www.sample.com/user/group/{1}/status
where {1} is the only variable (it will be a number like 1111 or 2323)
In the OnRequest script section I should be able to write something simple that allows me to extract this resource from the full url and then craft a return of a static file of the same name ie:
ref = value.at.specified.location.{1}.in.url
return file(ref.xml)
any help translating these 2 pseudo code lines to actual working code would be helpful
this works:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
path = groovyUtils.getProjectPath() + "/docroot/" + mockRequest.getPath().tokenize('/')[4] + ".xml";
try
{
mockRunner.returnFile(mockRequest.httpResponse, new File(path));
mockRequest.httpResponse.status = 201
}
catch (Exception e)
{
mockRequest.httpResponse.status = 403
}
return new com.eviware.soapui.impl.wsdl.mock.WsdlMockResult(mockRequest);

Resources