How to Pause your script in selenium untill your Autoit script gets completed? - eclipse

I want Selenium to wait untill and unless Autoit Script is completed.
Right Now whats happening is When I run TestNG.xml file it runs all the #Test Priority wise and within 5 sec TestNg output Console Shows all the #Test are Passed.
While my AutoIT scripts are still running parallely in background.
The Code is as Follows:
#Test (priority=1)
public void CreateNew() throws Exception
{
Runtime.getRuntime().exec("exeFiles\\CreateNew.exe");
}
#Test (priority=2)
public void OpenaFile() throws Exception
{
Runtime.getRuntime().exec("exeFiles\\OpenaFile.exe");
}
And the Code of AutoIt file is as Follows:
createnew()
Func createnew()
Sleep(2000)
Run("Mspaint.exe")
WinWaitActive("Untitled - Paint")
Send("!f")
Sleep(1000)
Send("n")
Sleep(2000)
WinClose("Untitled - Paint")
EndFunc ;==>createnew

You need to create a new process for AutoIt and wait for the process to complete. Look at below example.
#Test (priority=1)
public void CreateNew() throws Exception
{
Process p =Runtime.getRuntime().exec("exeFiles\\CreateNew.exe");
p.waitFor();
}
#Test (priority=2)
public void OpenaFile() throws Exception
{
Process p = Runtime.getRuntime().exec("exeFiles\\OpenaFile.exe");
p.waitFor();
}
p.waitFor() will make the current Thread to wait for the process.

Related

Breakpoints in NUnit and stopping Debugging - How to kill a Test?

My apologies, it is an odd use case but please bear with me.
I have a simple TestFixture (as shown below) that outside of calling a PrimeService to check whether or not a number is prime, logs to a file whenever a routine is hit (ie. OneTimeSetup, Setup, OneTimeTearDown etc.)
Can someone please explain to me why If I run the following scenario, the TestFixture runs in it's entirety?
I place a breakpoint in my Test right before my Assert.
I start a "Debug Tests" process in VS (2019)
When the test pauses (and it will on the first test naturally), I press the "Stop Debugging" button (shift F5)
If I go and open my log file, I will see that all 3 tests ran, as did the TearDowns and final Teardown.
My apologies, I just want to understand what is going on under the hood, and whether or not there is a way to kill a paused Test run.
Thanks.
[TestFixture]
public class PrimeService_IsPrimeShould
{
private NerdAnalysis.PrimeService _primeService;
private System.IO.StreamWriter file;
[OneTimeSetUp]
public void OneTimeSetup()
{
file = new System.IO.StreamWriter(#"C:\Users\Fozzy Bear\source\repos\NunitTutorial\MyFile.txt");
file.WriteLine("One time SetUp");
}
[SetUp]
public void Setup()
{
_primeService = new NerdAnalysis.PrimeService();
file.WriteLine("Setup");
}
[TestCase(-1)]
[TestCase(0)]
[TestCase(1)]
public void IsPrime_lessthan2_pass(int value)
{
file.WriteLine("Running test for value " + value);
var result = _primeService.IsPrime(value);
Assert.IsFalse(result, "${ value} should not be prime");
var breakLine = "break";
Assert.Pass();
}
[OneTimeTearDown]
public void FinalTearDown() {
file.WriteLine("Final Teardown");
file.Close();
file.Dispose();
}
[TearDown]
public void TearDown()
{
file.WriteLine("Tear down");
}
from http://msdn.microsoft.com/en-us/library/406kfbs1.aspx
Stop Debugging terminates the process you are debugging if the program
was launched from Visual Studio. If you attached to the process,
instead of launching it from Visual Studio, the process continues
running. If you want to terminate attached processes, you can
terminate a single process from the Processes window or terminate all
attached process with the Terminate All command.

Purging workflow after couple minutes

I have a Workflow step which if meet issues throw WorkflowException with a message and stacktrace, in effect - blocks whole workflow launcher with the payload. Finally, the workflow is indefinitely in the RUNNING state and does not handle any updates for blocked payload. This situation requires admin action to manually terminate the workflow.
There is how the simple workflow looks:
#Service
#Component
#Properties({
#Property(name = Constants.SERVICE_DESCRIPTION, value = "Workflow"),
#Property(name = "process.label", value = "Workflow Step") })
public class WorkflowStep implements WorkflowProcess {
#Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)throws WorkflowException {
try {
... doing some stuff ...
} catch (Exception e) {
throw new WorkflowException(e.getMessage(), e);
}
}
}
I want to check after i.e 2 minutes if the workflow is COMPLETED if not - terminate them to unblock the payload and after upload the next asset into this path - again handle by the workflow.
Any idea how to solve it without using CRON Scheduler?
If you catch the exception, why don't you terminate the workflow right then instead of throwing a WorkflowException?
You could log whatever you want, handle the error and then terminate...
BR,
Oliver

Java Program output printed in random position in Eclipse console

I have a JUnit class in Eclipse project. It is like the following:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*some other imports*/
public class _JunitTests{
final Logger logger = LoggerFactory.getLogger(_JunitTests.class);
public void test(int num){
logger.info("**** tests no."+num+" ***");
/* some code */
}
#Test
public static void test1() {
test(1);
}
#Test
public static void test2() {
test(2);
}
#Test
public static void test3() {
test(3);
}
#Test
public static void test1() {
test(1);
}
}
When I run all the tests, I was expecting output such as[class information of info is ignored]
**** tests no.1 ***
/* somethings */
**** tests no.2 ***
/* somethings */
**** tests no.3 ***
/* somethings */
However, the result shown in console is usually messed up like:
**** tests no.1 ***
**** tests no.2 ***
**** tests
/* somethings */
no.3 ***
/* somethings */
/* somethings */
This happens a lot before with my other codes when there are Exception messages.
My guess before is stderr and stdout are handled in different threads, and so the result would be displayed without a certain order.
Since the info from Logger is also red in Eclipse console, my guess is that it uses stderr to display the message? is it the case? if so, is there a way to solve the problem of messed up order? thanks.
Which logging framework do you use with SLF4J? It could be that the logging framework is configured to write the log messages asynchronously in a background thread.
You can try to replace the log call with a System.out.println() and see if that produces the output you expect. If it does you may want to reconfigure the logging framework to log the messages synchronously.

SWTbot tests not behaving as expected

So I'm testing an eclipse plugin with SWTbot and I'm not getting the result I'm expect - when I cut the test down it turns out that the problem isn't with the bot it's with some code that I've copied accross from another part of the program (where it was fully functional)
The following code...
#RunWith(SWTBotJunit4ClassRunner.class)
public class Tests {
private static SWTWorkbenchBot bot;
#BeforeClass
public static void beforeClass() throws Exception {
bot = new SWTWorkbenchBot();
bot.viewByTitle("Welcome").close();
}
#Test
public void maybeThisWillWork(){
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
System.out.println("A");
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
System.out.println("B");
}
#AfterClass
public static void sleep() {
System.out.println("In the sleep function");
bot.sleep(10000);
}
}
Gives me the output -
A
In the sleep function
Rather than the expected
A
B
In the sleep function
Any ideas?
you may need to run your test as JUnit plugin test. Have you tried that?
So it turns out that the answer is thus (also a nice advantage of stackoverflow is that I actually solved this somewhere else, remembered I'd had a similar problem and then had to come back to stackoverflow to remind myself of the details)
SWTBot isn't running in the UI thread proper hence the null pointer errors, what I had to do was use effectively:
Display display = bot.getDisplay();
display.syncExec(objectThatdoesthethingiwanttogetdoneintheUIthread);
System.out.println(objectThatdoesthethingiwanttogetdoneintheUIthread.results);
...and that got things working...

selenium server problem

In eclipse i write one test case i am trying to run that case but its showing error
This is my sample test case with junit:
public void setUp() throws Exception
{
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}
public void testCase1() throws Exception {
selenium.open("/jaidproj/home.jsp");
selenium.click("//ul[#id='navigation']/li[2]/a/span[2]");
selenium.waitForPageToLoad("30000");
selenium.click("//div[#id='sidebar-a']/table/tbody/tr[1]/td/a[3]");
selenium.waitForPageToLoad("30000");
selenium.click("//ul[#id='navigation']/li[4]/a/span[2]");
selenium.waitForPageToLoad("30000");
selenium.click("//ul[#id='navigation']/li[5]/a/span[2]");
selenium.waitForPageToLoad("30000");
selenium.type("name", "dsagasg");
selenium.type("email", "jaid.sk#gmail.com");
selenium.type("contact", "342532235");
selenium.type("comment", "sdfsagasgas");
selenium.click("submit");
selenium.waitForPageToLoad("30000");
}
public void tearDown() throws Exception {
selenium.stop();
}
}
//
i updated in java build path jar files also..
But at the run time its showing error:see the error below
*Failed to start: SocketListener0#0.0.0.0:4444*
can any one help in this regard.
Thanks in adv.
Close the session of server once you finish executing testcases by typing the below line in browser
http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
I think Your Mozilla firefox is not on path.Please set and you can successfully run your tests..