SAP Crashed whenever the script execution is completed
Posted: 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
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