QC OTA : How to add an Test Iteration in Test Lab->Test Set->Test case->Test Instance Details->Execution Settings using QC OTA - alm

I am able to read the Test set and the tests in the set using OTA, but not able to get the object of Test Iteration in Test Lab.enter image description here

Add a Test Iteration in Test Lab->Test Set->Test Case->Test Instance Details->Execution Settings using QC OTA.
First, you need to find the Test Case object. It's TSTest object, which represents a test instance, or execution test, in a test set.
Then, you need to modify the value of TC_DATA_OBJ of this test instance.
For example,
ITestSetTreeManager testSetTreeManager = (ITestSetTreeManager)tdConnection.TestSetTreeManager;
TestSetFolder Root = (TestSetFolder)testSetTreeManager.Root;
TestSetFolder labFolder;
try
{
labFolder = (TestSetFolder)Root.FindChildNode("TestSetFolder");
}
catch (Exception e)
{
labFolder = null;
}
if (labFolder != null)
{
TestSetFactory testSetFactory = (TestSetFactory)labFolder.TestSetFactory;
List testSetList = testSetFactory.NewList("");
if (testSetList.Count > 0)
{
for (int testSetIndex = 1; testSetIndex <= testSetList.Count; testSetIndex++)
{
TestSet testSet = testSetList[testSetIndex];
TSTestFactory tsTestFactory = (TSTestFactory)testSet.TSTestFactory;
List tsTestList = tsTestFactory.NewList("");
TSTest tsTest;
for (int tsTestIndex = 1; tsTestIndex <= tsTestList.Count; tsTestIndex++)
{
tsTest = tsTestList[tsTestIndex];
if (tsTest.Type == "BUSINESS-PROCESS")
{
string xml =
"<DATAPACKET data_type=\"manual\"><CONFIGURATION><SELECTION first_sel_row=\"-1\" last_sel_row=\"-1\" /></CONFIGURATION><METADATA><COLUMNS>" +
"<COLUMN column_name=\"p1\" column_value_type=\"String\" />" +
"<COLUMN column_name=\"p2\" column_value_type=\"String\" />" +
"<COLUMN column_name=\"p3\" column_value_type=\"String\" />" +
"<COLUMN column_name=\"p4\" column_value_type=\"String\" /></COLUMNS></METADATA><ROWADATA>" +
"<ROW col1=\"11\" col2=\"12\" col3=\"13\" col4=\"14\"/>" +
"<ROW col1=\"21\" col2=\"22\" col3=\"23\" col4=\"24\"/>" +
"<ROW col1=\"31\" col2=\"32\" col3=\"33\" col4=\"34\"/>" +
"</ROWADATA></DATAPACKET>";
tsTest["TC_DATA_OBJ"] = xml;
tsTest.Post();
}
}
}
}
}
Note:
If you want to add a test iteration using QC OTA, you also need to keep the old values.
You just need to append a row in the below and input the value of each column.
And others remain unchanged.
I hope my answer is helpful to you.
Thank you and regards,
Wenjuan

Related

Set a JMter variable with an groovy collection (JSR223 PostProcessor)

I'm trying to set a variable in JMter with the value in a List that I have in JSR223 Processor (Groovy). For that, I'm using the method vars.putObject, but when I try to use this variable in a ForEach Controller the loop doesn't execute.
My PostProcessor has the following flow:
Get a list of strings that were generated by a Regular Expression Extractor
Create a List with the valid values for the test (filter some values)
Add the result in a JMter variable vars.putObject
import org.apache.jmeter.services.FileServer
int requestAssetsCount = vars.get("CatalogAssetIds_matchNr").toInteger()
int maxAssetsNumbers = vars.get("NumberAssets").toInteger()
List<String> validAssets = new ArrayList<String>()
def assetsBlackListCsv = FileServer.getFileServer().getBaseDir() + "\\\assets-blacklist.csv"
File assetsBlackListFile = new File(assetsBlackListCsv)
List<String> assetsBlackList = new ArrayList<String>()
log.info("Loading assets black list. File: ${assetsBlackListCsv}")
if (assetsBlackListFile.exists()) {
assetsBlackListFile.eachLine { line ->
assetsBlackList.add(line)
}
}
else {
log.info("Black list file doesn't exist. File: ${assetsBlackListCsv}")
}
log.info("Verifying valid assets")
for (def i = 1; i < requestAssetsCount; i++) {
def assetId = vars.get("CatalogAssetIds_${i}_g1")
if (!assetsBlackList.contains(assetId)) {
validAssets.add(assetId)
}
else {
log.info("Found a blacklisted asset. Skipping it. Asset ID: ${assetId}")
}
if (validAssets.size() >= maxAssetsNumbers) {
break
}
}
I've tried (like regular extractor):
log.info("Storing valid assets list")
vars.putObject("ValidCatalogAssetIds_matchNr",validAssets.size())
for(def i = 0; i < validAssets.size(); i++) {
vars.putObject("ValidAssetIds_${i+1}_g",1)
vars.putObject("ValidAssetIds_${i+1}_g0","\"id\":\"${validAssets[i]}\"")
vars.putObject("ValidAssetIds_${i+1}_g1",validAssets[i])
}
I've tried (set list value):
log.info("Storing valid assets list")
vars.putObject("ValidAssetIds",validAssets)
Concat strings as "+ (i+1) + "
vars.putObject("ValidCatalogAssetIds_"+ (i+1) + "_g",1)
vars.putObject("ValidAssetIds_"+ (i+1) + "_g0","\"id\":\"${validAssets[i]}\"")
vars.putObject("ValiAssetIds_"+ (i+1) + "_g1",validAssets[i])
Don't use ${} syntax in JSR223 scripts because it will initialize values before script executed and not as expected

Get Visible Text from RichTextBlock

In a UWP app, I am using a RichTextBlock that gets populated with some content. It has word wrapping enabled and has a max lines set so that regardless of the length of its content, it will only show a certain number of lines of rich text.
I'd like to know if there is a way to figure out what is the visible text?
So if I have:
<RichTextBlock TextWrapping="Wrap" MaxLines="2">
<RichTextBlock.Blocks>
<Paragraph>
<Paragraph.Inlines>
A bunch of runs go in here with text that are several lines
</Paragraph.Inlines>
</Paragraph>
</RichTextBlock.Blocks>
</RichTextBlock>
I'd like to know how much of the text is actually visible.
I'm trying to detect cases where the text is longer than a set number of lines and append a "... Read More" at the end of the last line (replacing the last 13 chars with "... Read More")
So I wrote some code to get the behavior that I want, but unfortunately this is rather slow and inefficient. So if you're using it in an app that is primarily to show a lot of text that needs to be truncated (like a ListView with a lot of text items) then this would slow down your app perf. I still would like to know if there is a better way to do this.
Here's my code (which only handles Run and Hyperlink inlines so you'll have to modify to handle other types that you need):
private static void TrimText_Slow(RichTextBlock rtb)
{
var paragraph = rtb?.Blocks?.FirstOrDefault() as Paragraph;
if (paragraph == null) { return; }
// Ensure RichTextBlock has passed a measure step so that its HasOverflowContent is updated.
rtb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
if (rtb.HasOverflowContent == false) { return; }
// Start from end and remove all inlines that are not visible
Inline lastInline = null;
var idx = paragraph.Inlines.Count - 1;
while (idx >= 0 && rtb.HasOverflowContent)
{
lastInline = paragraph.Inlines[idx];
paragraph.Inlines.Remove(lastInline);
idx--;
// Ensure RichTextBlock has passed a measure step now with an inline removed, so that its HasOverflowContent is updated.
rtb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
}
// The last inline could be partially visible. The easiest thing to do here is to always
// add back the last inline and then remove characters from it until everything is in view.
if (lastInline != null)
{
paragraph.Inlines.Add(lastInline);
}
// Make room to insert "... Read More"
DeleteCharactersFromEnd(paragraph.Inlines, 13);
// Insert "... Continue Reading"
paragraph.Inlines.Add(new Run { Text = "... " });
paragraph.Inlines.Add(new Run { Text = "Read More", Foreground = new SolidColorBrush(Colors.Blue) });
// Ensure RichTextBlock has passed a measure step now with the new inlines added, so that its HasOverflowContent is updated.
rtb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
// Keep deleting chars until "... Continue Reading" comes into view
idx = paragraph.Inlines.Count - 3; // skip the last 2 inlines since they are "..." and "Read More"
while (idx >= 0 && rtb.HasOverflowContent)
{
Run run;
if (paragraph.Inlines[idx] is Hyperlink)
{
run = ((Hyperlink)paragraph.Inlines[idx]).Inlines.FirstOrDefault() as Run;
}
else
{
run = paragraph.Inlines[idx] as Run;
}
if (string.IsNullOrEmpty(run?.Text))
{
paragraph.Inlines.Remove(run);
idx--;
}
else
{
run.Text = run.Text.Substring(0, run.Text.Length - 1);
}
// Ensure RichTextBlock has passed a measure step now with the new inline content updated, so that its HasOverflowContent is updated.
rtb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
}
}
private static void DeleteCharactersFromEnd(InlineCollection inlines, int numCharsToDelete)
{
if (inlines == null || inlines.Count < 1 || numCharsToDelete < 1) { return; }
var idx = inlines.Count - 1;
while (numCharsToDelete > 0)
{
Run run;
if (inlines[idx] is Hyperlink)
{
run = ((Hyperlink)inlines[idx]).Inlines.FirstOrDefault() as Run;
}
else
{
run = inlines[idx] as Run;
}
if (run == null)
{
inlines.Remove(inlines[idx]);
idx--;
}
else
{
var textLength = run.Text.Length;
if (textLength <= numCharsToDelete)
{
numCharsToDelete -= textLength;
inlines.Remove(inlines[idx]);
idx--;
}
else
{
run.Text = run.Text.Substring(0, textLength - numCharsToDelete);
numCharsToDelete = 0;
}
}
}
}

How to set order of new sharepoint list columns programmatically [duplicate]

I'm adding in two new fields into an already existing Sharepoint list programmatically through a feature. The fields are being added successfully but I have been unable to adjust the column order.
This task is done simply through the UI by going to List Settings and then Column Ordering, but I have been unable to achieve the task programmatically.
Through some research I've seen that you can use the SPContentType of the form to change the ordering of the FieldLinks (as follows):
SPList list = web.Lists["Example List"];
if (list.ContentTypes.Count > 0) {
SPContentType ct = list.ContentTypes[0];
string[] names = {"Example_x0020_One", "Example_x0020_Two", "Example_x0020_Three"};
ct.FieldLinks.Reorder(names);
ct.Update();
}
In this example, I the list would already have "Example One" and "Example Three" columns, and I would add "Example Two" later and then try to order them.
However this approach did not work for me, so if anyone has input on it, that would be appreciated.
The next item I saw is manually changing the SchemaXml of the list to have the proper order of the fields, but I wanted to see if this was the best method.
Any input would be appreciated, thank you for your help.
I took a look at the source of the Column ordering page (formEdt.aspx), it looks like they use web services, not the object model:
function DoBuildAndSubmit()
{
var numFound, currentSelect, selectValue;
var form = document.forms.aspnetForm;
var numFields = form["numSelects"].value;
var xml = "<Fields>";
numFound = 0;
while(numFound < numFields)
{
for(x = 0; x < numFields; x++)
{
currentSelect = form["FormPosition" + x];
if(currentSelect.selectedIndex == numFound)
{
selectValue = currentSelect.options[numFound].value;
xml = xml + "<Field Name=\"" + selectValue + "\"/>" + "\n";
numFound++;
}
}
}
for(x = numFields ; x < 67; x++)
xml = xml + "<Field Name=\"" + form["FormPosition" + x].value + "\"/>" + "\n";
xml = xml + "</Fields>";
document.frmLayoutSubmit["ReorderedFields"].value=xml;
document.frmLayoutSubmit.action = "http://local/_vti_bin/owssvr.dll?CS=65001";
document.frmLayoutSubmit.submit();
}
Now, it might be possible to do through the object model, but I don't have a good feeling about it when the UI is punting.
Here's a powershell version:
# Moves "FieldToBeMoved" after "Description" field
$list = $web.Lists["Documents"]
$ct = $list.ContentTypes[0] # Or find the desired CT
$newOrder = #()
foreach ($field in $ct.Fields)
{
if ($field.StaticName -ne "FieldToBeMoved")
{
$newOrder += $field.StaticName
}
if ($field.StaticName -eq "Description")
{
$newOrder += "FieldToBeMoved"
}
}
$ct.FieldLinks.Reorder($newOrder)
$ct.Update();
I used the code from your answer, except I programmatically examined the content types and fields for the list I wanted to re-order.
//Step 1 (optional): List out the content types and fields for your list to see what is in the list
SPList list = web.Lists[strListName];
string strRet="";
foreach (SPContentType spct in list.ContentTypes)
{
strRet += "<strong>Content Type: </strong>" + spct.Name + ", <strong>Fields</strong>: <br />";
foreach (SPField field in spct.Fields)
{
if (strFieldInfo != "")
{
strFieldInfo += ", ";
}
strFieldInfo += "\"" + field.StaticName + "\"";
}
strRet += strFieldInfo + "<br />-----<br />";
}
//Output the results
lblOutput.Text = strRet;
Now, you'll have an idea of how many content types your list has and what fields are in the list.
By default, if content type management is not enabled, you'll have one content type that has all the fields.
Sample output from the above code:
Content Type: Event, Fields:
"ContentType", "Title", "Location", "EventDate", "EndDate", "Description", "fAllDayEvent", "fRecurrence", "WorkspaceLink", "EventType", "UID", "RecurrenceID", "EventCanceled", "Duration", "RecurrenceData", "TimeZone", "XMLTZone", "MasterSeriesItemID", "Workspace", "Course", "CourseLocation"
Next Step 2 is to change the order of the content type. You can cut and paste from the output from step 1, re-order it, and add "{" and "};" around it to create the string array for the ordering you want.
if (list.ContentTypes.Count > 0)
{
SPContentType ct = list.ContentTypes[0]; //Specify the content type here, if you have more than one content type in your list.
string[] fieldnames = { "ContentType", "Title", "Course", "CourseLocation", "EventDate", "EndDate", "Description", "fAllDayEvent", "fRecurrence", "WorkspaceLink", "EventType", "UID", "RecurrenceID", "EventCanceled", "Duration", "RecurrenceData", "TimeZone", "XMLTZone", "MasterSeriesItemID", "Workspace", "Location"};
ct.FieldLinks.Reorder(fieldnames);
web.AllowUnsafeUpdates = true;
ct.Update(true);
web.AllowUnsafeUpdates = false;
}

Local AppData Monitor in Metro app (StorageFileQueryResult.ContentsChanged event not firing)

how would a monitor just a particular file in AppData folder.
I've tried using StorageFolderQueryResult.ContentsChanged event to handle this, but this one actually callbacks for any changes through the folder.
My problem is to just a monitor a single file and use the eventhandler when its changed.
I've tried to use this "UserSearchFilter" property to QueryOptions. That didnt work actually.
cAn someone help with this ? It would also be helpful if you could additionally provide the syntax for the whole problem.
My contentschanged event is not firing on modifying the "filename" in the folder.
auto fileTypeFilter = ref new Platform::Collections::Vector<Platform::String^>();
fileTypeFilter->Append("*");
auto queryOptions = ref new QueryOptions(CommonFileQuery::OrderBySearchRank, fileTypeFilter);
//use the user's input to make a query
queryOptions->UserSearchFilter = InputTextBox->Text;
auto queryResult = musicFolder->CreateFileQueryWithOptions(queryOptions);
auto localFolder = ApplicationData::Current->LocalFolder;
auto currPath = localFolder->Path;
auto fileTypeFilter = ref new Platform::Collections::Vector<Platform::String^>();
fileTypeFilter->Append(".dat");
auto queryOptions = ref new QueryOptions(CommonFileQuery::OrderByName, fileTypeFilter);
//use the user's input to make a query
queryOptions->UserSearchFilter = L"filename";
auto queryResult = localFolder->CreateFileQueryWithOptions(queryOptions);
queryResult->ContentsChanged += ref new TypedEventHandler<IStorageQueryResultBase^, Platform::Object^>(this, &Scenario1::OnLocalAppDataChanged);
//find all files that match the query
create_task(queryResult->GetFilesAsync()).then([this, queryOptions] (IVectorView<StorageFile^>^ files)
{
String^ outputText = "";
//output how many files that match the query were found
if ( files->Size == 0)
{
outputText += "No files found for '" + queryOptions->UserSearchFilter + "'";
}
else if (files->Size == 1)
{
outputText += files->Size.ToString() + " file found:\n\n";
}
else
{
outputText += files->Size.ToString() + " files found:\n\n";
}
//output the name of each file that matches the query
for (unsigned int i = 0; i < files->Size; i++)
{
outputText += files->GetAt(i)->Name + "\n";
}
OutputTextBlock->Text = outputText;
});
}
void Scenario1::OnLocalAppDataChanged(Windows::Storage::Search::IStorageQueryResultBase^ sender, Platform::Object^ args)
{
Platform::String^ hello = L"hello world, I'm called back";
}
You have to call the method GetFilesAsync() at least once, otherwise the event will never fire.
Add
queryResult->GetFilesAsync();
before
queryResult->ContentsChanged += ref new TypedEventHandler<IStorageQueryResultBase^,...
I know you don't really need the files at that point, but that's the offical way the ContentsChanged event should be used. Have a look at the first paragraph of the documentation.

EntityDataReader to ToList()

my code :
public List<Book> GetBook(string Field, object Value)
{
using (EntityConnection conn = new EntityConnection("name=Entities"))
{
conn.Open();
// Create an EntityCommand.
using (EntityCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "Select VALUE b FROM Entities.Book as b where Cast(b." + Field + " as Edm.String) like '%" + Value.ToString() + "%'";
// Execute the command.
using (EntityDataReader rdr =
cmd.ExecuteReader(CommandBehavior.SequentialAccess))
{
conn.Close();
var s = from d in rdr.OfType<Book>().AsEnumerable()
select d;
return (s.ToList());
}
}
}
return (null);
}
why The result is always empty???
What is the correct code?
Why are you closing connection before you started to read from the reader? Reader is like cursor - it doesn't buffer all results to memory when you open it but it loads them incrementally so you could easily terminate connection (and reading functionality as well) before you read any result. You don't have to close the connection explicitly - that is responsibility of using block.
You can also use SQL profiler to validate the it really builds the query you expect.
using (EntityConnection conn = new EntityConnection("name=Entities"))
{
conn.Open();
// Create an EntityCommand.
using (EntityCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "Select VALUE b FROM Entities.Book as b where Cast(b." + Field + " as Edm.String) like '%" + Value.ToString() + "%'";
// Execute the command.
using (EntityDataReader rdr =
cmd.ExecuteReader(CommandBehavior.SequentialAccess))
{
var s = from d in rdr.OfType<Book>().AsEnumerable()
select d;
return (s.ToList());
}
}
}
s.ToList().Count returns 0 because rdr.OfType<Book> is always empty collection. EntitDataReader doesn't materialize entities - it is just wrapper about database related DataReader and it works in the same way. You must read columns and fill them to properties of your entity.
If you don't want to do it you can use objectContext.Translate method but once you start to work with ObjectContext you don't need EntityCommand and EntityDataReader at all.

Resources