GDATASoftwareAG / robotframework-flaui

Windows user interface automation library for Robot-Framework. FlaUILibrary is a wrapper for the FlaUI automation library.
MIT License
61 stars 12 forks source link

System.AccessViolationException: Attempted to read or write protected memory on scrolling #218

Open SamGeens opened 2 days ago

SamGeens commented 2 days ago

Background: We are trying to automate a testcase via robot framework via FlaUI library. We have a custom made GUI to control. Before, we were using TestStackWhite and with that library we were able to scroll up/down in the list and find the "element"/"row" we wanted to interact with.

Issue: After solving the previous issue. We ran into a new issue. The following error is thrown at random times during our scroll process:

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AccessViolationException: Attempted to read or write protected memory. This is of
ten an indication that other memory is corrupt.
   at Interop.UIAutomationClient.IUIAutomationTreeWalker.GetNextSiblingElement(IUIAutomationElement element)
   at FlaUI.UIA3.UIA3TreeWalker.GetNextSibling(AutomationElement element)
   at FlaUI.Core.AutomationElementXPathNavigator.MoveToNext()
   at MS.Internal.Xml.XPath.XPathDescendantIterator.MoveNext()
   at MS.Internal.Xml.XPath.DescendantQuery.Advance()
   at MS.Internal.Xml.XPath.FilterQuery.Advance()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.GetNextInput()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.DecideNextNode()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.Advance()
   at MS.Internal.Xml.XPath.FilterQuery.Advance()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.GetNextInput()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.Advance()
   at MS.Internal.Xml.XPath.FilterQuery.Advance()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.GetNextInput()
   at MS.Internal.Xml.XPath.CacheChildrenQuery.Advance()
   at MS.Internal.Xml.XPath.FilterQuery.Advance()
   at MS.Internal.Xml.XPath.XPathSelectionIterator.MoveNext()
   at System.Xml.XPath.XPathNavigator.SelectSingleNode(XPathExpression expression)
   at System.Xml.XPath.XPathNavigator.SelectSingleNode(String xpath)
   at FlaUI.Core.AutomationElements.AutomationElement.FindFirstByXPath(String xPath)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Python.Runtime.MethodBinder.Invoke(BorrowedReference inst, BorrowedReference args, BorrowedReference kw, MethodBase info, MethodBase[] methodinfo)
   at Python.Runtime.MethodObject.Invoke(BorrowedReference target, BorrowedReference args, BorrowedReference kw, MethodBase info)
   at Python.Runtime.MethodBinding.tp_call(BorrowedReference ob, BorrowedReference args, BorrowedReference kw)

The code we are executing is the following:

${total_rows_in_list}  UUT.get grid rows Count  ${item_list}

log to console  Checking the item list to find..

# Less attempts needed than rows in list. Each scroll is 3 list items and we scroll 5 times at once.

# Added 10 more scrolls for safe margin.
${scroll_attempts} =   Evaluate    ${total_rows_in_list} / 15 + 10

FOR    ${i}    IN RANGE    ${total_rows_in_list}
    ${item_found}  Set variable  False
    UUT.Scroll down   ${item_list}  1
    UUT.Scroll down   ${item_list}  1
    UUT.Scroll down   ${item_list}  1
    UUT.Scroll down   ${item_list}  1
    UUT.Scroll down   ${item_list}  1

    Suspend For  2 s
    # Check if item is in current list view
    ${needed_procedure_is_present}  ${msg}  run keyword and ignore error  UUT.Is element offscreen  ${demo_procedure}

    IF  '${needed_item_is_present}' == 'PASS'
        log to console  Item NR has been found!
        # Scroll down one more time because it might be not "visible"
        UUT.Scroll down   ${item_list}  1
        Sleep  2s
        log to console  Clicking on the item...
        UUT.Click  ${demo_item}

        Set variable  ${item_found}  True
        Exit For Loop
    END
END

Do you have any idea/indication on how to prevent the memory issue. Our implementation is currently unstable because of this.

Nepitwin commented 1 day ago

Hi @SamGeens ,

which kind of element are you trying to scroll down and language?

Maybe i can reproduce this part afterwards to identify why an Access Violation will be thrown.

SamGeens commented 1 day ago

Hi @Nepitwin,

The application without sensitive data looks like this: image

The scroll list is a data grid: image

noubar commented 22 hours ago

@SamGeens

Please try the following and update us with the results, If the error is the same or you are getting another error or it fixes it

UUT.Scroll down ${item_list} 1 if_focus=${Flase}

What you have not yet answered is this a c# project with WPF or is it windows Form or something else?