Intellij - Showing and property values and names - properties

Using IntelliJ to edit a Spring Beans file, I am using a properties file to define some of the values of the beans.
In IntelliJ, when you open the bean file all of the properties are displaying their values (in grey). When you edit this, it then displays the property name.
To get the value back, you have to close and then re-open the file
Is there another way to switch between the property name and value in an XML bean file other than closing and re-opening the file?

IDEA is trying to be helpful here, showing you the actual values referred to by the property placeholders ("${foo.bar}").
You can see the raw placeholder expression by:
Double-clicking on the value
Putting the caret on the value, and pressing Ctrl-Plus

Related

Robot Framework variable attribute in seperate file not storing attribute to be used elsewhere

Variable attribute not getting passed into other file.
I have my variables for element locators stored in one file and I have assertions done in another file which has worked fine until now and separates things out nicely. I am doing an assertion to check that an element exists and its attribute(value) is not blank. If I write it on one page as follows it works perfectly. This use the selenium library keywords should not be equal and Get Element Attribute just to note.
${EXAMPLE} get element attribute class=test test-data
should not be equal ${EXAMPLE} ${EMPTY}
But If I separate them out into different files. So a locators.robot file:
#Locater File
${EXAMPLE} get element attribute class=test[test-data]
And an Assertions.robot:
#Assertion File
should not be equal ${EXAMPLE} ${EMPTY}
It stops working. If I use a selenium library assertion like page should contain element then it works, so I know I am pulling in the other Resource correctly. I have a feeling I may need to store the attribute in another variable somehow and actually assert against that. Any ideas would be great. Thanks in advance.
Suppose you have html code like this as you given in other question -
<div id="top-list">
<div data-version="12345" data-list="1" data-point="10">
Way 1 - Less recommended -
This is how my assertion.robot looks like -
*Settings
Library SeleniumLibrary
Resource Locator.robot
*Test Cases
Test attributes Locator
Open Browser file:///C:Desktop/testxpath.html chrome
${attribute_value}= Get Element attribute ${Datalist_locator_with_all_attribt} data-list
should not be equal ${attribute_value} ${EMPTY}
The locators are in locator.robot file. I'm not calling Get Element Attribute keyword in the locators because doing so there will be no link of directly executing it and referencing back the return value of it in testcase... So just keeping the locators in the locator file nothing else. This locators are accessible when I did Resource Locator.robot in my assertion.robot file. As you can see the Get Element Attribute element take first argument locator of element and second argument is nothing but the attribute name of which value you need. And this keyword returns value of attribute that supplied as second argument. -
*Variables
${Datalist_locator_with_all_attribt} xpath://div[#data-version='12345' and #data-list='1' and #data-point='10']
${locator_with_single_attribute} xpath://div[#data-version='12345']
Output
Way 2 - More Recommended -
Wrap the Get Element Attribute and Should Not Be Equal keywords in one single keyword. and dump it in another keyword file or create *keywords section in locator.robot file itself. Doing this your assertion.robot file will look like this -
*Test Cases
Test attributes Locator
Open Browser file:///C:/Desktop/testxpath.html chrome
Attribute values should not be empty
and locator.robot will look like this. You can make it more generic though -
*** Variables
${Datalist_locator_with_all_attribt} xpath://div[#data-version='12345' and #data-list='1' and #data-point='10']
${locator_with_single_attribute} xpath://div[#data-version='12345']
*** Keywords
Attribute values should not be empty
${attribute_value}= Get Element attribute ${Datalist_locator_with_all_attribt} data-list
should not be equal ${attribute_value} ${EMPTY}
Output

Intellij shortcut to create code snippet for testing

Is there any shortcut/setting/plugin available in intellij where I can create test data structure with some default values ?
e.g.
Map<String,String> stringMap = new HashMap();
stringMap.put("1","A")
stringMap.put("2","B")
stringMap.put("3","C")
I dont want to type all of the above as I want to test very quick with any values.
You can use the 'Live Templates' functionality, for instance. A guide on how to create such a template can be found here.
Use live templates to insert common constructs into your code, such as
loops, conditions, various declarations, or print statements.
To expand a code snippet, type the corresponding template abbreviation
and press Tab
In the screenshot below, I created a custom template called smap in the 'other' template group, added your code to it and selected the language (Java) that this template can be applied to.
Once in the editor, I can type smap and a pop-up will appear suggesting me to use the existing template to replace the abbreviation with code. Hitting Tab or Enter will perform the replacement.

Open single instance of form editor

I have Form Editor and on every double click event on editor input I need to avoid duplicate instance of the form editor to open. I'm setting the editor name by setPartName
I need to check that name and to be open only one instance
You can specify a matchingStrategy class in your org.eclipse.ui.editors definition of the editor which lets you control which editor is used to open files,
For example this is the definition of the PDE plugin.xml/MANIFEST.MF/build.properties editor:
<extension
point="org.eclipse.ui.editors">
<editor
default="true"
name="%editors.pluginManifest.name"
icon="$nl$/icons/obj16/plugin_mf_obj.png"
class="org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor"
contributorClass="org.eclipse.pde.internal.ui.editor.plugin.ManifestEditorContributor"
matchingStrategy="org.eclipse.pde.internal.ui.editor.plugin.ManifestEditorMatchingStrategy"
id="org.eclipse.pde.ui.manifestEditor">
<contentTypeBinding contentTypeId="org.eclipse.pde.pluginManifest"/>
<contentTypeBinding contentTypeId="org.eclipse.pde.fragmentManifest"/>
<contentTypeBinding contentTypeId="org.eclipse.pde.bundleManifest"/>
</editor>
The matchingStrategyclass must implementIEditorMatchingStrategy` which has one method:
public boolean matches(IEditorReference editorRef, IEditorInput input)
Returns whether the editor represented by the given editor reference
matches the given editor input.
Implementations should inspect the given editor input first, and try
to reject it early before calling IEditorReference.getEditorInput(),
since that method may be expensive.

InteliJ - How to create shortcuts for code samples

I am using InteliJ and really love using it. One of the questions I have is this:
Is there a way to create code short cuts?
For instance, while bug testing, I am forever writing:
<?php die(var_dump($var)); ?>
and figured it would be great to have a shortcut key to automate this. i.e.
"Cmd Option D"
or something similar to dump the pre-defined statement into my code...
Any thoughts on this?
You can use Live Templates:
To define a template go to Settings/Live templates, then select group or create new group of templates and hit the green plus button and select Live Template.
In the abbreviation field type for example vd which will be the trigger for your snippet, define context, which represents the languages this template will be available for and put this in the Template Text field:
<?php die(var_dump($SELECTION$)); ?>
The $SELECTION$ part is a variable which represents current selection.
Now when you are in editor, you can just type vd and hit Tab. That will expand your snippet and put your cursor inside var_dump().
You can event type the variable name you want to dump, select it, hit CTRL+ALT+T, which will show you a Surround with dialog, where you can choose your template. After you select it your variable name will be surrounded with the var_dump snippet.
Another way to invoke a live template is to hit CTRL+J which will show you autocomplete popup with the available templates.

New structure field is not empty

I'm changing my liferay velocity template by adding new field for structure. e.g. 'heading1' and then adding this new field to template:
<h1>Heading is: $heading1.data</h1>
But if the structure field is not yet filled the outcome is:
Heading is: $heading1.data
So I thought I can fix this by:
#if($heading1.data!="")<h1>Heading is: $heading1.data</h1>#end
But the outcome is still:
Heading is: $heading1.data
If I open the web content and just publish it then the outcome is right, it doesn't show anything, but I don't want do find every similar web content and start publish them manually.
So is there a way how to check if the heading is just not filled?
Thanks.
You can use a silent reference to tell Velocity not to display an empty reference:
<h1>Heading is: $!heading1.data</h1>
or you can directly test whether its content does exist:
#if($headings1.data) <h1>Heading is: $heading1.data</h1> #end
Up to Velocity 1.7, this test will be false if the reference is null or uninitialized, but will still be true if the reference contains an empty string. Empty strings will also evaluate to false in next versions.