Unable to access value from list

Hi there,

Could you please help me to correct my script below? I don't know to use list and how to access list value. :cry: I'm very appreciated.

==================================
ComonShare.script
function FindCurrentScreenAndPressButton inputbutton, screenlookingfor
    put inputbutton into selectedbutton
    put screenlookingfor into currentscreen
    if ["ComonShare" findImage:currentscreen] is true then
            ["ComonShare" PressSelectedButton: selectedbutton]
            Wait 2.0
    else
            set errormsg = "Unable to find" & selectedbutton
            LogError errormsg
            return false
    end if
end FindCurrentScreenAndPressButton
=======================

ExeTestCase.script
function testcase1
        put ((image1,screen1), (image2,screen2), (image3,screen3), (image4,screen4) into testcase1image
        put Failed into testcasefailed.
        put Passed into testcasepassed.
        repeat with each item of testcase1image
            if ["ComonShare" FindCurrentScreenAndPressButton: testcase1image] is not false then
                 ["ComonShare" FindCurrentScreenAndPressButton: testcase1image]
            else
                 set errormsg = "Testcase1 is failed at" & second value, screen from the list testcase1image.
                 LogError errormsg
                 return testcasefailed & errormsg.
                 exit function
            end if
        end repeat
      return testcasepassed
end testcase1

Comments

  • EggplantMattEggplantMatt ForumAdmin admin
    I think this should work.
    ==================================
    ComonShare.script
    function FindCurrentScreenAndPressButton inputList
        put item 1 of inputList into selectedbutton
        put item 2 of inputList into currentscreen
        if ["ComonShare" currentscreen] is true then
                ["ComonShare" PressSelectedButton: selectedbutton]
                return true
        else
                LogError "Unable to find" & selectedbutton
                return false
        end if
    end FindCurrentScreenAndPressButton
    
    =======================

    ExeTestCase.script
    function testcase1
            put ((image1,screen1), (image2,screen2), (image3,screen3), (image4,screen4) into testcase1image
            repeat with each item of testcase1image
                if ["ComonShare" FindCurrentScreenAndPressButton: it] is false then
                     LogError "Testcase1 is failed at " & it
                     return "failed" & errormsg
                end if
            end repeat
          return "passed"
    end testcase1
    
  • Thanks, Matt

    It works great; however, please help to bring this script to next level. What I really want is instead of using 2D array, I would like to read the image value from excel or text file. For example, the snip code above, instead of define
    function testcase1
    put ((image1,screen1), (image2,screen2), (image3,screen3), (image4,screen4)) into testcase1image
    repeat with each item of testcase1image
    if ["ComonShare" FindCurrentScreenAndPressButton: it] is false then
    LogError "Testcase1 is failed at " & it
    return "failed" & errormsg
    end if
    end repeat
    return "passed"
    end testcase1

    I want to be something like this.

    function Exetestcase
    set mytestcase = 1
    repeat forever
    get nextValue(partList)
    put line1 of imageexcel file into item 1 of testcaseimage
    put line1 of imagescreen file into item 2 of testcaseimage
    repeat with each item of testcaseimage
    if ["ComonShare" FindCurrentScreenAndPressButton: it] is false then
    LogError "Testcase" & mytestcase "is failed at " & it
    return "failed" & errormsg
    end if
    end repeat
    return "passed"
    add 1 to mytestcase
    end repeat
    if it is empty then
    exit repeat
    end repeat

    Then the image excel file would be like:

    image1;image2;image3;image4
    image2;image4;image6;image7
    .
    .
    .

    The screen excel file would be like
    screen1, screen2, screen3, screen4
    screen1, screen3, screen6, screen8
    screen10, screen12, screen3, screen14
    .
    .
    .
    .

    The combine of line 1 of image file and line1 of screen excel file will constitute testcase1.

    The combine of line 2 of image file and line2 of screen excel file will constitute testcase2.
    And so on.....

    If you could put both image and screen into 1 file and access line by line, that would be great.
    I want to implement this way because when I generate testcase I just working on excel file without touch the source code.

    Thanks so much for your greatful help.

    Best Regards,
  • Just a suggestion.. Why don't you use .csv files?

    You can edit those just fine in excel and also read them like text files in Eggplant.
  • csv is OK to me but I don't know to read and reference it.

    Best Regards,
  • EggplantMattEggplantMatt ForumAdmin admin
    Hi, Buffalo:

    There are instructions for accessing values directly from an Excel spreadsheet here: http://www.redstonesoftware.com/phpbb2/viewtopic.php?t=151 .

    There is also a writeup on data-driven testing with an example of how to read from a text file on page 31 of the Using Eggplant guide.

    If you still have questions after looking at those resources, please let me know.

    Regards,
    Matt
  • Matt,

    There are 2 issues with my script below. Please help me. This is urgent. I need to make this work by the end of this week. Thanks so much for your help.

    1. Is there any way that I pass the first item of the row into different variable?
    2. Unable to access a list value from excel.

    ===============
    imageexcel.xls
    testcase1   screenimage1, buttonimage1      screenimage2, buttonimage2    screenimage1, buttonimage2
    
    testcase2   screenimage1, buttonimage1      screenimage2, buttonimage2    screenimage1, buttonimage2
    
    getimages.script
    do AppleScript {{ 
    tell application "Microsoft Excel" 
    open "Document:imageexcel.xls" 
    
    set theRange to value of the usedRange of worksheet 1 
    set newData to {} 
    repeat with aRow from 1 to count of theRange 
    	set newRow to {} 
                    put item 1 of aCell into mytestcase
    	repeat with aCell from 1 to count of item 1 of theRange 
                            //get the first item from cell2 
                            put item1 of aCell1 into myscreenimage
                            put item2 of aCell2 into mybuttonimage
                            put myscreenimage & " " & "and" & " " mybuttonimage
    	end repeat 
    end repeat 
    get newData 
    end tell 
    }}
    
  • EggplantMattEggplantMatt ForumAdmin admin
    edited June 2005
    Buffalo:

    It looks like you've got a bunch of SenseTalk code in your Applescript block -- that won't work; the Applescript has to be just Applescript. You use the Applescript to extract all the data from the spreadsheet at once and put it into a SenseTalk variable and then you parse it. It will look something like this:
    do AppleScript {{ 
    tell application "Microsoft Excel" 
    open "G5:Users:Matt:Documents:tempfiles:imageexcel.xls" 
    get value of the usedRange of worksheet 1
    end tell
    }}
    put the result into myData
    
    repeat with aRow = each item of myData
    	put item 1 of aRow into mytestcase 
    	put item 1 of item 2 of aRow into myscreenimage 
    	put item 2 of item 3 of aRow into mybuttonimage 
    	put myscreenimage && "and" && mybuttonimage 
    end repeat 
    
    I've created the Excel file locally and run this code to verify that it works. Here's the output:
    Wed, 6/8/05 11:35:42 AM	START		Running Selection from /Users/matt/Documents/Eggplant Suites/Auxiliary.suite/Scripts/test.script
    screenimage1 and  buttonimage2
    screenimage1 and  buttonimage2
    Selection Executed in 0:00:00
    
    Let me know if you still have trouble getting this to work.
  • Thanks so much for your quick replied, Matt. I'll try and let you know if there is any problem.

    Best Regards,
Sign In or Register to comment.