none
Applying filters from Powershell script using HCK APIs RRS feed

  • Question

  • I had a question regarding Applying Filters from powershell script:

    Q1. How can we confirm that the following code has actually applied filters and exited successfully. Can we find out from the logs somehow?

    # apply filter to the project. Reload the project in HCK Studio after running the script.
    $result = $filterEngine.Filter($project)

    The reason I ask is, I printed $project.GetAppliedFilters().Count after doing the above, and it prints 0 as the count. 

    Q2. Is it compulsory to reload the project in Studio after applying filters from a script? I want to just have a script which creates project, runs tests, applies filters and create a package.

     

     

    Tuesday, December 18, 2012 12:39 AM

Answers

  • When you write (or print) $filterResult, it calls the ToString() method on the class - which returns the actual type (default implementation in the Object class in .Net)

    To actually display the filter results, you have to enumerate the filter results like Nilesh points out above.

    As mentioned in this thread, project.GetAppliedFilters returns filters applied to immediate task results for a test result. It doesn’t get filters applied to all child task results (in the chain) for a test result. To get all the applied filters, you would have to manually recourse through the child task results.

    Monday, December 31, 2012 11:31 PM

All replies

  • Hi Disha,

    When you apply filters "manually" or using  "$result = $filterEngine.Filter($project)", HCK does not always apply filters but it applies filters when particular test has failed and filter set contains filter for this particular failed test.

    So when all tests have passed successfully in your project, and you apply filters, no filter will get applied as all tests have already passed successfully. But if any test gets failed, and you apply filters, filter will get applied if filter set contains filter for this test. Accordingly the value of "$project.GetAppliedFilters().Count" will change. "0" for no filter applied, "1 or more" for 1 or more filters applied.

    If you still have any doubt or issue, let me know here :)

    Thanks,

    Nilesh.

    Tuesday, December 18, 2012 6:33 AM
  • Thanks for your response.
    Wednesday, December 19, 2012 10:48 PM
  • I can see Filter applied in HCK Studio from my script using $filterResult = $projectFilterEngine.Filter($newProject). But when I try printing $newProject.GetAppliedFilters().Count - it still says 0. Can you tell me what could be wrong?
    Thursday, December 20, 2012 1:37 AM
  • What about $filterResult ? have you tried to print it? It will also give you an idea of what filters have been applied and whether filters were successful or not.

    Thursday, December 20, 2012 6:06 AM
  • $filterResult just prints the following

    Filter result: [Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection.WttTestResult, System.Collections.ObjectModel.R
    eadOnlyCollection`1[Microsoft.Windows.Kits.Hardware.ObjectModel.IFilterResult]]

    One thing that I have noticed is the filter is applied after a test fails in HCK Studio, irrespective of doing $filterResult = $projectFilterEngine.Filter($newProject) from the script.

    I don't know why $filterResult = $projectFilterEngine.Filter($newProject) is not working. I remember it to be working earlier since I could see $newProject.GetAppliedFilters() to be a non-zero value.

    Thursday, December 27, 2012 12:24 AM
  • Hi Disha,

    "[Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection.WttTestResult,System.Collections.ObjectModel.ReadOnlyCollection`1[Microsoft.Windows.Kits.Hardware.ObjectModel.IFilterResult]]" indicates that $filterResult is a readonly collection of objects of [Microsoft.Windows.Kits.Hardware.ObjectModel.IFilterResult] type.

    Loop through this collection and try printing.

    You can use, "HCK API References" in HCK documentation, for more information about FilterResult object.

    Let me know, what is the outcome after this.

    Thanks,

    Nilesh

    Monday, December 31, 2012 6:59 AM
  • When you write (or print) $filterResult, it calls the ToString() method on the class - which returns the actual type (default implementation in the Object class in .Net)

    To actually display the filter results, you have to enumerate the filter results like Nilesh points out above.

    As mentioned in this thread, project.GetAppliedFilters returns filters applied to immediate task results for a test result. It doesn’t get filters applied to all child task results (in the chain) for a test result. To get all the applied filters, you would have to manually recourse through the child task results.

    Monday, December 31, 2012 11:31 PM
  • Thanks Prakash and Nilesh for your help. I was able to see the filters applied to child task results.
    Thursday, January 3, 2013 11:48 PM