get element based on class name - Cypress - cypress

I want to get the following element from the dom.
<span class="MuiBadge-badge MuiBadge-anchorOriginTopRightRectangle MuiBadge-colorError">5</span>
I'm looking for a simple syntax like: cy.contains('.MuiBadge-badge'). I can pass the full list of classes but it is not what I'm looking for.

You should also be able to use cy.get('[class*="MuiBadge-badge"]'). The asterisk usually represents a wildcard, and indicates that, in this case, the class contains this string.

You're close. You would just use the .get() command.
In your example, you could select based on one or more classes. Note for each class name you are selecting the period before the class.
For a single class: cy.get('.MuiBadge-badge');
For multiple classes: cy.get('.MuiBadge-badge .MuiBadge-anchorOriginTopRightRectangle .MuiBadge-colorError');
The documentation is here: https://docs.cypress.io/api/commands/get#Syntax

Related

How are request parameters mapped into RenderingModel of magnolia?

Im using Magnolia RenderingModel in combination with Freemarker.
I have URLs like the following:
http://anyPath/context?productTypes=XXXXX&productTypes=YYYYY
my rendering model class looks like:
class MyModel extends RenderingModelImpl {
...
private String[] productTypes;
...
}
However the mentioned array contains only the first value, but not the second.
I checked the behaviour of template directives like ctx.getParameters(). This shows the same behaviour, I get only the first value returned. But if im using ctx.getParameterValues(paramName), it returns both values.
This leads me to following questions:
How would I go, if I want to lookup how the request parameters are mapped into the rendering model, or better:
How can i change the behaviour of that ?
Can anyone acknowledge, that this behaviour is wrong ?
It used to be mentioned in documentation and I believe it still is - if you use .getParameters() you get only first value for multivalue parameter. If you want to get all the values, you need to use .getParameterValues(String param).
From what I understand reasons for that were backward compatibility.
As for changing the behavior, you would need to write your own renderer (e.g. by extending default FreemarkerRenderer and override info.magnolia.rendering.renderer.AbstractRenderer.newModel(Class<T>, Node, RenderableDefinition, RenderingModel<?>) method which instantiates and populates the model class.
Alternatively you can provide fix for above set population method and submit it to Magnolia as a patch. While the .getParameters() behavior is iirc on purpose, the model param population might not be, so you have high chance of getting that changed.

Trouble with complex routing rule

I have a lookup table called BlockCustomer. I also have an FTP Adapter that picks up files from multiple customers. I need to be able to determine the customer from the source of the file and do a lookup on the table. If BlockCustomer.Customer1 = 0 then it will send it to it's target, otherwise it will do nothing.
If I could use javascript I would do something like this:
WHEN Lookup(BlockCustomer,HL7.Source.split("/incoming/")[1].split("/")[0]),1) = 0
But obviously I can't. I found $ZSTRIP but I'm not sure if or how it will work. Is this possible or am I going to have to create a custom class?
In Cache we use function $piece if needs to get some parts of string by delimiter. For rule you could use the same function called Piece, with the same arguments. So you conditions should looks like:
Lookup(BlockCustomer,Piece(HL7.Source,"/incoming/",2),1)=0
By the way if you think, that you need some specific functions for you, you can do it by developing it. Just extend the class Ens.Rule.FunctionSet and add a method. And function will appear with the same name. As an example you can see at Ens.Util.FunctionSet class, which contains almost all available functions.

Parse.com: Check if Class exists

Is there a way to check if a Class with a certain name exists in Parse?
In my db I am creating classes on the fly and want to check if a Class exists before querying it.
I know one way would be to store all the names of the class in a dedicated class just with the names of the created classes and then to query that. I am wondering if there is a more direct approach
I think there is not yet a method implemented to check if the class exist. What you can do, is do a query on the class name and if it returns an empty list of objects, it is fair to assume that the class does not exist.
You can make a get request on the "schema api" for the class whose existence you want to check.
If the class is not found then an error message is returned clearly stating that the class doesn't exist/ not found.
Here is the link showing how to make a fetch request on the class schema:
http://parseplatform.github.io/docs/rest/guide/#fetch-the-schema
Hope it helps!

REST sort descending with minus ('-') symbol, rather than <propertyName>.dir=desc

I'm trying out Spring Data with MongoDB and REST as shown here. One thing I noticed is that to sort results, you add a query parameter named .dir with a value of "asc" or "desc".
In many REST APIs I've used, the mechanism for sorting was to simply put a minus ("-") symbol in front of the property name in the sort (or order) parameter.
Is there any way I could customize Spring to allow for this behavior?
I remembered I stumbled on this thread before I made the customized resolver. You can use SimpleSortHandlerMethodArgumentResolver class on https://github.com/sancho21/spring-data-commons/commit/6c90a9cfcb50b2ed0e7a25db0cfd64d36e7065da
Please comment to support its adoption on https://github.com/spring-projects/spring-data-commons/pull/166/files
As for reminder, in order to use this class, you need to inject an instance of it into the existing the constructor of existing PageableHandlerMethodArgumentResolver instance.

Ruby: How to get method content dynamically and write it to file?

I'm working on transforming legacy code to a new one in a new project.
There are more than 100 of similar codes and I have to transform them to a slightly different new format.
Basically, get a particular method from the legacy application, rename it, modify the content of the method to fit the new format, and put that method in a class for the new project.
Since there are more than 100 of them, I want to do it programmatically, instead of manually copying and pasting and modifying.
Is there a way to get the source code of a method as a string dynamically?
It must be only for a specific method, not the entire content of the class or file.
After that is done, I think I can just do gsub, or maybe use AST (Abstract Syntax Tree) to pass to Ruby2Ruby.
So I need more than the answers for the question How can I get source code of a methods dynamically and also which file is this method locate in?.
Any help will be greatly appreciated.
After further investigation, I resorted to use live_ast gem to convert the method object to Abstract Syntax Tree and generate the code for the method from that Abstract Syntax Tree (it's using Ruby2Ruby underneath).
Actually, live_ast provides a convenient method to_ruby to do the both steps.
It's working very well.
e.g.
require 'live_ast'
require 'live_ast/to_ruby'
SomeClassWithMethod.instance_method(:method_name).to_ruby
You could use source_location to find the beginning of the method you're looking for, then parse the file from that point until the end of the method. You could examine each line of the file starting from the start of the method, incrementing a counter when you find the start of a block and decrementing it when you reach the end of a block, until the counter reaches 0.

Resources