help: combine several iim into one in java

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information:CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
super_hiro
Posts: 15
Joined: Tue Feb 23, 2010 2:06 pm

help: combine several iim into one in java

Post by super_hiro » Tue Mar 23, 2010 6:27 pm

Hi,

I have different iim and I need it all to be combined.

I have iim1 to log into a website, iim2 to run a script x amount of times, and iim3 to log off the website.

Basically I'm trying to:

1) Log into a website
2) Run 2nd iim x amount of times
3) log out of website

Can someone help me create a javascript that lets me run it automatically?

the part 2 is kind of tricky because I want to be able to specify how many times the script repeats. (Currently I'm doing this by selecting "Repeat Macro" on the Macro window, but I want the java to be able to do it automatically)

So is it possible to contain all the 3 into one javascript? I'm very new to Java, in fact don't know anything at all. If you can specify what does what so I can learn it also myself, that'll be awesome!

Thank you for any help!
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: help: combine several iim into one in java

Post by Daniel, Tech Support » Thu Mar 25, 2010 10:23 am

Hello,

I recommend that your read this article on Firefox JavaScript Scripting Interface.

So, basically you play a macro with iimPlay(), you set variables for a macro with iimSet() (prior to playing it!), you get the last value a macro extracted with iimGetLastExtract() and if a macro returned an error, you check it with iimGetLastError(). All of these commands are explained in the abovementioned article.

You would do task 1 by running a macro that does the login from JavaScript, task 2 can be accomplished by using JavaScript prompt() function and then playing the macro in a loop. Task 3 - run another macro that does the logout. You have a few JavaScript files with your installation of iMacros. You could use them as code examples.

Here is one of them:

Code: Select all

//imacros-js:showsteps no

// With the imacros-js:showsteps command you can tell iMacros to show or
// not show the Javascript commands during the execution. 
// Showing steps is useful for debugging, but adds an artificial delay to each step.

// This command overrides the global settings in the Option Dialog.

// Note that the command is *inside* a comment "//", since it is no
// official Javascript command and is used in the iMacros JS interpreter only.

// There can be only one such command per JS file and it affects the complete file.

var i, s;

iimDisplay ("Test script running");
iimSet ("NAME", "T. Test");
iimSet ("MENU", "Pizza");
iimSet ("DRINK", "water");
iimSet ("DESSERT", "Fruits");
iimSet ("IS_CUSTOMER", "Yes");
iimSet ("PASSWORD", "abcabc");
iimSet ("REMARKS", "Form filled");
iimSet ("WAIT", "3");

i = iimPlay("SI-Test-Macro1",60);

/* Check for error */
if (i < 0) {
    s = iimGetLastError();
    alert (s);
};

/* Submission completed, now check if the result page is ok */
/* We do this by checking if the ordered menu is indeed "Pizza"  */

iimDisplay ("Verify form output");
i = iimPlay("SI-Test-Macro2",60);

if (i < 0) {
    s = iimGetLastError();
    alert (s);
};

s = iimGetLastExtract();

if (s.indexOf ("Pizza") != -1)
    iimDisplay ("Test OK");
else
    iimDisplay ("Problem detected :"+s);
Best regards,
Daniel, iOpus Support
super_hiro
Posts: 15
Joined: Tue Feb 23, 2010 2:06 pm

Re: help: combine several iim into one in java

Post by super_hiro » Mon Mar 29, 2010 10:40 am

Hi Daniel,

As always thank you so much for your help.

I've created a simple javascript that works surprisingly enough:

Code: Select all

i = iimPlay("loginiimscript");
i = iimPlay("mainiimscript");
i = iimPlay("logoutiimscript")
What I want to do is put in a code to repeat "mainiimscript" 90 times.

Am I able to set that option in javascript? If not, are there other ways I can do this?
SFU666
Posts: 4
Joined: Mon Mar 29, 2010 2:42 pm

Re: help: combine several iim into one in java

Post by SFU666 » Mon Mar 29, 2010 5:23 pm

Hi, i need a simmilar script,

java script should
start Macro1
LOOP Macro2
Start Macro3
Start Macro4
start Macro1
LOOP Macro2
Start Macro3
Start Macro4

in an other post i found this as loop, can i combine the 2 samples ?
retcode = iimPlay("macro1");
for (i = 0; i < 90; i++) {
retcode = iimPlay("macro2");}
retcode = iimPlay("macro3");
super_hiro
Posts: 15
Joined: Tue Feb 23, 2010 2:06 pm

Re: help: combine several iim into one in java

Post by super_hiro » Mon Mar 29, 2010 6:52 pm

SFU666 wrote: in an other post i found this as loop, can i combine the 2 samples ?
retcode = iimPlay("macro1");
for (i = 0; i < 90; i++) {
retcode = iimPlay("macro2");}
retcode = iimPlay("macro3");
OMG you just helped me do what I wanted! Thank you!

But my macro2 is unique, pulling data from each line of .csv file.

Would you happen to know how I can make it loop but also extract new data from each rows everytime? Basically I have this on the iim

Code: Select all

SET !DATASOURCE_LINE {{!LOOP}}
but when I pull the macro2 from the javascript, it just populates 90 times with the same first row of the csv file.

Thank you so much!
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: help: combine several iim into one in java

Post by Daniel, Tech Support » Tue Mar 30, 2010 11:59 am

Hi Super_hiro,

I think I answered your question here.

Best regards,
Daniel, iOpus Support
SFU666
Posts: 4
Joined: Mon Mar 29, 2010 2:42 pm

Re: help: combine several iim into one in java

Post by SFU666 » Tue Mar 30, 2010 3:32 pm

May you post your source code when it worked for you, i dont get mine to open Imacros ...

Code: Select all

<script type="text/javascript">
retcode = iimPlay("#Current");
for (i = 0; i < 90; i++) {
retcode = iimPlay("aaaaaneu");}
retcode = iimPlay("aaajanine");
retcode = iimPlay("macro4");
retcode = iimPlay("macro5");
</script>
SFU666
Posts: 4
Joined: Mon Mar 29, 2010 2:42 pm

Re: help: combine several iim into one in java

Post by SFU666 » Wed Mar 31, 2010 7:24 pm

or could it be that this is not possible in the firefox version ? i dont get it to work ...

Code: Select all

var i, retcode,
retcode = iimPlay("macro1");
SFU666
Posts: 4
Joined: Mon Mar 29, 2010 2:42 pm

Re: help: combine several iim into one in java

Post by SFU666 » Wed Mar 31, 2010 10:01 pm

Ok, works now thx

Code: Select all

iimPlay("Login 1",60)
for( var i=0; i<2; i++)
{
iimPlay("StudiLOOP",60)
}
iimPlay("Logout",60)
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: help: combine several iim into one in java

Post by Daniel, Tech Support » Thu Apr 01, 2010 9:08 pm

Good job!
Daniel, iOpus Support
Post Reply