Add description for Serenity Junit Test - junit

I want to add description test for Serenity Junit test. Example consider below test
#Test
public void testSample() {
step.callStep();
step.callStepTwo();
}
For above test, test name in Serenity html is "Test Sample". With that I want add a description. How to do that ?

The test name should be a summary of the description.
Let's say you want to test a page's login feature. You can name the test as testMyPageLoginFunction.
If you don't want the test name to be so long and wordy, you can add a string that describes what the test is testing in the tag
#Test("Your description here")

Related

How do I exclude a test in an Abstract Test (parent test class) in some children in JUnit?

For example,
I have an AbstractStorageTest which has several tests including storageOverflow.
Children of that test class are ArrayStorageTest, ListStorageTest, MapStorageTest, SortedStorageTest.
Obviously storageOverflow is not applicable for Lists and Maps as they increase automatically when required.
How do I exclude storageOverflow test in ListStorageTest, MapStorageTest, and SortedStorageTest and leave it only in ArrayStorageTest where it is applicable to?
I overrode that test method in ListStorageTest, MapStorageTest, and SortedStorageTest making them pass successfully, but it does not seem to be the right solution.
How about creating another abstract test class like AbstractLimitedStorageTests that extends AbstractStorageTests and serves as a new home for your storageOverflow test method. ArrayStorageTest than becomes a subclass of this new class.

Disabled TextArea Resize stops working when there is Overflow-Y

If a textarea is disabled and has overflow-y it no longer lets you resize.
If you add overflow-y to hidden and keep it disabled it does let you resize.
Any way to have a disabled textarea with scrollable overflow-y and still have it resizable?
Fiddle with just textarea:
https://jsfiddle.net/bs5sakus/ (not resizable)
<textarea disabled> TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST </textarea>
Fiddle with overflow-y hidden: https://jsfiddle.net/30o3tmap/ (resizable)
Possible solution is to use readonly instead of disabled and style it to look disabled. This also allows users to highlight and copy the text in the textarea but not modify it
https://jsfiddle.net/xynLfqag/1/
<textarea readonly> TEST </textarea>
jQuery UI resizable will work but using the SE grabber and scrollbars cause overlapping
https://jqueryui.com/resizable/
Hello I ran into the same situation here.
As I read in some comments above, the issue may be with your own app as the default behaviour does allow the scroll and resize simultaneously
In my case, I found somewhere forgotten in my app the following css set up:
*::-webkit-scrollbar {
display: none;
}
This was avoiding the correct default behavour from textarea
I removed it and the textarea worked as expected
Hope it helps

ViewBag doesn't load

I'm beginning to learn ASP.NET MVC 5, and I'm just trying to make random things to get myself familiar with the system. I tried executing the following code in a standard environment (more or less exactly what you get when you load of a new blank project), but some reason I can't pass a string to my ViewBag properly.
Controller
public ActionResult News(String date)
{
ViewBag.Message = Server.HtmlEncode(date);
return View();
}
View
#{
ViewBag.Title = "News";
}
<h2>News</h2>
<div class="jumbotron">
<h1>#ViewBag.Message</h1>
<p class="lead">This is my new website. I hope that I learn to develop the appropriate skills to create it.</p>
</div>
Some reason it just doesn't show anything for the area where I designated the ViewBag message to go. What's up with it?
Also, as I curiosity question, I noticed some code where they use things like "class = "btn btn-primary btn-lg"" but I couldn't find anywhere that they actually defined the class. How does this work and where is the class declaration?
Thanks for your time!
EDIT: OK, my mistake was pretty stupid. I forgot that you need to pass ?date= when the variable isn't named id.
I see in the comments that the "btn" class is a CSS class not a C# one, but nonetheless, where would I go if I wanted to edit it and/or make my own similar classes?
Thanks again!
I would suspect that the date parameter your passing through is not been matched by the Action method.
Simply Debug you code and check the value of date before it is assigned to the Viewbag.
Also, you could show the code that calls the 'News' Action Result.

How to mock a CQ5 Page object containing a cq5 tag

I have a method on which I'd like to run a JUnit test. I'm mocking the cq5 page using JMockit.
My test method looks like this
#Mocked
Page page;
#Mocked
PageManager pageManager;
Tag testTag = pageManager.createTag("someID","someTitle","someDescription");//i've left out the try catch for brevety
System.out.println(testTag.getTitle()); // always null here
public void testSomeMethod() {
new Expectations() {
// variables declared here are mocked by default
{
page.getProperties();
propertyMap.put("cq:tags", testTag);
returns(new ValueMapDecorator(propertyMap));
}
};
String propertyValue = methodToBeTested(page);
Assert.assertEquals(propertyValue, "someTitle");
}
And the actual method to be tested does this :-
public static String getTopic(Page page) {
String topic = null;
Tag[] tags = page.getTags();
System.out.println(tags.size()); // returns 0 when I run the test.
for (int i = 0; i < tags.length; i++) {
Tag tag = tags[i];
topic = tag.getTitle();
}
}
return topic;
}
This always returns null when I run the test; however the method to be tested works correctly in the real scenario.
I suspect I'm not setting/mocking PageManager correctly, and consequently, my testTag is null
How do I mock this correctly to get the output I'm looking for?
You're getting to this testing from the wrong side. The way mocks (usually - I've never worked with jmockit specifically) work is, you create a blank object that acts as an impostor. This impostor is not a true PageManager - it only acts as one, and introduces himself as one whenever asked. When someone asks that impostor to do something (like calling it's method), the impostor does not know what to do, so it does nothing and returns null. However, you can tell the impostor how to behave in certain situations. Namely, you can tell it what to do when a method is called.
In your case, you don't need to create actual tags to test that method - you only need to mock a page object that, when asked for it's tags, will return an array containing a mocked tag which, in turn, when asked for it's title, will respond with the title you actually want to use in your test.
I don't know jmockit, so I cannot provide any code snippet. This, however, is a general question not strictly connected to CQ5/AEM
You may not be able to find any 'setter' methods for all objects you are trying to mock and this is anyways not the correct approach to mock.
The best way as mentioned by is to use mocked pages. You can use the Expectations class (mockit.Expectations) to mock the values to be returned by certain methods in the object.
See this example of mocking a 'SlingHttpServletRequest' object in a MockedClass class.
#Test
public void testMethod(#Mocked final SlingHttpServletRequest request){
String indicator ;
new Expectations() {
{
request.getParameter("archive");
returns("true");
}
};
indicator = OriginalClass.originalMethod(request);
Assert.assertEquals(indicator, "true");
}
In a similar way, you can mock other objects and their desired values.
I have answered the same question here: https://forums.adobe.com/thread/2536290
I ran into the same issue. in order to resolve Tags, they must exists under /content/cq:tags/your/tag or /etc/tags (legacy).
The Page#getTags implementation makes a call to TagManager#getTags which in turn tries to resolve the actual tag resource in the repo. Since you are testing in an AEM context, you have to load these tags in the appropriate location for the MockTagManager to resolve them.
What this means is that you need to load your tags into the AEM test context just like you've loaded your resources (via json).
Take a look at the aem-mock TagManager impl here: wcm-io-testing/MockTagManager.java at develop · wcm-io/wcm-io-testing · GitHub start with the resolve method and debug your way to figure out where you need to add those tags.

Responsive columns with percentage max-width

What I need is very simple, or atleast it should be, but after days of research I've come to resort to asking on stackoverflow if anyone actually has any idea how to do this...
I have 3 columns of content, all of which have expandable content inside. None of the content is very wide, but it is plentiful (once expanded). I need to do it so that when you expand the content in one column, it shrinks the other two columns up to a certain amount, and when you expand the content of two columns it evens out etc. Then, the columns must have a percentage max-size and a min-size (percentage or static), so that when columns expand they don't completely squash the others, and so that I can set a maximum "expandability" to each column. For simplicity's sake, here's an example that would've done the trick if only it worked:
<table width="100%"><tr>
<td style="min-width:200px; max-width:60%;">Col1ExpandableContent</td>
<td style="min-width:200px; max-width:50%;">Col2ExpandableContent</td>
<td style="min-width:200px; max-width:40%;">Col3ExpandableContent</td>
</tr></table>
The above code doesn't work of course, but I'm sure you can imagine how it would work if it did. It's exactly what I need, only that max-width doesn't work with percentages on TDs for some reason. If you need a better visualization I made a fiddle to help illustrate the problem here: http://jsfiddle.net/m5xgcf3s/
I can't just use the min-width's of the cols because of the nature of the contents, they all need to be expandable but only a certain amount. I'm open for any solution and any way of doing this, it doesn't need to be a table (it's just that the TD widths and alignments in a table is perfect by default, if only it supported max-width percentage) or anything as long as it meets the requirements and doesn't use a framework (which hopefully shouldn't be needed anyway). Bonus if it doesn't use javascript at all, but BIG BONUS if you find a solution that allows for a smooth animated size transition while still meeting the requirements. Also bonus if you can explain to me why the heck max-width percentage doesn't work on table cells...
Thanks for the help guys, but I made a script that solved it myself... NO frameworks, NO jQuery, NO hacks, just give the TDs an id and put in this code;
<script type="text/javascript">
window.onresize=function setTDmaxwidth() {
var containerwidth = window.innerWidth;
if (containerwidth >= 400 ) {
document.getElementById("col1").style.maxWidth=( ( containerwidth * 0.6 )+'px');
document.getElementById("col2").style.maxWidth=( ( containerwidth * 0.5 )+'px');
document.getElementById("col3").style.maxWidth=( ( containerwidth * 0.4 )+'px');
} else { }
}
</script>
It simulates a percentage max-width by calculating a fraction of the container width every time its size changes (in this case the container is 100% the width of an iframe). I'll leave the question unanswered though incase anyone comes up with another answer (with or without a table), hopefully one which allows for width transition animations, or a valid explanation as to why percentage max-width's don't work on TDs
Can you try it?
I have kept example for only one tr td.
You have to do each function for this case.
try it, you will have some idea..
Css
<style type="text/css">
td { border: 1px solid black; }
</style>
Script
<script>
function onLoadFunction(){
if(($(".tdFirst div").text().length)<100){
$(".tdFirst div").css('width','200px'); // min width
} else if(($(".tdFirst div").text().length)>=400) {
$(".tdFirst div").css('width','400px'); //max width
} else {
$(".tdFirst div").css('width',$(".tdFirst div").text().length+'px'); //width auto adjust
}
}
</script>
HTML
<body onLoad="onLoadFunction()">
<table>
<tr>
<td align="center"class="tdFirst">
<div>
Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test
</div>
</td>
<td><p>testing...</p></td>
</tr>
</table>
</body>
Attempt #2
script Use jQuery in your fiddle
$('document').ready(function(){
$(".tdFirst div").each(function(){
if(($.trim($(this).text()).length)<50){
$(this).css('width','20px'); // min width
} else if(($.trim($(this).text()).length)>=60) {
$(this).css('width','60px'); //max width
} else {
$(this).css('width',$.trim($(this).text()).length+'px'); //width auto adjust
}
});
});
To set widths to be dynamic using percentages and max-width, the parent should have a fixed width in px terms , so in this case it has to be either on the table element or a container div of table element.
I have updated the fiddle here: http://jsfiddle.net/qoaxxbqp/
this update has both initial widths set on container div as well as table element as in :
<div style="width:600px;border:2px blue solid;" >
<table width="500px"><tr>
<td style="min-width:100px; max-width:60%;">Col1ExpandableContent</td>
<td style="min-width:100px;max-width:50%;">Col2ExpandableContent</td>
<td style="min-width:100px; max-width:40%;">Col3ExpandableContent</td>
</table>
</div>
you also only have table set to a fixed width initially and not have a parent container, or set fixed width on container div and use width:100% on the table. Either way, but have a parent / immediate parent's parent with a fixed width(table with % width in this case).
I have also added a jquery hover in/out functions to demonstrate the expansion.