SAP Crashed whenever the script execution is completed

Class library usage, coding and language questions.
nivasd16
Posts: 14
Joined: Fri Jan 22, 2016 11:17 pm

SAP Crashed whenever the script execution is completed

Post by nivasd16 » Wed Sep 28, 2016 11:48 pm

Hi Team
I used the below code to login to SAP... once the SAP login is successful and the script is execution done then the SAP is closing out immediately
Below is the code is used
Code in the Class file
using System;
using System.Collections.Generic;
using System.Collections;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Repository;
//using Ranorex.Plugin.SapTypes;
using System.Collections.Generic;

using SAPFEWSELib;
using System.Data.Linq;

using SampleTest.Repository;


namespace SampleTest.Framework
{
/// <summary>
/// Description of Class1.
/// </summary>
public class SAPLogin
{
public static GuiApplication Sapguiapp { get; set;}
public static GuiConnection SapConnection { get; set;}
public static GuiSession SapSession { get; set;}

public static void LaunchSap()
{
SAPLogin.Sapguiapp=new GuiApplication();
System.Activator.CreateInstance(Type.GetTypeFromProgID("SapGui.ScriptingCtrl.1"));
SAPLogin.SapConnection=SAPLogin.Sapguiapp.OpenConnectionByConnectionString("/SAP_CODEPAGE=1100 /FULLMENU /M/sap-et1ci.qat.np.costco.com/S/3600/G/public /UPDOWNLOAD_CP=2",Sync: true);
SAPLogin.SapSession=(GuiSession)SAPLogin.SapConnection.Sessions.Item(0);
}

public static void SAP_Login(string myclient,string mylogin,string mypass,string mylang)
{
GuiTextField strclient = (GuiTextField)SAPLogin.SapSession.ActiveWindow.FindByName("RSYST-MANDT", "GuiTextField");
GuiTextField strlogin = (GuiTextField)SAPLogin.SapSession.ActiveWindow.FindByName("RSYST-BNAME", "GuiTextField");
GuiTextField strpass = (GuiTextField)SAPLogin.SapSession.ActiveWindow.FindByName("RSYST-BCODE", "GuiPasswordField");
GuiTextField strlanguage = (GuiTextField)SAPLogin.SapSession.ActiveWindow.FindByName("RSYST-LANGU", "GuiTextField");

strclient.SetFocus();
strclient.Text = myclient;
strlogin.SetFocus();
strlogin.Text = mylogin;
strpass.SetFocus();
strpass.Text = mypass;
strlanguage.SetFocus();
strlanguage.Text = mylang;

//Press the green checkmark button which is about the same as the enter key
GuiButton btn = (GuiButton)SapSession.FindById("/app/con[0]/ses[0]/wnd[0]/tbar[0]/btn[0]");
btn.SetFocus();
btn.Press();
}
}
}

Code in the main component
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
using SampleTest.Framework;
using Ranorex.Plugin.SapTypes;
using SampleTest.Repository;



namespace SampleTest.Modules
{
/// <summary>
/// Description of UserCodeModule1.
/// </summary>
[TestModule("C8F86E3E-857E-4665-90D5-310D40EEE68C", ModuleType.UserCode, 1)]
public class SAPSample : ITestModule
{
/// <summary>
/// Constructs a new instance.
/// </summary>
public SAPSample()
{
// Do not delete - a parameterless constructor is required!
}
public static SAPRepo Repo1 = SAPRepo.Instance;
/// <summary>
/// Performs the playback of actions in this module.
/// </summary>
/// <remarks>You should not call this method directly, instead pass the module
/// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
/// that will in turn invoke this method.</remarks>
void ITestModule.Run()
{
Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;

// SAPActive.SapSession.StartTransaction("VA03");
SAPLogin.LaunchSap();
SAPLogin.SAP_Login("210","Testing_38","welcome1","");
//Tcode.tcode_Launch("S_PH0_48000510");
Repo1.SAPEasyAccess1.Text1001.PressKeys("S_PH0_48000510");

}
}
the script is executing sucessfully till the last step once last step is the execution ends SAPSesiion is closin out automatically

jma
Posts: 107
Joined: Fri Jul 03, 2015 9:18 am

Re: SAP Crashed whenever the script execution is completed

Post by jma » Fri Sep 30, 2016 1:59 pm

The issue doesn't seem to be related to Ranorex directly. As far as I can tell you use a third party library (SAPFEWSELib.dll) to interact with the SAP application. I don't have any experience with this dll, but is it really necessary to use this library? I would suggest checking some log files of the SAP application in order to figure out the cause of the application crash.

Ranorex provides a SAP plugin which allows you to automate the UI of the SAP application. It should be sufficient to automate the application with this plugin. More information can be found on the Ranorex web page: http://www.ranorex.com/support/user-gui ... tions.html