How to simulate specific code part as if previous ones were executed - java

I'm writing automation code by using selenium web driver in eclipse. as per my assumption, whole case execution time probably will take about five minutes but once my code got an error, I have to run it from the beginning after changing the code to see whether changing part is working fine or not. Is there a way to simulate the part being until to fixed code?

Simulate the error outside of the test script, fix it, put it inside the test and run it.
OR comment the code in a manner that the line where the error is happening still works.
For these 2 solutions, you need to know:
What the error is
What the application does
Does this part of the script work without some other parts?
Can i manually do the necessary steps for the test on the browser with debugging, so it's quicker to reach the desired step?
You just need to improvise.
Hope this helps.

There is no way for you to accomplish this, unless of course you code the scenario in such a way that you're able to mimic that state that the application WOULD be in had you ran through the entire test. There's no magical way to make it happen by itself.

Related

how do i work around 429 errors in selenium?

I run into 429 errors a lot in selenium, because the driver is too fast for the server. this causes the website to get stuck (with no error message presented to the user). I use waits and I've tried using the sleep method but it doesn't always work. Is there anything I can do or is this a design flaw on the website - shouldn't the error be presented to the user so I can try to reload the page?
I am using incognito mode so cookies aren't an issue.
try adding the bellow line of code after declaring the driver
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
also using sleep having assigned it a fair amount of time? make sure that it's using millescondes
thread.sleep(3000);
It might be an issue that has to be handled in the source code of the application. I would do the following:
Run a performance test and see if I can replicate it.
Check the logs of the application to see if this happening frequently on production.
Please see following article for dev to handle 429 errors --> link
Otherwise the solution provided by #hamza belatra should be sufficient.
Unless it is a problem in your Test Architecture code, how to the driver is handled and so on.

How to track the methods used in a Java application while running

I am working on understanding a project which was already created by someone else. It did not followed a proper coding method (no comments and so on). I'm finding it difficult to find where a method is used during the use of the app .So ideally I want to track how each method is used and when it's called while manipulating the applciation . I've already searched the problem here and nothing worked for me. So can anyone please help me out.
I am using Intellij btw .
Thank you .
You can use the debugger of Intellij, that's a really cool tool and besides your problem, it can be used to find bugs in your code.
The basic and easiest way to use it is:
Add breakpoints on lines where you want the application to stop just before executing that line. You can add as many breakpoints as you want and in as many files you want. To add a breakpoint, just click on the empty space beside the line numbering on the left side of the editor window.
then turn on the debugger from the run menu or Shift + F9.
then use the step over option or F8 to jump to the next breakpoint from the current location.
In your case, you can add a breakpoint in the method for which you wanna test, and then see if the program approaches that particular breakpoint during execution.
You can read the more detailed documentation on debugging from this link: Complete debugging guide: Jetbrains.
Hope this helps to solve your issue.
use Find Usages for the method to see where it is used
use a method call hierarchy to see which methods invoke this method
use method breakpoint to stop in debugger any time the method is invoked

Why doesn't Android Studio see updates right away?

I am using Android Studio 4.1.1. windows 7. I write in Java. I noticed this feature of the program. Changing something in code, layout or resources. I run the program and see that my changes have not appeared! First comes the thought that I was wrong somewhere. I start looking for an error. I don’t find it. I run the program again and it already works as it should. Now I'm used to it. The larger the program, the more often this happens. To be sure of the result, you have to run the program twice each time, because I'm not sure if this time all the changes took effect. It is very uncomfortable. Tell me why this is happening and how to solve this problem.

How on earth does he debug a running application like this, and more importantly, how can I?

"Debugception!"
You may notice that within the first 15 seconds of this YouTube video (from 1:01:01 to 1:01:16), Markus Persson (aka "Notch", creator of Minecraft) has somehow managed to save/update an application and attach a debugger to it while it was already under the process of being debugged, supposedly all with a simple keyboard shortcut. The previously coded application somehow magically became the newly edited one, and seemingly without relaunching it or spawning a new process... It's possible that this is just some form of locally remote debugging, but something about it just doesn't seem quite right.
I've spent several days Googling and asking around on how he was able to do this, yet to no avail. I've found no such option under Eclipse preferences, and whenever I try to save & debug an already running application, it simply launches a separate instance of the newly updated application, side-by-side with the older, outdated one.
Am I missing something? How was this possible?
How was he able to utilize such an astounding, powerful debugging feature?
Thanks in advance!
Update
Okay, so this appears to be a standard feature specific to Eclipse.
Coming from a background in NetBeans and Visual Studio, I'm astounded that this doesn't seem to exist elsewhere (or at least in NetBeans!)...
This is a built-in feature of Eclipse. If you edit a method while the program is running in debug mode, it will compile the new method, and replace the old method with the new version. If some thread was already running that method, it will jump back to the beginning (AFAIK; this might only happen when the program is paused).
You don't need to re-launch the program or set any special preferences. Just edit and save, and the magic will happen.
Eclipse can't always figure out how to merge your changes into the running program - usually if you changed anything outside a method body (including the method's parameters or return type). In this case, you will get a warning dialog, with the option to stop the program, restart the program or ignore the changes.

Selenium RC and Internet Explorer

I am trying to create a fully-automated test suite for a web application, using Selenium RC and test cases written in Java. However, I have encountered a few problems that I have not been able to solve. Please let me know if you have a suggestion about any of these issues.
Single window mode. I would like to run single window mode because I think it will provide a significant performance improvement, and probably solve problem 2. I am able to run my test cases in single window mode with Firefox and everything works as expected, with much faster execution. However, I have not been able to get my test cases to execute when using single window mode with Internet Explorer; button clicks do not work at all, so the tests fail due to the browser never advancing to the next screen. The exact same test case executes fine in multi-window Internet Explorer. Is there some kind of trick I can use to get this working?
When running in multi-window mode, if there is an error in the test, or if the user exits the Selenium GUI window, the browser never closes. I know that it is possible to get the process id and kill it, but this seems rather dangerous, especially if the user is running multiple instances of the browser. This is part of the reason that I would like to use single window mode, if possible. Is there some other way, possibly by handling the window close event for the Selenium GUI, to solve this?
I am unable to use the waitForPageToLoad command in any of my test scripts because it will never recognize that the page has loaded and resume execution. I think this is because the pages use Javascript, but I am not sure; I don't have too much experience in webpage development. Right now, I am using the wait command and specifying the amount of time to wait. However, this is very unreliable, sometimes if the Internet connection is slow, my tests fail because the wait times are not long enough. Other times the tests are excessively slow, due to long wait times. Any ideas for how to handle this problem?
Thank you! I appreciate any answers or suggestions you can give. Please let me know if you would like some more information.
For multi widow close issue, you need to handle the exceptions. Call the close function in the finally block will resolve the window close issue.
For Page refresh, you need to check that manually and call in correct places. Usually clicking on links will cause page refresh before showing next screen.
Have you tried IE HTA mode? When I used to mess with this stuff it was the only reliable way to run tests on IE.
Not sure
You need to use the wait class. In essence you make an action then poll on an element which isn't present yet but you know will be when its safe to continue with the test. So you only ever wait the minimum time needed.

Categories

Resources