Formatting output so that Intellij Idea shows diffs for two texts - intellij-idea

I would like to be able to print in the logs a message for which intellij idea would present a nice way of comparing two objects (strings). This happens automatically for the error message logged by a failed junit assert:
assertEquals("some\nString", "another\nString");
=>
org.junit.ComparisonFailure: <Click to see difference>
at org.junit.Assert.assertEquals(Assert.java:123)
at org.junit.Assert.assertEquals(Assert.java:145)
at com.something.DummyTest.testDummy(DummyTest.java:89)
The <Click to see difference> entry is actually displayed as a link in the output window of the Intellij Idea. When you click on the link, a compare window opens which shows the two values (just like you would compare two files).
Simply throwing an exception is not acceptable because I would like to log multiple objects to compare. I already tried logging a text, but I wasn't able to convince idea to compare the two texts.

IntelliJ IDEA is using the hardcoded regular expression. If the text matches the pattern, it will suggest to click to view the difference.
The pattern is:
expected:<bla-blah> but was:<blah-blah-blah>
Output should match the format of assertEquals or assertThat.
The exact patterns are somewhat scattered around the code in IDEA, but some are e.g. here.

I had the same Problem and found the solution in https://github.com/joel-costigliola/assertj-core/issues/1364#issuecomment-440800958
You should throw an org.junit.ComparisonFailure. Then IntelliJ will display the <Click to see difference>

Related

Problem with line breaks in PDF document generated by BIRT

I have some cell texts in a BIRT report which do not flow as nicely as I hoped.
For example,
The text is Long value resultwithaverylongname whichcannotbreak and I had hoped that it would be displayed like this:
Long value
resultwithaverylongname
whichcannotbreak
The render options are as follows:
renderOptions.setOutputFormat(IPDFRenderOption.OUTPUT_FORMAT_PDF);
renderOptions.setOption(IPDFRenderOption.PAGE_OVERFLOW, IPDFRenderOption.OUTPUT_TO_MULTIPLE_PAGES);
renderOptions.setOption(IPDFRenderOption.PDF_TEXT_WRAPPING, true);
renderOptions.setOption(IPDFRenderOption.PDF_WORDBREAK, true);
It seems to me that my desired output is physically possible but I don't know why BIRT does not break on a whitespace and breaks in the middle of the word.
I am using BIRT 4.16 (from Sourceforge). The texts contain normal whitespace (no non-breakable spaces) and are displayed via a data object.
3.Sep.21
I now have an example project which I am trying to commit to Github. In the meantime here is a screenshot showing breaks which look good and others which are not...
The git repo is here: https://github.com/pramsden/test.wordbreak
If the text "resultwithaverylongname" physically fits, then you are right:
BIRT should not break it in the middle of the word.
Your renderOptions seem right (depending of what BIRT version you are using).
At first glance this looks like a bug.
But: In German language, we often have quite long words, and I've created a lot of (complex) PDF reports with BIRT, but I never saw this issue.
So I guess it is a tiny silly detail which causes this.
Just to double-check:
Are the spaces between "Long", "value", "result..." normal spaces (0x20)? or non-breaking spaces?
Which BIRT release are you using?
Are you using a data item or a dynamic text item and if so, is it HTML or plain text?
Can you create a reproducible simple test case and post the rptdesign file somewhere?
well i don use BIRT , but try to use (\n),
in my case I use PDFFlow library to generate pdf docs, and to make a line-break i just use \n
this is a simple example code to create a pdf file and use line break
var DocumentBuilder.New()
.AddSection()
.AddParagraphToSection("Hello world! \n go to the next line")
.ToDocument()
.Build("Result.PDF");
try it and tell me if it works

Scripts connected to an Image in EggPlant

I have LoginButton.png that is being used across the whole suite in different scripts. I want to edit the name or move it to a new folder, without breaking all the scripts. So is there a way to list all the scripts that are using this image or to refactor the name/path across the whole suite?
Find option (Edit>Find) it's the closest to what I want, but it only looks at the open script, not the whole suite, and replaces anything with similar naming convention eg: Find "LoginButton" and replace with "NewButton", if you have "LoginButton", "LoginButton1", "LoginButton2" after the replace you will end up with "NewButton", "NewButton1", "NewButton2", and i just want to change "LoginButton" not "LoginButton1" and "LoginButton2".
Thanks
Unfortunately, you've found the closest solution. One of Eggplant's major drawbacks is that you're locked into a single, (rather feature-less) IDE. If you're having issues matching other words with your search query, you can try including spaces, i.e. " LoginButton ", on the outside of the word.

Special characters in drop-down list with Robot Framework (Selenium)

just wondering if any of you know how to handle special characters with a website that contains a drop-down list. I scripted the following in Robot Framework (Selenium) to verify the contents of a drop-down list:
Verify all required fields and labels are present
Verify a and lists of b for 'ööö'
Verify a and lists of b for '${xyz}'
(...)
Dropdown "{abc}" should contain options "${json_blabla["ABC"]["${xyz}"]}"
However, when trying to do that, I get the following error message when running the script:
Resolving variable '${json_blabla["ABC"]["ööö"]}' failed: KeyError: '\xc3\xb6\xc3\xb6\xc3\xb6'
Any idea how to get around this? I'm sure I saved everything in UTF-8 encoding, and I think the JSON file should be fine too, so I'm suspecting it's somewhere in the script I just showed?
Found it:
It seems that it needs to be told explicitly that the string must be in Unicode, so one option to have it corrected is:
Dropdown "{abc}" should contain options "${json_blabla["ABC"][u"${xyz}"]}"
And voilà!
Thanks for voting & until next time!

verifyText using *text* instead of verifyTextPresent (deprecated)

I'm kind of new to selenium IDE and automated test and I don't know much about programming languages. I have a question concerning verifyText command as verifyTextPresent is deprecated. If I put the target word/text in * * will it work as if I was using verifyTextPresent? Could waitForText work?
I am trying to verify that the search function of a website is working as expected. I search the word "client" and I want to verify that the word is present in the results.
clickAndWait css=div.cf-tooltip-text
type id=edit-global-search client
clickAndWait id=edit-submit-global-search
verifyText id=content-column *client*
This works, but in the Log I can not understand what it really does. Also if I try the word on its own "client" I get an error which I understand because it compares it to the text of the whole column. I also tried to put an irrelevant word between asterisks such as youwillnotfindthetext (just to make sure that everything between asterisks will pass the test) and there I had an error too.
So it seems to be working somehow but I want to ask some of you expert guys.
Thanks
If you put a * in starting and ending means it will look for the inner text containing in the specific element. If a text is present as you given in the script it will return a pass. If the text u specified in the script is not present, it will throw an error. That's what happens when you put youwillnotfindthetext in between the *.
Check this link Selenium: test if element contains some text

How do I write a robust structural search template to report Mockito times(1)/Times(1) passed to verify in IntelliJ IDEA?

In my project Mockito.times(1) is often used when verifying mocks:
verify(mock, times(1)).call();
This is redundant since Mockito uses implicit times(1) for verify(Object), thus the following code does exactly what the code above does:
verify(mock).call();
So I'm going to write an a structural search drive inspection to report such cases (let's say, named something like Mockito.times(1) is redundant). As I'm not an expert in IntelliJ IDEA structural search, my first attempt was:
Mockito.times(1)
Obviously, this is not a good seach template because it ignores the call-site. Let's say, I find it useful for the following code and I would not like the inspection to trigger:
VerificationMode times = Mockito.times(1);
// ^ unwanted "Mockito.times(1) is redundant"
So now I would like to define the context where I would like the inspection to trigger. Now the inspection search template becomes:
Mockito.verify($mock$, Mockito.times(1))
Great! Now code like verify(mock, times(1)).call() is reported fine (if times was statically imported from org.mockito.Mockito). But there is also one thing. Mockito.times actually comes from its VerificationModeFactory class where such verification modes are grouped, so the following line is ignored by the inspection:
verify(mockSupplier, VerificationModeFactory.times(1)).get();
My another attempt to fix this one was something like:
Mockito.verify($mock$, $times$(1))
where:
$mock$ is still a default template variable;
$times$ is a variable with Text/regexp set to times, Whole words only and Value is read are set to true, and Expression type (regexp) is set to (Times|VerificationMode) -- at least this is the way I believed it should work.
Can't make it work. Why is Times also included to the regexp? This is the real implementation of *.times(int), so, ideally, the following line should be reported too:
verify(mockSupplier, new Times(1)).get();
Of course, I could create all three inspection templates, but is it possible to create such a template using single search template and what am I missing when configuring the $times$ variable?
(I'm using IntelliJ IDEA Community Edition 2016.1.1)
Try the following search query:
Mockito.verify($mock$, $Qualifier$.times(1))
With $Qualifier$ text/regexp VerificationModeFactory|Mockito and occurrences count 0,1 (to find it when statically imported also).
To also match new Times(1) you can use the following query:
Mockito.verify($mock$, $times$)
With $times$ text/regexp .*times\s*\(\s*1\s*\) and uncheck the Case sensitive checkbox.