I am using the GeneralTeamService Plugin to get and set the Team field value in my groovy script. I have a requirement to create a team through the script. I have found the below method for Creating Team but not sure what is the input for it.
#WithPlugin("com.atlassian.teams")
#PluginModule GeneralTeamService teamService
//get Team custom field object
def cfTeam =
ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Team').first()
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
log.debug "foundTeamId ${foundTeamId}"
issue.setCustomFieldValue(cfTeam, teamService.getTeam(foundTeamId, true).get())
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
// does a new team have to be created?
teamService.createTeam(teamDescription)
Here i dont get what is teamDescription variable
Also, it will be helpful if someone can provide me GeneralTeamService plugin details link.
Thanks in Advance
Related
I'm starting with BDD (cucumber + capybara + selenium chromedriver) and TDD (rspec) with factory_bot and I'm getting an error on cucumber features - step_definitions.
uninitialized constant User (NameError)
With TDD, everything is ok, the factory bot is working fine. The problem is with the cucumber.
factories.rb
FactoryBot.define do
factory :user_role do
name {"Admin"}
query_name {"admin"}
end
factory :user do
id {1}
first_name {"Mary"}
last_name {"Jane"}
email {"mary_jane#gmail.com"}
password {"123"}
user_role_id {1}
created_at {'1/04/2020'}
end
end
support/env.rb
require 'capybara'
require 'capybara/cucumber'
require 'selenium-webdriver'
require 'factory_bot_rails'
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.configure do |config|
config.default_driver = :selenium
end
Capybara.javascript_driver = :chrome
World(FactoryBot::Syntax::Methods)
And the problem is happening here
support/hooks.rb
Before '#admin_login' do
#user = create(:user)
end
step_definitions/admin_login.rb
Given("a registered user with the email {string} with password {string} exists") do |email, password|
#user
end
I don't know why, but I can't access the user using cucumber and factory_bot.
Anybody could help me please?
I think I need to configure something on the cucumber.
What do you think guys?
First of all Luke is correct about this being a setup issue. The error is telling you that the User model cannot be found which probably means Rails is not yet loaded. I can't remember the exact details of how cucumber-rails works but one of the things it does is to make sure that each scenario becomes an extension of a Rails integration test. This ensures that all of the Rails auto-loading has taken place and that these things are available.
Secondly I'd suggest you start simpler and use a step to create your registered user rather than using a tag. Using tags for setup is a Cucumber anti-pattern.
Finally, and more controversially I'd suggest that you don't use factory-bot when cuking. FactoryBot uses a separate configuration to create model objects directly in the datastore. This bypasses any application logic around the creation of these objects, which means the objects created by FactoryBot are going to end up being different from the objects created by your application. In real life object creation involves things like auditing, sending emails, conditional logic etc. etc. To use FactoryBot you either have to duplicate that additional creation logic and behavior or ignore it (both choices are undesirable).
You can create objects for cuking much more effectively (and quicker) by using the following pattern.
Each create method in the Rails controller delegates its work to a service object e.g.
UserController
def create
#user = CreateUserService.new(params).call
end
end
Then have your cukes use a helper module to create things for you. This module will provide tools for your steps to create users, using the above service
module UserStepHelper
def create_user(params)
CreateUserService.new(default_params.merge(params))
end
def default_params
{
...
}
end
end
World UserStepHelper
Given 'there is a registered user' do
#registered_user = create_user
end
and then use that step in the background of your feature e.g.
Background:
Given there is a registered user
And I am an admin
Scenario: Admin can see registered users
When I login and view users
Then I should see a user
Notice the absence of tagging here. Its not desirable or necessary here.
You can see an extension of this approach in a sample application I did for a CukeUp talk in 2013 here https://github.com/diabolo/cuke_up/commits/master. If you follow this commit by commit starting from first commit at the bottom you will get quite a good guide to setting up a rails project with cucumber in just the first 4 or 4 commits. If you follow it through to the end (22 commits) you'll get a basic powerful framework for creating and using model objects when cuking. I realize the project is ancient and that obviously you will have to use modern versions of everything, but the principles still apply, and I use this approach in all my work and having been doing so for at least 10 years.
So if you're using rails, it's probably advised to use cucumber-rails over cucumber. This is probably an issue where your User models have not been auto-loaded in.
Cucumber auto-loads all ruby files underneath features, with env.rb first, it's almost certainly an issue with load order / load location
Is it possible to add a property to messageExchange object in an "Assertion Script", and retrieve the value of this property later in "TestSuite TearDown Script"?
Basically, I want to get how many records REST API retrieved, in "TestSuite TearDown Script" window. I want to do this, without needing to process the responses of all steps in the "TestSuite TearDown Script".
This is how I am adding a property in "Assertion Script"
import groovy.json.JsonSlurper;
def resp = messageExchange.response.responseContent;
def jslurp = new JsonSlurper().parseText(resp);
messageExchange.addProperty("recordCount",Integer.toString(jslurp.size()));
I want to retrieve "recordCount" in "TestSuite TearDown Script", for all the 40+ REST API results that are executed as part of my TestSuite.
Somehow, if I am able to obtain a reference to the messageExchange object of each step from testStepResult, I should be able to achieve what I am trying to do.
Any pointers or your thoughts would be appreciated.
Thank you
I've never had to retrieve a property from an object set in one part of soapUI and used in another. I have a feeling soapUI doesn't share that way.
So, what about setting a custom property at, say the test-suite level? In your assertion script, you can use messageExchange to set a property like this:
def recordCounter = messageExchange.modelItem.testStep.testCase.testSuite.
setPropertyValue('recordCounter', 'your number');
Then, in your tear-down script you could retrieve it with:
def recordCounter = context.expand('${#TestSuite#recordCounter}')
I'm using JIRA 7.1.4 Server and under Behaviours I'm trying to create a Groovy Initialiser Function for setting default values of form fields, so when the user tries to create a new ticket, some fields are already filled in with default values. This is what I have so far:
import com.atlassian.jira.component.ComponentAccessor
def versionManager = ComponentAccessor.getVersionManager()
def versions = versionManager.getVersionsUnreleased(issueContext.projectObject.id, false)
getFieldById("affectedVersion").setFormValue([versions.first().id])
getFieldById("description").setFormValue([versions.first().id])
When the dialog for creating a new JIRA ticket opens, this script successfully sets the "Description" field to the right version id (only for debugging purposes), but the "Affects Version/s" field remains empty for some reason.
I think the id of the "Affects Version/s" field is OK, because I got it from JQL, so e.g. the following query displays correct information:
project = "--------" and affectedVersion is EMPTY
Therefore I assume that I'm trying to set the value of the version field incorrectly, but cannot figure out the mistake. The above Groovy script is based on this example, but the script might be wrong, and I was not able to find more information about getFieldById or setFormValue here either.
Can anyone give a working example of setting JIRA's "Affects Version/s" or "Fix Version/s" fields from Groovy?
If you setting fixversion on issue create step in workflow. You need to put this script into first post function(before issue create).
import com.atlassian.jira.component.ComponentAccessor
def versionManager = ComponentAccessor.getVersionManager()
def versions = versionManager.getVersionsUnreleased(issue.getProjectObject().getId(), false)
issue.setAffectedVersions([versions.first()])
I would like to be able to create project issue automatically. The aim is to create new issue based on received email.
I looked at ProjectWSSInfoDataSet, which is supposed to have reference to issue list (according to "PSI Methods and DataSets for Project Workspaces" at http://msdn.microsoft.com/en-us/library/aa495198(office.12).aspx). Indeed, ProjectWSSInfoDataSet XML schema contains PROJECT_ISSUES_URL field, but if it is just the url then it is not much usefull for me.
Has anyone did something similar? (Or possibly with project risks or deliverables.)
I think have to do it with the SharePoint Webservices. Find the list in the specified web and update it.
I recommend the SharePoint 2010 Client Object Model to do this:
//Use SP2010 Client Object Model to update the list
ClientContext SPContext = new ClientContext(wssUrl);
//Get list by name
string listname = "issues";
var query = SPContext.LoadQuery(SPContext.Web.Lists.Where(l => l.Title == listname));
SPContext.ExecuteQuery();
List myIssueList = query.FirstOrDefault();
//Add an item
ListItemCreationInformation nItem = new ListItemCreationInformation();
nItem.LeafName = "Blubb..";
myIssueList.AddItem(nItem);
SPContext.ExecuteQuery();
If you wan't to get the Workspace Url via the Project Id, you can do this by WSSInterop Webservice of the Project Server:
//Use WssInterop Webservice to get the Workspace URL
WssInteropSoapClient wssinteropSvc = new WssInteropSoapClient();
Guid prjGuid = new Guid("30937680-39FA-4685-A087-90C73376B2BE");
ProjectWSSInfoDataSet wssData = wssinteropSvc.ReadWssData(prjGuid);
string wssUrl = wssData.ProjWssInfo[0].PROJECT_WORKSPACE_URL;
I don't know if the code will compile, but it should work like this.
Regards Florian
I am using the following code to update an entity.
Service.Update(_policy);
where policy is a class generated using CrmSvcUtil.exe
public partial class new_policy : Microsoft.Xrm.Sdk.Entity, System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
I retrieve the policies using LINQ, then update one attribute (an EntityReference) and then attempt the update
When this code runs I get the following error message:
EntityState must be set to null, Created (for Create message) or
Changed (for Update message)
There are other entities generated in the same way that I can update.
I tried
_policy.EntityState = EntityState.Changed
but then I get a message saying
The entity is read-only and the 'EntityState' property cannot be
modified. Use the context to update the entity instead.
Does anyone know what is causing this?
You have to tell your crmContext (use appropriate name) what to do with the changes.
You should add crmContext.UpdateObject(contact); before crmContext.SaveChanges();
See also How to update a CRM 2011 Entity using LINQ in a Plugin?
To avoid the problem you can simply use update-helper-objects instead of using the retrieved record:
var policyUpdater = new Policy { Id = _policy.Id, FieldToUpdate = "newValue" };
service.Update(policyUpdater);
Note: Properties of the update-helper-object that aren't set are simply ignored. The update won't set the corresponding record fields to null
I had the same problem. I switched from using
context.Update(object)
to
context.UpdateObject(object)
and it worked.
This worked for me:
recordToUpdate.EntityState = EntityState.Changed;
(recordToUpdate is an Entity to be updated)
Turns out it was an issue with my linq query that was retrieving the entity in the first place. When I replaced this with a query expression it worked okay.
Time to brush up on my linq!