How to Control Native Android Apps with ABAP
Business processes are no longer only implemented in the SAP GUI for Windows. More and more measures are being taken on other UIs on other devices. In this blog post, I described how to use ABAP through PowerShell to control the possibility of native applications and web applications on a virtual Android device.
To achieve this scenario, we use the methods described in article and this article The bridge between the SAP system and the virtual device builds a series of libraries and applications. It starts from SAPIEN's ActiveXPoshV3 library and is used to connect to PowerShell from SAP. The PowerShell script containing the process is stored on the SAP back-end system as a containing development object. ABAP reports to load this script and execute it. The script uses the Appium client library to connect to the Appium server, which connects to the virtual device from Android Studio.
Here is a PowerShell script to control the Android calculator application. Store it for inclusion in your SAP system. It loads the client library, sets the necessary functions, such as device name, application, etc., and executes some activities. It adds 6 to 9, multiplies 166 by 9 and writes the result to the screen.
#-Begin-----------------------------------------------------------------
#-Includes------------------------------------------------------------
$Path = "C:\Program Files\Appium"
[Void][System.Reflection.Assembly]::LoadFrom($Path + "\appium-dotnet-driver.dll")
[Void][System.Reflection.Assembly]::LoadFrom($Path + "\Castle.Core.dll")
[Void][System.Reflection.Assembly]::LoadFrom($Path + "\Newtonsoft.Json.dll")
[Void][System.Reflection.Assembly]::LoadFrom($Path + "\WebDriver.dll")
[Void][System.Reflection.Assembly]::LoadFrom($Path + "\WebDriver.Support.dll")
#-Sub Main------------------------------------------------------------
Function Main() {
[OpenQA.Selenium.Remote.DesiredCapabilities]$Capabilities = `
[OpenQA.Selenium.Remote.DesiredCapabilities]::new();
$Capabilities.SetCapability([OpenQA.Selenium.Appium.Enums.MobileCapabilityType]::`
DeviceName, "emulator-5554");
$Capabilities.SetCapability([OpenQA.Selenium.Appium.Enums.MobileCapabilityType]::`
PlatformVersion, "8.1.0");
$Capabilities.SetCapability([OpenQA.Selenium.Appium.Enums.MobileCapabilityType]::`
PlatformName, "Android");
$Capabilities.SetCapability([OpenQA.Selenium.Appium.Enums.AndroidMobileCapabilityType]::`
AppPackage, "com.android.calculator2");
$Capabilities.SetCapability([OpenQA.Selenium.Appium.Enums.AndroidMobileCapabilityType]::`
AppActivity, "com.android.calculator2.Calculator");
[System.Uri]$Uri = [System.Uri]::new("http://127.0.0.1:4723/wd/hub");
$Driver = `
[OpenQA.Selenium.Appium.Android.AndroidDriver[OpenQA.Selenium.Appium.AppiumWebElement]]::`
new($Uri, $Capabilities);
If ($Driver -eq $null) {
Return;
}
$Driver.FindElementById("com.android.calculator2:id/digit_9").Click();
$Driver.FindElementById("com.android.calculator2:id/op_add").Click();
$Driver.FindElementById("com.android.calculator2:id/digit_6").Click();
$Driver.FindElementById("com.android.calculator2:id/eq").Click();
$Result = $Driver.FindElementById("com.android.calculator2:id/result").Text;
Write-Host "Das Ergebnis ist " $Result;
$Driver.FindElementByAccessibilityId("clear").Click();
$Driver.FindElementById("com.android.calculator2:id/digit_1").Click();
$Driver.FindElementById("com.android.calculator2:id/digit_6").Click();
$Driver.FindElementById("com.android.calculator2:id/digit_6").Click();
$Driver.FindElementByAccessibilityId("multiply").Click();
$Driver.FindElementById("com.android.calculator2:id/digit_9").Click();
$Driver.FindElementByAccessibilityId("equals").Click();
$Result = $Driver.FindElementById("com.android.calculator2:id/result").Text;
Write-Host "Das Ergebnis ist " $Result;
$Driver.CloseApp();
$Driver.Quit();
}
#-Main----------------------------------------------------------------
Main
#-End-------------------------------------------------------------------
Here is a script to control the Chrome browser on Android. Store it for inclusion in your SAP system. Its function is the same as the script above, but here we control the browser. We call Google search, enter the word Selenium in the field, and press Enter.
#-Begin-----------------------------------------------------------------
#-Includes------------------------------------------------------------
$Path = "C:\Program Files\Appium"
[Void][System.Reflection.Assembly]::LoadFrom($Path + "\appium-dotnet-driver.dll")
[Void][System.Reflection.Assembly]::LoadFrom($Path + "\Castle.Core.dll")
[Void][System.Reflection.Assembly]::LoadFrom($Path + "\Newtonsoft.Json.dll")
[Void][System.Reflection.Assembly]::LoadFrom($Path + "\WebDriver.dll")
[Void][System.Reflection.Assembly]::LoadFrom($Path + "\WebDriver.Support.dll")
#-Sub Main------------------------------------------------------------
Function Main() {
[OpenQA.Selenium.Remote.DesiredCapabilities]$Capabilities = `
[OpenQA.Selenium.Remote.DesiredCapabilities]::new();
$Capabilities.SetCapability("deviceName", "emulator-5554");
$Capabilities.SetCapability("platformVersion", "8.1.0");
$Capabilities.SetCapability("browserName", "Chrome")
$Capabilities.SetCapability("platformName", "Android");
[System.Uri]$Uri = [System.Uri]::new("http://127.0.0.1:4723/wd/hub");
$Driver = `
[OpenQA.Selenium.Appium.Android.AndroidDriver[OpenQA.Selenium.Appium.AppiumWebElement]]::`
new($Uri, $Capabilities);
If ($Driver -eq $null) {
Return;
}
$Driver.Navigate().GoToUrl("https://www.google.de");
$Driver.FindElementByName("q").SendKeys("Selenium");
$Driver.FindElementByName("q").SendKeys([OpenQA.Selenium.Keys]::Enter);
Start-Sleep -Seconds 5
$Driver.CloseApp();
$Driver.Quit();
}
#-Main----------------------------------------------------------------
Main
#-End-------------------------------------------------------------------
ABAP Code Preparation and Execution
To execute these scripts using the following report, you need the zActiveXPoshV3 class here This report loads the first script containing z_posh_appium_app and executes it. But before starting Android Studio with a new empty project and virtual device. Then start your Appium server.
report source code:
"-Begin-----------------------------------------------------------------
REPORT Z_APPIUM.
DATA:
lo_posh TYPE REF TO zactivexposhv3,
lv_pscode TYPE string,
lv_result TYPE string,
lt_result TYPE STANDARD TABLE OF string
.
CREATE OBJECT lo_posh.
CHECK lo_posh->load_lib( ) = lo_posh->mc_true.
CHECK lo_posh->get_is_powershell_installed( ) = lo_posh->mc_true.
CHECK lo_posh->init( iv_load_profiles = lo_posh->mc_false ) = 0.
lo_posh->set_outputmode( lo_posh->mc_outputbuffer ).
lo_posh->set_outputwidth( 132 ).
lo_posh->clear_output( ).
lv_pscode = lo_posh->read_incl_as_string( iv_incl_name = 'Z_POSH_APPIUM_APP' ).
lo_posh->execute( lv_pscode ).
lv_result = lo_posh->get_outputstring( ).
lo_posh->clear_output( ).
lt_result = lo_posh->outputstring_to_table( iv_outputstring = lv_result ).
LOOP AT lt_result INTO lv_result.
WRITE: / lv_result.
ENDLOOP.
lo_posh->free_lib( ).
"-End-------------------------------------------------------------------
Results of the:
in conclusion
As you can see, Android devices can be controlled from SAP. You can synchronize through direct two-way communication between scripts and ABAP reports, function modules or methods. So you can use this method during testing, for example in the context of eCATT. This opens the door to very interesting integration scenarios.
More original articles by Jerry, all in: "Wang Zixi":
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。