Forum Discussion

william_roe's avatar
william_roe
Super Contributor
9 years ago

Unable to Focus the Control

Are others out there experiencing random 'Unable to Focus the Control' errors? We've been experiencing them for some time now. A support ticket was entered in March and an unrelated patch seemed to fix the problem. However I now think closing and re-opening TestComplete was the actual fix.It seems to happen when using the 'Keys' operation on a field but does not happen everytime. The 'Keys' method is suppose to set the focus. The strange thing is the test can be re-started and the error doesn't happen. Various variations of wait (WaitChild, WaitAliasChild, WaitProperty, etc) are used to ensure controls are loaded throughout all of our tests.

 

Here's the code for this morning's failure (converted to script from keyword test):

 

function AddItemLimits()
{
  KeywordTests.OpenItemLimitsPage.Run();
  Aliases.browser.CribMaster.sectionPrimarycontent.CraftCode.sectionActionwrapper.sectionActioncontent.formMainform.panelPnlitemcraftcode.panelFullscreenShow.article.panelHalf.WaitAliasChild("CraftCode_e", 5000);
  Aliases.browser.CribMaster.sectionPrimarycontent.CraftCode.sectionActionwrapper.sectionActioncontent.formMainform.panelPnlitemcraftcode.panelFullscreenShow.article.panelHalf.CraftCode_e.Keys("0"); <=== FAILING HERE
  Aliases.browser.CribMaster.sectionPrimarycontent.CraftCode.sectionActionwrapper.sectionActioncontent.formMainform.panelPnlitemcraftcode.panelFullscreenShow.article.panelHalf.panel.panelFullscreen.header.tableEmployeefilterRb1.All.Click();
  KeywordTests.LogNotificationException.Run("Error adding Item Limits");
  KeywordTests.RemovePage.Run();

 

I re-ran the entire test suite a second time this morning which includes this code and it didnt' fail.

 

Any ideas? We've been using TC for more than a year and getting quite frustrated by the inconsistency with which tests run. I would estimate the success rate of running our test suite (5,000+ screen interactions) is less than 20%.

 

Firefox 39.0

TC 10.6.3387 (tcFFHook.xml dated 7/6/2015)

2 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi William,

     

    Unfortunately, I am afraid that I will disappoint you... as personally I was getting the mentioned error when the control was really not able to get the focus. The reason could be that either control was absent, or was not internally completely initialized and thus did not respond to the messages sent to it in the expected way, or for some other reason.

    In my code I used to use <control>.SetFocus to explicitly set focus to the control when this is needed. Actually, I even used to something like this:

    <window>.Activate

    <control>.SetFocus

    The first statement explicitly activates the window the test code will work with and this helps to prevent false negatives if some unexpected error/warning message is displayed. (OnUnexpectedWindow event will be triggered and at least the message along with the screenshot will be posted to the log.)

    The second statement explicitly sets the focus the the target control and sometimes this helps if the control does something in the background when getting focus (e.g. options list is filled with data for some customized combobox).

     

    > The 'Keys' method is suppose to set the focus.

    To say the truth, I am not sure that this is done explicitly by TestComplete. It is my understanding that .Keys just sends a corresponding event to the target control. And then it is either OS or the tested application that will or will not set the focus to this or that control. As an example, consider this sample string for .Keys: "1[Tab]2" - in most cases it will enter '1' into the currently active control, then move to another control and enter '2' to this another control. I am really doubting that TestComplete within .Keys() call somehow controls what control must be focused when the press of the Tab key is emulated. This is, basically, the reason for my current understanding.

     

    Not sure if all the above helps somehow, but anyway... :)

     

    P.S.

    > "Donald Trump Supports TestComplete".

    I can't but welcome this his decision! Great job and strong move of SmartBear's management that we all will definitely benefit from.

    ;)

     

  • william_roe's avatar
    william_roe
    Super Contributor

    Either I need a more sensational subject or nobody else is experiencing this. How about "Donald Trump Supports TestComplete".