How to send Keys.Tab as a parameter to a function - selenium

I have a code as below:
void someFunc(){
driver.findElement(By.xpath(OR.getProperty("Nodes_AddNodeDescriptionInput"))).sendKeys(Keys.TAB);
}
which sends a key Tab to the xPath mentioned.
But i want to avoid driver...details in that someFunc(), so I want to have a code which replaces the above code with the below one.
if(!sendKeyboardKeysByXpath("Nodes_AddNodeDescriptionInput", Keys.TAB)) {
printError("Failed to send the Tab key.");
return(false);
}
Def for sendKeyboardKeysByXpath:
public static boolean sendKeyboardKeysByXpath(String xPathKey, CharSequence... textToType) {
printLogs("Calling sendKeyboardKeysByXpath with values: " + xPathKey + ", " + textToType);
try {
printLogs("Typing '"+ textToType + "' to " + xPathKey);
if(!checkElementPresenceByXpath(xPathKey)) {
printFunctionReturn(fn_fail);
return(false);
}
driver.findElement(By.xpath(OR.getProperty(xPathKey))).clear();
driver.findElement(By.xpath(OR.getProperty(xPathKey))).sendKeys(textToType);
}
catch(Throwable t) {
ErrorUtil.addVerificationFailure(t);
printError("sendKeysByXpath: Exception occurred while typing keys.");
printFunctionReturn(fn_fail);
return(false);
}
return(true);
}
How to send the Keys.Tab as a parameter. I am getting garbage value in sendKeyboardKeysByXpath function

Use Keys.TAB.name() it will write TAB
So in your log method it would be textToType.name()

Related

ArchUnit case insensitive name matching

I'm trying to setup tests with Arch Unit to test my naming conventions, following the official examples.
It seems ArchUnit's naming assertions are case sensitive, which is bothering me.
I want to test that no classes in the package domain.service contains the word service.
Given a class domain.service.FileSystemService:
This test passes:
#ArchTest
val domain_service_should_not_have_names_containing_service: ArchRule =
noClasses()
.that().resideInAPackage("..domain.service..")
.should().haveSimpleNameContaining("service")
This test fails:
#ArchTest
val domain_service_should_not_have_names_containing_service: ArchRule =
noClasses()
.that().resideInAPackage("..domain.service..")
.should().haveSimpleNameContaining("Service")
Am I missing something? Is there a way to make ArchUnit's comparisons case insensitive?
If you don't want to use haveNameMatching as proposed in the comments you can also create your own ArchConditions.
public static ArchCondition<JavaClass> containName(String namePart) {
return new NameContains(namePart);
}
private static class NameContains extends ArchCondition<JavaClass> {
private String namePart;
NameContains(String namePart) {
super("contain '" + namePart + "' in the name");
this.namePart = namePart;
}
#Override
public void check(JavaClass javaClass, ConditionEvents events) {
boolean containsName = javaClass.getSimpleName().toLowerCase().contains(namePart.toLowerCase());
String message;
if (containsName) {
message = createCheckMessage(javaClass, "contains '" + namePart + "' in the name");
} else {
message = createCheckMessage(javaClass, "does not contain '" + namePart + "' in the name");
}
events.add(new SimpleConditionEvent(javaClass, containsName, message));
}
}
// taken from com.tngtech.archunit.lang.conditions.ArchConditions
public static <T extends HasDescription & HasSourceCodeLocation> String createCheckMessage(T object,
String message) {
return object.getDescription() + " " + message + " in " + object.getSourceCodeLocation();
}
You can use it like this:
rules.add(noClasses().that().resideInAPackage("..domain.service..").should(containName("Service")));

How to return object from retrofit api get call

I am trying to get list of objects from api call with retrofit but i just cant find the way to do so :(
This is the function i built:
private List<Business> businesses getBusinesses()
{
List<Business> businessesList = new ArrayList<>();
Call<List<Business>> call = jsonPlaceHolderApi.getBusinesses();
call.enqueue(new Callback<List<Business>>() {
#Override
public void onResponse(Call<List<Business>> call, Response<List<Business>> response) {
if(!response.isSuccessful())
{
textViewResult.setText("Code: " + response.code());
return;
}
List<Business> businesses = response.body();
for(Business business : businesses)
{
String content = "";
content += "ID: " + business.getId() + "\n";
content += "Name: " + business.getName() + "\n";
content += "On promotion: " + business.isOnPromotion() + "\n\n";
textViewResult.append(content);
}
businessesList = businesses;
}
#Override
public void onFailure(Call<List<Business>> call, Throwable t) {
call.cancel();
textViewResult.setText(t.getMessage());
}
});
}
I am trying to get the businesses response and return it.
can anyone help me?
Feeling frustrated :(
The way your executing the Retrofit call is asynchronous - using call.enqueue. there's nothing wrong with this approach. In fact it's perhaps the best option, since network calls can take a while and you don't want to block unnecessarily.
Unfortunately, this means you cannot return the result from the function. In most scenarios, if you did, the call would likely finish after the return making your return useless.
There are several ways to deal with this, the simplest one is to use callbacks. For example:
interface OnBusinessListReceivedCallback {
void onBusinessListReceived(List<Business> list);
}
private void businesses getBusinesses(OnBusinessListReceivedCallback callback){
Call<List<Business>> call = jsonPlaceHolderApi.getBusinesses();
call.enqueue(new Callback<List<Business>>() {
#Override
public void onResponse(Call<List<Business>> call, Response<List<Business>> response) {
if(!response.isSuccessful()){
textViewResult.setText("Code: " + response.code());
return;
}
callback.onBusinessListReceived(response.body());
}
#Override
public void onFailure(Call<List<Business>> call, Throwable t) {
call.cancel();
textViewResult.setText(t.getMessage());
}
});
}
You can then call it like so:
getBusinesses(new OnBusinessListReceivedCallback() {
public void onBusinessListReceived(List<Business> list){
// list holds your data
}
});

webflux Mono<T> onErrorReturn not called

this is my HandlerFunction
public Mono<ServerResponse> getTime(ServerRequest serverRequest) {
return time(serverRequest).onErrorReturn("some errors has happened !").flatMap(s -> {
// this didn't called
return ServerResponse.ok().contentType(MediaType.TEXT_PLAIN).syncBody(s);
});
}
time(ServerRequest serverRequest) method is
private Mono<String> time(ServerRequest request) {
String format = DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now());
return Mono.just("time is:" + format + "," + request.queryParam("name").get());
}
when i don't using param "name",it will throw one NoSuchElementException;
But, the Mono onErrorReturn not working!
why or what do i wrong?
The onError... operators are meant to deal with error signals happening in the pipeline.
In your case, the NoSuchElementException is thrown outside of the reactive pipeline, before anything can subscribe to the returned Mono.
I think you might get the behavior you're looking for by deferring the execution like this:
private Mono<String> time(ServerRequest request) {
return Mono.defer(() -> {
String format = DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now());
Mono.just("time is:" + format + "," + request.queryParam("name").get());
});
}

How can I get Annotation class from TypeDescription

I'm trying to work with ByteBuddy.
How, with given TypeDescription, can I get annotation class?
So far I found getActualName.
#Override
public boolean matches(final TypeDescription target) {
//System.out.printf("matches(%1$s)\n", target);
//System.out.printf("\tcanonicalName: %1$s\n", target.getCanonicalName());
//System.out.printf("\tcomponentType: %1$s\n", target.getComponentType());
{
final AnnotationList inheritedAnnotations = target.getInheritedAnnotations();
inheritedAnnotations.forEach(v -> {
//System.out.printf("\tinherited annotationDescriptor: %1$s\n", v);
});
}
{
final AnnotationList declaredAnnotations = target.getDeclaredAnnotations();
declaredAnnotations.forEach(v -> {
//System.out.printf("\tdeclared annotationDescriptor: %1$s\n", v);
});
}
{
final FieldList<FieldDescription.InDefinedShape> declaredFields = target.getDeclaredFields();
declaredFields.forEach(declaredFiled -> {
System.out.println("declaredField: " + declaredFiled);
final AnnotationList declaredAnnotations = declaredFiled.getDeclaredAnnotations();
declaredAnnotations.forEach(declaredAnnotation -> {
System.out.println("declaredAnnotation: {}" + declaredAnnotation);
final Set<ElementType> elementTypes = declaredAnnotation.getElementTypes();
System.out.println("\telementTypes: " + elementTypes);
final TypeDescription annotationType = declaredAnnotation.getAnnotationType();
System.out.println("\tannotationType: " + annotationType);
System.out.println("\tannotationType.actualName: " + annotationType.getActualName());
});
});
}
return false;
}
I'm, actually, trying to add some methods on compiled classes by some fields annotated with specific annotation.
An AnnotationList is a list of AnnotationDescription typed object where you can invoke the getAnnotationType method to receive a TypeDescription of their annotation type.

MPAndroidChart can't show markerview if I add onTouchListener ,if I remove onTouchListener ,markview can show again

I'm using MPAndroidChart and it's very good ,but now I have a problem just like what I described . Besides, my onClick event can be triggered !
Try using the "onChartValueSelectedListener":
mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
#Override
public void onValueSelected(Entry entry, int i, Highlight highlight) {
//display msg when value selected
if (entry == null)
return;
Toast.makeText(getActivity(), entry.getXIndex() + " = " + entry.getVal() + "%", Toast.LENGTH_SHORT).show();
}
#Override
public void onNothingSelected() {
}
});