Problems with Popup Objects

The main problem is that appearance of popup messages is not predictable and may happen at any point in the application.

This causes a real problem for automatic test execution. Ideal solution may be to find an application configuration option and to disable such popups at all. Unfortunately this this not always possible. In some cases there is no such a config option. In others we simply cannot switch popups off completely because some of them are required for test scenarios.

For example, well known application box.com is throwing unexpected new feature prompts up in unanticipated places on occasion, failing scripts when the prompt requires a response the script is not expecting:

Solution

Proposed solution to this problem is to check presence of the popup object just before doing any action.

Go to Functions (<test>.user.js) file and add the following code:

function OnBeforeObjectAction(/**SeSObject*/ obj, /**string*/ actionName, /**array*/ arguments)
{
    // TODO: check if any popups before accessing object action, for example:
    if( Global.DoWaitFor('popup_object_close', 300) )
    {
        // It is important to use _DoClick, because it works directly
        // without calling 'OnBeforeAction' recursively
        SeS('popup_object_close')._DoClick();
    }
    
    // Return 'false' to let other OnBeforeAction handlers to be called.
    return false;
}

g_sesOnBeforeActionExecutedImpl.push( OnBeforeObjectAction );

 

This snippet introduces an array of functions: g_sesOnBeforeActionExecutedImpl, each will be called before any DoSomethigaction in the script.

OnBeforeAction arguments

Input parameters to this function are:

  • obj - Resolved SeSObject. If object is not found then OnBeforeObjectAction is not executed at all.
  • actionName - Action with Do prefix. I.e. actionName='Click' for the DoClick.
  • arguments - array of action arguments.

Here is an example scenario where OnBeforeAction is used to trace all actions into a file:

function OnBeforeActionTrace(/**SeSObject*/ obj, /**string*/ actionName, /**array*/ arguments)
{
	var objName = obj.object_name||obj.object_id||obj.name||"\"\"";
	// Callback on after action executed
	var actionString = "Before calling "+objName+".Do"+actionName+"("+JSON.stringify(arguments)+")";
	
	File.Append('Trace.txt', actionString+"\r\n");
	
	// Return 'false' to let other OnBeforeAction handlers to be called.
	return false;
}

File.Write('Trace.txt', 'Test starts\r\n');

g_sesOnBeforeActionExecutedImpl.push( OnBeforeActionTrace );

Rapise uses similar method internally to trace screenshots. Check built in function function _SeSMakeScreenshotBeforeAction defined in %ENGINE%/SeSCommon.js for more reference.