I am unable to Playback my CodeduiTest - playback

I am new to CodedUI, I am using VSTS 2012. Here I am able to record a script on IE9 but I am unable to play back the script. while play back it is giving an error says Unable to find Control. even I put wait and waitforcontrolready etc...

Depending on the exception that is thrown you can use other click methods if you are sure the control is there. Loading may or maynot be the cause, thus waits may or maynot do anything. Example below, you can do custom clicks since each exception throw are caused by different reasons:
try{
WaitForControl(uiControl);
Mouse.Click(uiControl);
}
catch (FailedToPerformActionOnHiddenControlException e)
{
WaitForControl(uiControl);
Mouse.Click(new Point(uiControl.Left + (uiControl.Width / 2), uiControl.Top + (uiControl.Height / 2)));
}
catch (FailedToPerformActionOnBlockedControlException e)
{
WaitForControl(uiControl);
Mouse.Click(new Point(uiControl.Left + (uiControl.Width / 2), uiControl.Top + (uiControl.Height / 2)));
}
catch (PlaybackFailureException e)
{
WaitForControl(uiControl);
Mouse.Click(new Point(uiControl.Left + (uiControl.Width / 2), uiControl.Top + (uiControl.Height / 2)));
}
catch(Exception e){
WaitForControl(uiControl);
Mouse.Click(uiControl, new Point(uiControl.Left + (uiControl.Width / 2), uiControl.Top + (uiControl.Height / 2)));
}

Related

Spring Integration Channel works for first time, then does not the second time

When using Spring Integration and Channel to another integration flow, it only works the first time.
Then after that it skips over the channel and returns.
From first integration flow:
.handle((p, h) -> {
System.out.println("Payload Before Channel" + p.toString());
return p;
})
.channel(IntegrationNamesEnum.JAMS_SUBMIT_JOB_INTGRTN.getChannelName())
.handle((p, h) -> {
System.out.println("Payload After Channel" + p.toString());
return p;
})
Then on the next integration flow:
#Bean
public IntegrationFlow jamsSubmitJob() {
return IntegrationFlows.from(IntegrationNamesEnum.JAMS_SUBMIT_JOB_INTGRTN.getChannelName())
.handle((p, h) -> {
try {
jamsToken = authMang.getJamsAuth().getTokenWithTokenType();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JAMS_SUBMIT_JOB_INTGRTN
.info(IntegrationNamesEnum.JAMS_SUBMIT_JOB_INTGRTN.toString() + " Integration called.");
JAMS_SUBMIT_JOB_INTGRTN.info(IntegrationNamesEnum.JAMS_SUBMIT_JOB_INTGRTN.toString() + " Headers:= " + h);
JAMS_SUBMIT_JOB_INTGRTN.debug(IntegrationNamesEnum.JAMS_SUBMIT_JOB_INTGRTN.toString() + " Payload:= " + p);
return p;
})
.handle((p, h) -> {
// hail mary to get new token
return MessageBuilder
.withPayload(p)
.removeHeaders("*")
.setHeader(HttpHeaders.AUTHORIZATION.toLowerCase(), jamsToken)
.setHeader(HttpHeaders.CONTENT_TYPE.toLowerCase(), "application/json")
.build();
})
.handle((p, h) -> {
JAMS_SUBMIT_JOB_INTGRTN
.info(IntegrationNamesEnum.JAMS_SUBMIT_JOB_INTGRTN.toString() + " Submitting payload to JAMS:");
JAMS_SUBMIT_JOB_INTGRTN.info(IntegrationNamesEnum.JAMS_SUBMIT_JOB_INTGRTN.toString() + " Headers:= " + h);
JAMS_SUBMIT_JOB_INTGRTN.info(IntegrationNamesEnum.JAMS_SUBMIT_JOB_INTGRTN.toString() + " Payload:= " + p);
return p;
})
.handle(Http.outboundGateway(JAMS_SUBMIT_ENDPOINT)
.requestFactory(alliantPooledHttpConnection.get_httpComponentsClientHttpRequestFactory())
.httpMethod(HttpMethod.POST)
.expectedResponseType(String.class)
.extractPayload(true))
.logAndReply();
}
The behavior is that every other message gets through, basically skipping over the channel until the next time around. Strangely if I duplicate the jamsSubmitJob Bean, then it will work twice, then fail, then start over again.
Thanks!
This is a misunderstanding what is channel and what is a subscriber to that channel.
So, you have this:
.channel(IntegrationNamesEnum.JAMS_SUBMIT_JOB_INTGRTN.getChannelName())
.handle((p, h) -> {
This way you declare a channel (if that does not exist in the application context yet) and subscriber to it.
Then you have this:
return IntegrationFlows.from(IntegrationNamesEnum.JAMS_SUBMIT_JOB_INTGRTN.getChannelName())
.handle((p, h) -> {
This way you declare a channel (if that does not exist in the application context yet) and subscriber to it.
Did you notice a duplication in my explanation? I did that deliberately to take your attention to the problem.
So, if channel does not exist it is created. In the other place an existing object is used. In the end you end up with two subscribers to the same channel. The framework by default creates for us an instance of a DirectChannel, which come with a round-robin dispatching strategy. That means that the firsts message is going to a first subscriber, the second - to second, the third to the first and so on.
What you want is probably a request-reply pattern, and you better look into the .gateway(IntegrationNamesEnum.JAMS_SUBMIT_JOB_INTGRTN.getChannelName()) instead of .channel() in that your first IntegrationFlow.
See more info in docs:
https://docs.spring.io/spring-integration/docs/current/reference/html/core.html#channel-implementations-directchannel
https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl-channels
https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl-gateway

Expecting to catch an Aggregate Exception

I am trying to understand exception handling in TPL Dataflow so I can effectively handle errors. In my comment numbered 1. below I am expecting to catch an AggregateException but everything just halts and doesn't recover. If I remove the throw (2.) then the ActionBlock continues to process but again, the AggregateException handler doesn't trigger.
Would anyone be able to help with an explanation to improve my intuition.
Would also welcome any documentation references on the topic.
async Task Main()
{
var ab = new System.Threading.Tasks.Dataflow.ActionBlock<int>(async a => {
try
{
await Task.Delay(100);
if (a == 7)
{
throw new Exception("Failed");
}
else
{
Console.WriteLine(a);
}
}
catch (Exception ie)
{
Console.WriteLine(ie.Message);
throw; //2. This causes the actionblock to halt, removing allows block to continue
}
});
for (int i = 0; i < 10; i++)
{
await ab.SendAsync(i);
}
ab.Complete();
try
{
await ab.Completion;
}
catch (AggregateException ae)
{
Console.WriteLine(ae.Flatten().Message);
// 1. Expecting to catch here.
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
What you're seeing is the await unwrapping your Aggregate Exception. When you await the completion task the exception is unwrapped and thrown to the general exception catch. But if you don't unwrap the exception then you'd see the exception caught as an aggregate exception like this:
try
{
ab.Completion.Wait();
}
catch (AggregateException ae)
{
Console.WriteLine("Aggregate Exception");
// 1. Expecting to catch here.
}
catch (Exception e)
{
Console.WriteLine("Exception Caught");
}
It's obviously better to properly await the completion but this samples shows you that indeed an AggregateExcpetion is caught when it's not unwrapped.

why we use multiple catch when we can handle with parent exception

Exception handling provides the smooth flow of application but when we come to the technical part it's difficult to understand why we should use multiple catch blocks.When we can handle the exception by general parent exception using one catch block so why we need multiple catch
A multiple catch block is useful when you want to handle different exceptions in different ways.
try
{
int num1 = int.Parse(Console.ReadLine());
int num2 = int.Parse(Console.ReadLine());
int result = num1 / num2;
}
catch (DivideByZeroException ex)
{
Console.Write("Cannot divide by zero");
}
catch (InvalidOperationException ex)
{
Console.Write("Not a valid number");
}
catch (FormatException ex)
{
Console.Write("Not a valid number");
}
When use multiple catch blocks
To print message specific to an exception
To execute some logic specific to an exception

Java 8 Path Stream and FileSystemException (Too many open files)

geniuses!
I'm practicing Java 8.
So if I do something like this:
Files.walk(Paths.get(corpusPathStr))
.filter(path -> path.toFile().isFile())
.forEach(path -> {
try {
Files.lines(path)
.forEach(...);
} catch (IOException e) {
e.printStackTrace();
}
});
I got FileSystemException error.
If I open a file under forEach, may too many files be opened?
Or are there other reasons causing FileSystemException (Too many open files)?
Thanks for your help in advance!
Use
try(Stream<Path> stream = Files.walk(Paths.get(corpusPathStr))) {
stream.filter(path -> Files.isRegularFile(path) && Files.isReadable(path))
.flatMap(path -> {
try { return Files.lines(path); }
catch (IOException e) { throw new UncheckedIOException(e); }
})
.forEach(...);
}
catch(UncheckedIOException ex) {
throw ex.getCause();
}
The streams returned by Files.walk and Files.lines must be properly closed to release the resources, which you do by either, a try(…) construct or returning them in the mapping function of a flatMap operation.
Don’t use nested forEachs.
The UncheckedIOException might not only be thrown by our mapping function, but also the stream implementations. Translating it back to an IOException allows to treat them all equally.
Files::line opens and reads the file in a lazy manner, i.e. Stream<String>. Since you're not closing any of your opened Streams you're getting such an error.
So when you're done reading a file you should close its handle. Since the returned Stream is AutoCloseable you can and should use a try-with-resource block.
try (Stream<Path> walk = Files.walk(Paths.get(""))) {
walk.filter(Files::isRegularFile).forEach(path -> {
try (Stream<String> lines = Files.lines(path)) {
lines.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (IOException e) {
e.printStackTrace();
}

Closing stage after specific event

How do I close a stage in JavaFX 2 after some specific external event has occurred? Suppose I have a stage with a simple progress bar that is filled up by a Task (borrowed from another answer):
Task<Void> task = new Task<Void>(){
#Override
public Void call(){
for (int i = 1; i < 10; i++) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(i);
updateProgress(i, 10);
}
return null;
}
};
How do I close the window automatically (and open the next one) after the Task is done and the ProgressBar is filled to 100%?
Before return null; you can add
Platform.runLater(
new Runnable() {
public void run() {
stage.close();
}
}
);
or
progressBar.progressProperty().addListener(new ChangeListener<Number>(){
//add checking, that progress is >= 1.0 - epsilon
//and call stage.close();
})
The first is better. But note, that task is done on a separate thread. so you should put a request on stage.close() on JFX thread using special call.
Also, jewelsea provides links on stage closing questions in comment to the question.

Resources