I'm trying to make use of the #onclick when developing a jenkins plugin but nothing happens when the checkbox which has this attribute is clicked (same with #onchange).
I have a checkbox for each job implemented as a ListViewColumn with the corresponding column.jelly file
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<td>
<f:checkbox name="selected" onclick="${it.itClicked()}" onchange="${it.itClicked()}" />
</td>
</j:jelly>
and the method itClicked() resides in the corresponding java class of this jelly file:
class CheckboxTemplate extends ListViewColumn {
...
public void itClicked() {
System.out.println("it clicked!");
}
...
#Extension
public static class DescriptorImpl extends ListViewColumnDescriptor {
...
}
But this apparently is not working...
I've made another plugin before which called a method in the java class from the predefined object "it" from the jelly file and it worked fine, so having the method defined in the working place is not the problem (I assume).
Anyone who has any idea of why itClicked() is not executed when the checkbox is checked/changed?
If there is information that I missted posting, tell me, and I'll come back with it asap!
I managed to solve this by adding
<st:bind var="myItem" value="${it}"/>
in my jelly file and changing #clicked to
onclick="myItem.mark('${job.fullName}')"
where mark() was defined in the backend with the particular annotation
#JavaScriptMethod
public void mark(String job) {
// do what you need to do
}
job if of course a predefined variable in the column.jelly file which is not required for this to work, I only passed it to map the checkbox with the corresponding job name.
Hope this is useful for others who struggle with the documentation (and with the nonexisting complete examples) on these topics.
Related
I'm using NUnit + Webdriver + C#. Setup class has next stucture:
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
public partial class SetupBase<TWebDriver> where TWebDriver : IWebDriver, new()
{
public IWebDriver _driver;
[OneTimeSetUp]
public void OneTimeSetUp()
{
Init();
}
}
How can I set name of tests to include methode name, arguments and name of browser?
I tried with capabilities but it didn't help
ChromeOptions options = new ChromeOptions();
options.AddAdditionalCapability("Name", String.Format ("{0}_Chrome", TestContext.CurrentContext.Test.Name), true);
Also tried to use next code but was not able to find way how to pass driver type to NameAttribute
public class NameAttribute : NUnitAttribute, IApplyToTest
{
public NameAttribute(string name)
{
Name = String.Format("{0} {1}", name);
}
public string Name { get; set; }
public void ApplyToTest(Test test)
{
test.Properties.Add("Name", Name);
}
}
Can you help me please. Maybe need to update base class structure somehow?
This is how I use in tests
public class _001_General<TWebDriver> : SetupBase<TWebDriver> where TWebDriver : IWebDriver, new()
{
[OneTimeSetUp]
public void OneTimeSetupTest ()
{
//somework
}
[Test]
public void Test ()
{
//somework
}
}
Also SetupBase class contains functions that are used in tests
In NUnit, test cases, test methods, test fixtures and generic test fixture classes are all "tests" even though we sometimes talk loosely about "tests" as meaning test cases.
In your example, the following names are created:
_001_General<TWebDriver> (or maybe _001_General<>)
_001_General<InternetExplorerDriver>
Test
_001_General<ChromeDriver>
Test
Tests also have "fullnames", similar to that for a type or method. For example
_001_General<ChromeDriver>.Test
(Note: the fullname would also include a namespace, which I haven't shown.)
If you are using a runner that displays fullnames, like the NUnit 3 Console Runner, then there is no problem. So, I assume you are not. :-)
Some runners, like the NUnit 3 Visual Studio Test Adapter use simple test case names. So you would end up with a bunch of tests displayed with the name "Test."
Is that your problem? If so, this is not much of an answer. :-) However, I'll leave it as partial and add to it after hearing what runner you want to use and what you would like to see displayed in it.
UPDATE:
Based on your comment, what you really want to see is the test FullName - just as it is displayed by the NUnit 3 Console runner that TC runs for you. You'd like to see them in the VS IDE using the NUnit 3 VS Adapter.
Unfortunately, you can't right now. :-) More on that below. Meanwhile, here are some workarounds:
Use the console runner on your desktop. It's not as visual but works quite well. It's how I frequently work. Steps:
Install the console runner. I recommend using Chocolatey to install it globally, allowign you to use it with all your projects.
Set up your project to run the console runner with any options you like.
Make sure you use an external console window so you get the color display options that make the console runner easier to use.
Size your windows so you can see everything (if you have enough screen space) or just let the console run pop up on top of VS.
Try to trick VS by setting the test name in a way that includes the driver parameters. That's what you are already doing and it sounds as if you have already gotten almost all you can out of this option, i.e. class name without class parameters. You could try to take it a step further by creating separate classes for each driver. This would multiply the number of classes you have, obviously, but doesn't have to duplicate the code. You could use inheritance from the generic classes to create a new class with only a header in each place where it's needed. Like...
public class TestXYZDriver : TestDriver ...
This might be a lot of work, so it really depends on how important it is to you to get visual results that include fixture parameters right now.
For the future, you could request that the NUnit 3 Adapter project give an option of listing tests by their full names. I haven't worked on that project for a few years, so I'm not sure if it's actually possible. It may not be entirely in the control of the adapter, since VS controls what is displayed.
I use SpecFlow with Coded UI to create some automated functional tests for a WPF application. Test case execution is performed using MsTest and Visual Studio Premium 2012.
I have a lot of test cases. If I execute them one by one everything is OK. If I put them all in an ordered test I receive the following error:
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotAvailableException: The following element is no longer available: Name [], ControlType [Custom], AutomationId [reags:LoadView_1], RuntimeId [7,1620,64780193] ---> System.Windows.Automation.ElementNotAvailableException: The following element is no longer available: Name [], ControlType [Window], AutomationId [UnitializedCB3702D1-14B6-4001-8BC7-CD4C22C18BE1], RuntimeId [42,1770052]
at Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaUtility.MapAndThrowException(SystemException e, IUITechnologyElement element)
at Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaElement.get_AutomationId()
at Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaElement.HasValidAutomationId()
at Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaElement.get_FriendlyName()
at Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMapUtil.FillPropertyFromUIElement(UIObject obj, IUITechnologyElement element)
at Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMapUtil.FillPropertyOfTopLevelElementFromUIElement(UIObject obj, IUITechnologyElement element)
at Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMapUtil.FillTopLevelElementFromUIElement(IUITechnologyElement element, TopLevelElement obj, Boolean stripBrowserWindowTitleSuffix)
at Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMapUtil.GetCompleteQueryId(UITechnologyElement pluginNode)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetQueryIdForCaching()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<>c__DisplayClass6.<CacheQueryId>b__5()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.CacheQueryId(String queryId)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl..ctor(IUITechnologyElement element, UITestControl searchContainer, String queryIdForRefetch)
at Microsoft.VisualStudio.TestTools.UITesting.TechnologyElementPropertyProvider.GetPropertyValue(UITestControl uiControl, String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestPropertyProvider.TryGetPropertyFromTechnologyElement(UITestControl uiControl, String propertyName, Object& value)
at Microsoft.VisualStudio.TestTools.UITesting.PropertyProviderBase.GetPropertyValue(UITestControl uiControl, String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestPropertyProvider.GetPropertyValueWrapper(UITestControl uiControl, String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyValuePrivate(String propertyName)
The first couple of errors were fixed using this hint, but I have some auto-generated steps and in order to re-search the controls I have to move the code and... a lot of unnecessary and annoying work.
Could you suggest some another solution to fix this? Is there some trick with the ordered tests? Or some nice clean-up methods for problems like this?
Thanks!
Here's what I did with a recent project.
First I created some CodedUI test methods as if SpecFlow didn't exist so I could keep those layers separate. Then I created step definition classes in C# that delegate to the coded UI test methods I created.
In a before scenario hook I created my UIMap instances (the classes generated by the CodedUI test generator) so each scenario had a fresh instance of my UIMap classes. You need this because object references in these classes are cached. Each new screen in your app is a whole new object tree that CodedUI must traverse.
Many times my step definitions just dive right into the CodedUI API to create custom searches, and I used the auto generated methods in my UIMap classes as a point of reference.
A little elaboration on how I set up my test project.
About My Test Project
I created a new "Test" project in Visual Studio 2010, which references the following libraries:
Microsoft (probably comes with default Test project template)
Microsoft.VisualStudio.QualityTools.CodedUITestFramework
Microsoft.VisualStudio.QualityTools.UnitTestFramework
Microsoft.VisualStudio.TestTools.UITest.Common
Microsoft.VisualStudio.TestTools.UITest.Extension
Microsoft.VisualStudio.TestTools.UITesting
UIAutomationTypes
NuGet Packages
AutoMapper
AutoMapper.Net4
SpecFlow.Assist.Dynamic
TechTalk.SpecFlow
Test Project Structure
This was my first stab at CodedUI Tests. I came from a Ruby on Rails background, and did a fair amount of reading online about implementing CodedUI Tests and SpecFlow tests. It's not a perfect setup, but it seems to be pretty maintainable for us.
Tests (Test project)
Features/
Bar.feature
Foo.feature
Regression/
Screen1/
TestsA.feature
TestsB.feature
StepDefinitions/
CommonHooks.cs
DataAssertionSteps.cs
DataSteps.cs
FormSteps.cs
GeneralSteps.cs
PresentationAssertionSteps.cs
Screen1Steps.cs
Screen2Steps.cs
UI/
FormMaps/
Screen1FormMap.cs
Screen2FormMap.cs
UIMapLoader/
User.cs
UIMap.uitest (created by CodedUI test framework)
Models (C# Class Library Project)
Entities/
Blog.cs
Comment.cs
Post.cs
Repositories/
BlogRepository.cs
CommentRepository.cs
PostRepository.cs
ViewModels/
Screen1ViewModel.cs
Screen2ViewModel.cs
Tests/Features
This folder contains all the SpecFlow feature files implementing the basic business rules, or acceptance tests. Simple screens got their own feature file, whereas screens with more complex business logic were broken into multiple feature files. I tried to keep these features friendly to read for both Business and Developers.
Tests/Regression
Because our Web Application was not architected in a manor allowing unit testing, all of our testing must be done through the UI. The Tests/Regressions folder contains all the SpecFlow feature files for our full regression of the application. This includes the really granular tests, like typing too many characters into form fields, etc. These features weren't really meant as business documenation. They are only meant to prevent us from being woken up at 3 a.m. because of production problems. Why do these problems always happen at 3 a.m.? ...
Tests/StepDefinitions
The Test/StepDefinitions folder contains all the SpecFlow Step Definition files. I broke these files down first into common steps, and then steps pertaining to a particular screen in my application.
CommonHooks.cs -- Created by SpecFlow
[Binding]
public class CommonHooks
{
[BeforeTestRun]
public static void BeforeTestRun()
{
...
}
[BeforeScenario]
public void BeforeScenario()
{
User.General.OpenLauncher();
}
[AfterScenario]
public void AfterScenario()
{
User.General.CloseBrowser();
User.General = null;
}
}
The BeforeScenario and AfterScenario methods are where I create and/or destroy instances of the CodedUI UIMap classes (More on that further down)
DataAssertionSteps.cs -- Step definitions asserting that data shows up, or doesn't show up in the database. These are all Then ... step definitions.
Scenario: Foo
Then a Foo should exist
In DataAssertionSteps.cs:
[Then(#"a Foo should exist")]
public void ThenAFooShouldExist()
{
// query the database for a record
// assert the record exists
}
DataSteps.cs -- Steps to seed the database with data, or remove data. These are all Given ... step definitions used to set up a scenario.
FormSteps.cs -- Step definitions for interacting with forms. These all tend to be When I ... steps
GeneralSteps.cs -- Realy generic step definitions. Things like When I click the "Foo" link go here.
PresentationAssertionSteps.cs -- Generic steps asserting that the UI is behaving properly. Things like Then I should see the text "Foo" go here.
Screen1Steps.cs -- When I needed steps for a particular screen, I created a step definition file for that screen. For example, if I needed steps for the "Blog Post" screen, then I created a file call BlogPostSteps.cs, which contained all those step definitions.
Tests/UI
The Tests/UI folder contains a bunch of custom written C# classes that we used to map label text found in our *.feature files to the names of form controls. You might not need this layer, but we did. This makes it easier to refactor your test project if form control names change, and especially for Web Projects because the HTML form field names change based on the <asp /> containers in our ascx files.
Example class:
namespace Tests.UI.FormMaps.Screen1FormMap
{
public static IDictionary<string, string> Fields = new Dictionary<string, string>()
{
{ "First Name", "UserControlA_PanelB_txtFirstName" },
{ ... },
...
};
}
Example Step:
When I enter "Joe" in the "First Name" textbox in the "Screen 1" form
Example Step Definition:
[When(#"I enter ""(.*)"" in the ""(.*)"" textbox in the ""(.*)"" form")]
public void WhenIEnterInTheTextboxInTheForm(string text, string labelText, string formName)
{
if (formName == "Screen 1")
{
// form control name: Screen1FormMap.Fields[labelText]
}
...
}
The step definition then used the Tests.UI.FormMaps.Screen1FormMap.Fields property to retrieve the form control name based on the label text in the *.feature files.
Tests.UI.FormMaps.Screen1FormMap.Fields["First Name"]
Tests/UI/UIMapLoader/User.cs
The other thing inside this folder is the UI/UIMapLoader/User.cs file. This class is a custom written class providing easy access to all the UIMap classes generated by the CodedUI Test framework.
namespace Tests.UI.UIMapLoader
{
public static class User
{
private static UIMap _general;
public static UIMap General
{
get { return _general ?? (_general = new UIMap()); }
set { _general = value; }
}
}
}
That way the Step Definition classes can easily access the UI maps via:
User.General.SomeCodedUITestRecordedMethod(...);
You saw a reference to this class in the BeforeScenario and AfterScenario methods in the CommonHooks.cs file referenced above.
Models Project
This is just a class lib to encompass the entities and repositories allowing the test project to access the database. Nothing special here except the ViewModels directory. Some of the screens have complex relationships with data in the database, so I created a ViewModel class to allow my SpecFlow step definitions to easily seed the database with data for these screens.
I'm trying to create a JIT pivotviewer and I have been kinda struggling a bit. Could someone clear my confusion on how the cxml is dynamically created? Also how should the information be set up for me to request it? I currently have it sitting inside of my database, do I need to create an xml doc for it to load from or can it pull it straight from the db?
For building a JIT PivotViewer collection you start by downloading the JIT example built by Microsoft.
Look around in the solution, when getting started the most important bit is the CollectionFactories project. To create a collection using data from your database you need to create your custom CollectionFactory.
Your custom collectionfactory extends the CollectionFactoryBase class:
class MyCustomCollection : CollectionFactoryBase
the class needs to implement the MakeCollection method, all this method has to do is create an instance of Collection class and add CollectionItems to it.
public override PivotServerTools.Collection MakeCollection(CollectionRequestContext context) {
return MakeCollection();
}
private static PivotServerTools.Collection MakeCollection() {
PivotServerTools.Collection collection = new PivotServerTools.Collection();
collection.Name = "MyImages";
ItemImage[] fileList = ImageListFromDatabase();
foreach (ItemImage image in fileList) {
collection.AddItem(image.Name, image.ImageUrl.ToString(), image.Description, image, null);
}
return collection;
}
Now to use this collection and see it in action, you need to provide the name of the collection for the PivotViewer Silverlight application (PivotServer) in the solution:
default.aspx
<param name="initParams" value="cxml=MyImages.cxml" />
I have few public properties in App.xaml.cs which is in project A and I want to refer them in my project B. However my project A has a reference to project B, so I cannot add again the reference of project A in project B otherwise it will result in cyclic error. So how can I refer those properties in my class library? I don't want to use reflection :).
As a workaround I have stored those properties in one class in project B (so it can be referred in project A as well as project B) and made those properties to be static and all works fine. However I am still curious to know what if I had stored them in App.xaml.cs? Any options available?
Thanks in advance :)
The App class should expose things that are only relevant to the application project. As soon as you realised that you wanted these things accessable in B.dll they became relevant to more than just the application project and therefore no longer belong in the application project.
Adding a class to B.dll that carries these things as static properties could be a reasonable approach. Another common pattern is to have a single Current static property.
public MyClass
{
private static MyClass _current = new MyClass();
public static MyClass Current { get { return _current; } }
public string SomeInstanceValue { get; set; }
}
Both A and B would access things using the pattern var x = MyClass.Current.SomeInstanceValue. The advantage of this approach is that it allows the Current property getter to determine if a "current" instance is available or not.
You might also want to review the documentation on ApplicationLifeTimeObjects.
When A and B both need something, maybe you should put them in a C project (C as in Common) and then refer to C from both A and B.
I want to open one form from another.
I'm having no troubles doing this with blank project. Start new, make 2 forms, put button on first, use this code
Form2 ^ form = gcnew Form2;
form->ShowDialog();
Also adding the include file at the top...
I'm getting this error
error c3767 candidate function(s) not accessible
I've gone through my project and compared it to the really basic one I tried as an example...I've been searching google for hours and trying all sorts of different things, but none of the other peoples problems are related to opening another form...
If anyone could shed any light on this for me, it would be awesome
Thanks
Simon
It looks like the form's constructor is not public. This example form generates that exact same error message:
public ref class Form2 : public System::Windows::Forms::Form
{
//public: // <=== Remove this comment to fix C3767
Form2(void)
{
InitializeComponent();
}
// etc...
};