SeeShell Scripting with C#


#1

Hi,
I like SeeShell and I am considering getting the Pro version. I’m trying to follow the documentation for scripting and having issues. I took the demo from your GitHub (links are broken in documentation by the way) and tried to run both C# and powershell but can’t seem to get them to work. It can’t find the object “Kantu” when run, but it can find “SeeShell”. I downloaded SeeShell about 15 days ago so I assume I have the trial pro features to enable scripting. Can you provide any more guidance?

Goal is to run multiple macros in succession and output error messages via text file (what macro failed, which step, image file name at failure, etc.) to infer cause of failures without having to go manually go into SeeShell to run tests.

Thanks!


#2

Sorry, some parts of the Github documentation still need to be updated. “SeeShell” is the correct new name of the API com object.

In Powershell notation:

$comObj = new-object -ComObject SeeShell.Browser is correct if you want to start the SeeShell Chromium Browser

$comObj = new-object -ComObject SeeShell is correct if you want to start SeeShell Desktop Automation

=> Does this work for you? You also find sample VBS files in the seeshell/API folder after installation.

(I can add C# example code to Github in the next days, too.)

Goal is to run multiple macros in succession and output error messages via text file (what macro failed, which step, image file name at failure, etc.)

That should work - it is exactly why we have the API.


#3

Ok thanks, got it running with SeeShell.Browser. A couple of questions

#1: I’m trying to run multiple macros together. Is there a way to run multiple macros in sucession without refreshing the page? Currently the page refreshes each time a new macro is run.

#2: Also, I’d like to change how the image file paths are specified. By default, it will look in a folder that shares the same name as the macro.
Ex: Macro name = Test123.see
Image directory = Test123

Is there a way to specify a different folder, such as specifying a relative / absolute image file path within the macro? I’d like all of my macros to refer to one single directory, instead of many sets of folders being created for each macros’ images.


#4

Did you remove the Open command(s) from the 2nd/3rd… macro you call? Without them, there should be no refresh, and the 2nd macro continues where the first stopped.

The images in the SeeShell(.Browser)/image folder are only temporary files generated by SeeShell when it runs the macros. They can be deleted safely. All images are stored inside the .see file, which is technially a ZIP file with images (PNG) and macro flow (JSON) inside. See also this post: Export a macro to run on another PC


#5

Here’s what we’re trying to do… We want to create several small “component” macros (1 - Open Page, 2 - Click optional button, 3 - Select field, 4 - Click Save, etc.). We then want to be able to run any combination of these macros in series (and run other combinations in parallel). We figure the two ways to do this are to run multiple macros using some code like this:

 List<string> myScripts = new List<string>();
 myScripts.Add("Macro 1");
 myScripts.Add("Macro 2");
 myScripts.Add("Macro 3");

 for(int j = 0; j < myScripts.Count; j++)
            {
                i = myKantu.open(j == 0);
            ...
            }

Macros 2 and 3 contain at most 3 commands (ex: Click “Save”, done), but it still refreshes upon running the macro. Here’s the full JSON of one these macros:

    {
      "CreationDate": "2018-08-22",
      "Commands": [
        {
          "Type": "Image",
          "Mode": "Click",
          "Image": "save_20180822_180111477.png",
          "ConfidenceLevel": 0.5,
          "ClickHowMode": 0
        }
      ]
    }

If we can’t fix the browser refresh problem, we would want a quick and convenient way to generate a new SeeShell macro by aggregating several component macro JSONs and image files.

Lastly, is there more extensive documentation on the API so I can see type information?
Ex: the type return for SeeShell.browser is dynamic. This means I can write and compile bad commands, and only find errors when running the scripting app.

Thanks again, really appreciate the help!


#6

From your code snippets, I see that you have .open inside the loop (or is this a typo)? You need .open (= opens SeeShell Browser) only once per instance. And then use only PLAY commands.

So it should be

i = mySeeShell.open();

for(int j = 0; j < myScripts.Count; j++)
{
i = myKantu.Play(myScript[j]);

}

Does this solve the issue?

About the documentation: We plan a bigger update for the SeeShell docs in September. Meanwhile, please ask if anything is unclear. That helps as also the with improving the docs.

Here is a sample VBS script that runs several macros - no refresh should happen between each Play command. You find this script in the /documents/SeeShell.Browser/API folder. Note that i = myBrowser.open(true) is outside the loop.

'
' Self-test for Browser replay
' 
' This script runs all demo scripts and logs the result
'

option Explicit

Dim objFileSystem, objFile, myBrowser
Dim strOutputFile, i
dim objList, element, hasError

Const OPEN_FILE_FOR_APPENDING = 8

' generate a logfile name based on the script name
strOutputFile = "./log_"+  Wscript.ScriptName + ".txt" 
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)

msgbox ("Click OK to start. This test will take a few minutes.")

objFile.WriteLine("Self-Test started at " + cstr (now))

set myBrowser = CreateObject ("SeeShell.Browser")
if  myBrowser Is Nothing then 
	objFile.WriteLine("CreateObject ERROR: " + cstr(i) + " Text: " + myBrowser.getLastError())
    hasError = true
end if 

i = myBrowser.open(true)
if  i < 0 then 
	objFile.WriteLine("Open ERROR: " + cstr(i) + " Text: " + myBrowser.getLastError())
    hasError = true
end if 

'List of Test Scripts
Set objList = CreateObject("System.Collections.ArrayList")

objList.Add "Demo-Automate-Forms"
objList.Add "Demo-ITA-Flight-Search"
objList.Add "Demo-WebScraping"
objList.Add "Demo-Variables"
objList.Add "Demo-Download"
objList.Add "Demo-Upload"
objList.Add "Demo-PDF-Extract"
objList.Add "Demo-Mouse-Draw"
objList.Add "Demo-Variables"
objList.Add "Demo-Scroll"
objList.Add "Demo-Javascript"
objList.Add "Demo-ClickRelative"
' For Flash to work, install Flash: https://a9t9.com/kantu/flash#install
objList.Add "Demo-Flash"


'Run the tests!
Dim testnumber
testnumber = 1 
For Each element In objList

  i = myBrowser.echo ("Currently testing: " + element + " (" + cstr(testnumber) +" of " + cstr(objList.Count)+")")
  i = myBrowser.Play (cstr(element))  
  
  if i >= 0 then
   objFile.WriteLine("Play OK: " + element)
  else
    objFile.WriteLine("Play ERROR, Script: " + element + " Error code: "  + cstr(i) + " Text: "+myBrowser.getLastError())
	hasError = true
  end if 
  testnumber = testnumber+1
 
Next

'Close 
i = myBrowser.close
if  i < 0 then 
	objFile.WriteLine("Open ERROR: " + cstr(i) + " Text: " + myBrowser.getLastError())
    hasError = true
end if 

' close log file
objFile.Close
Set objFileSystem = Nothing

'inform
if (hasError) then
  msgbox ("There were some errors. Please check the log file: " + strOutputFile)
else
  msgbox ("All tests passed.")
end  if 
 

WScript.Quit(i)

#7

The refresh problem will get solved. Either it is an issue with your scripts, or indeed an issue with SeeShell (then we will fix it ASAP).

Independent of this:

.see macros are just ZIP files with a JSON and images. So you can manually create them:

  1. Put JSON and images (PNG) in a folder
  2. ZIP it
  3. Change zip archivve extension from .zip to .see => done!

Inside the ZIP, the json file can have any name, but must have the .json extension.

The reverse also works: If you rename *.see to *.zip you can open and manually edit SeeShell scripts in Windows Explorer or any other file manager.


#8

That’s not a typo, j == 0 upon start, and will increment past 0 (return false) during next run, preventing new browsers from opening.

Regardless I modified the code and still having the refresh problem in between each macro.
Also confirmed subsequent macros do not have any Open commands.

I think this might be a bug?

Below is modified C# code:

        i = myKantu.open(true);
        for (int j = 0; j < myScripts.Count; j++)
        {
            textBoxLog.Text += "Macro Name: " + myScripts[j] + "\r\n";
            if (i < 0) textBoxLog.Text += "Kantu Open Error: " + i.ToString() + " Text: " + myKantu.getLastError() + "\r\n";
            myKantu.echo("Hello from the C# app: "+ myScripts[j]);
            textBoxLog.Text += "Start Script\r\n"; 
            i = myKantu.play(myScripts[j]);
            if (i < 0)
            {
                textBoxLog.Text += "Script Replay Error: " + i.ToString() + " Text: " + myKantu.getLastError() + "\r\n";
            }
            else
            {
                textBoxLog.Text += "Script completed - OK\r\n";
            }
            myKantu.echo("Done");
        }

#9

Ouch, I confirmed that the latest version of the SeeShell Browser free/trial version has indeed a “refresh at macro start” bug . That should not happen. The PRO/PRO Plus editions are not affected.

I created a ticket for this and we will fix the issue asap. A patch for this issue should be available by the end of next week.


Duplicate json Files Appearing in SeeShell Browser
#10

We just released V3.2.1.2 of the SeeShell Browser, which should fix the issue discussed here.

The updated installer also includes a new Powershell test file SeeShell-ManyPlay-Demo.ps1. It runs three macros one after the other, each continuing where the other macro has left off.

Of course, please let me know if this version does not solve the issue.