Firstly to address the obvious
I’ve seen a million and one questions on this with the main dupe target being:
How do I return the response from an asynchronous call?
This does not suit my needs because
B: that question is more specific to Ajax which makes it extremely confusing for me to gain anything from it.
C: this is more about the best way to wait for asynchronous calls like this to complete
What I’ve done besides Stack overflow research
I also went to many websites including:
Which gave me some basic insight on how callbacks are implemented and I’ve implemented one correctly
I also found this website
What rabbit hole did you go down?
an overarching description of what I’m doing
I have a thread off of main. This thread clicks a web-element. The clicked web-element has 3 basic cases I want to document/flag for:
- clicking it doesn’t reload the page and doesn’t move/get deleted (locators remain the same)
- clicking it doesn’t reload the page but the element locators (think ‘id’ get deleted or changed)
- clicking the web element causes a page reload
In order to document these three cases I need flags for, the on-load event and the stale-reference exception event and I want a timeout if both those don’t happen in time. If on-load happens then we know its case 3, in stale-reference happens but on-load doesn’t happen.
The code in question
Notes on the code/what I need codewise
The only things required to run this should be a web element, a driver object and maybe some print statements to be the ‘flags’. I used the chrome-driver
driver because I like chrome and I’m using the question box as the
webElement (and of course deleting my comments). My styling and syntax is probably messy but this is just test code at this point I want to get it functional. What I want is basically a
InsideCallback.POST(somedata) to java
But in code that works with (or replaces) my current test code. I know that since its asynchronous I don’t want to poll the return result (that defeats the purpose of the whole being asynchronous thing). I just don’t know how to say ‘when this function in another language returns its stuff’ in code. Unfortunately I don’t have a specific error with a stack-trace because its more about whats NOT in the code. I feel like I’m on the right path but I need to know if Ajax is the right way to go. The problem is, the workable examples of this seem complicated and might take awhile so I want to know what I’m getting into.
Updated code so it shouldn’t have syntax errors that cause stacktrace/failure, it ran fine when I tried it, just some parenthesis mixup and argument syntax that was wrong. I still am missing some way to actually callback the callback function but I’m going to continue trying to research it.
Updated question to more accuractely reflect title/current status of research.