Is Appium supported with MS Server 2022 - appium

We are trying to get Appium to run in a MS Server 2022 environment using the published calculator program. When it is run on a win-10 PC the application runs fine - it spawns the application and the script can control the calculator's keys.
When it is run on the 2022 server, the calculator.exe spawns but there is no control of the application keys.
There are some differences in the application/environment. In the "published" calc environment the app is addressed like this:
capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
This was not recognized by the system so we went for the direct path:
capabilities.setCapability("app", "C:\Windows\System32\calc.exe");
Many of the other addressable features of the calculator program showed different values for their addressable IDs.
Bottom line is that there are lots of differences between the systems, has anyone gotten MSserver 2022 and Appium to work?
`public class CalculatorTest {
private static WindowsDriver<WebElement> CalculatorSession = null;
private static WebElement CalculatorResult = null;
#BeforeClass
public static void setup() {
try {
DesiredCapabilities capabilities = new DesiredCapabilities();
//capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
capabilities.setCapability("app", "C:/Windows/System32/calc.exe");
CalculatorSession = new WindowsDriver<WebElement>(new URL("http://127.0.0.1:4727/"), capabilities);
CalculatorSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
CalculatorResult = CalculatorSession.findElementByAccessibilityId("CalculatorResults");
Assert.assertNotNull(CalculatorResult);
}catch(Exception e){
e.printStackTrace();
} finally {
}
}
`
org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: Failed to locate opened application window with appId: C:/Windows/System32/calc.exe, and processId: 29876.
The output of the power shell:Get-StartApps command for calculator.
MSServer 2022:
Calculator         {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\win32calc.exe
Windows 10:
Calculator Microsoft.WindowsCalculator_8wekyb3d8bbwe!App

Related

.net core console application using TopShelf

I have created a .net core console application using TopShelf. But I got an error when running the application using docker (alpine-linux).
Configuration Result:
[Success] Name MyApp
[Success] DisplayName MyApp
[Success] Description My Application
[Success] ServiceName MyApp
Topshelf v4.1.0.177, .NET Framework v4.0.30319.42000
Topshelf.Runtime.Windows.WindowsHostEnvironment Error: 0 : Unable to get parent process (ignored), System.DllNotFoundException: Unable to load shared library 'kernel32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Error loading shared library libkernel32.dll: No such file or directory
at Topshelf.Runtime.Windows.Kernel32.CreateToolhelp32Snapshot(UInt32 dwFlags, UInt32 th32ProcessID)
at Topshelf.Runtime.Windows.WindowsHostEnvironment.GetParent(Process child)
Topshelf.HostFactory Error: 0 : The service terminated abnormally, System.PlatformNotSupportedException: ServiceController enables manipulating and accessing Windows services and it is not applicable for other operating systems.
at System.ServiceProcess.ServiceController.GetServices()
at Topshelf.Runtime.Windows.WindowsHostEnvironment.IsServiceListed(String serviceName)
at Topshelf.Hosts.ConsoleRunHost.Run()
at Topshelf.HostFactory.Run(Action`1 configureCallback)
How to solve this issue? I need to run my console application as a windows service
The Topshelf documentation is pretty specific:
To work with Topshelf you will need to be running on a Windows operating system. The developers of Topshelf regulary test on Windows 7 and Windows Server 2008RC2. Though it should still work on Windows Server 2003, as long as .Net 3.5 sp1 is installed.
The good news is that writing Linux daemons is easier than Windows Services - all they have to be is basically a console application where you control the main loop.
If I got your problem statement correctly, you want to be able to run one service both in Windows and in Docker. In this case it seems the easiest way will be to examine your OS environment on start up with something like System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform()
and either defer your main work to Topshelf or run it Linux-style. For the example below I installed Microsoft.Extensions.Hosting package and opted for implementing an IHostedService (which Topshelf can conveniently reuse)
public class YourHostedService : IHostedService, IDisposable
{
private int executionCount = 0;
private Timer _timer;
public YourHostedService()
{
}
public Task StartAsync(CancellationToken stoppingToken)
{
_timer = new Timer(DoWork, null, TimeSpan.Zero,
TimeSpan.FromSeconds(5));
return Task.CompletedTask;
}
private void DoWork(object state)
{
executionCount++;// this gets called every 5 seconds
}
public Task StopAsync(CancellationToken stoppingToken)
{
_timer?.Change(Timeout.Infinite, 0);
return Task.CompletedTask;
}
public void Dispose() => _timer?.Dispose();
}
public class Program
{
public static async Task Main(string[] args)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var rc = HostFactory.Run(x =>
{
var token = CancellationToken.None;
x.Service<YourHostedService>(s =>
{
s.ConstructUsing(name => new YourHostedService());
s.WhenStarted(tc => tc.StartAsync(token));
s.WhenStopped(tc => tc.StopAsync(token));
});
x.RunAsLocalSystem();
x.SetDescription("TopShelf Host");
x.SetDisplayName("YourHostedService");
x.SetServiceName("YourHostedService");
});
}
else
{
await Host.CreateDefaultBuilder(args)
.ConfigureServices(builder =>
{
builder.AddHostedService<YourHostedService>();
})
.RunConsoleAsync();
}
}
}
More inspiration can be drawn from here.
UPD So it seems your particular case can also be solved by running arbitrary (well, in this case your) program as Windows service.
In this case you've got some options that don't involve programming but rather config writing:
The Microsoft's own tool SrvAny that's been part of NT Resource Kit: you basically install it as a dummy service and edit the registry setting to point to your .exe
A 3rd party tool SrvStart: this one's relatively easy to pick up as well, and config is similar to the above
So your requirement is to run a dotnet core (which version?) application as a windows service.
TopShelf might not be the right tool for this, as it supports .NET Framework 4.0 or Mono, not dotnet core.
Since you want to run a windows service, it does not make any sense to publish your app as a Linux Docker image! Use sc create and sc start to register and start your published executable instead.
Topshelf is not a good choice for .NET Core because .Net Core has powerful facilities for build Windows Service. Furthermore, TopShelf is only supporting Windows.
See Examples:
https://medium.com/#tocalai/create-windows-service-using-net-core-console-application-dc2f278bbe42
https://codeburst.io/create-a-windows-service-app-in-net-core-3-0-5ecb29fb5ad0

GraalVM: Access to native code is not allowed by the host environment

I just recently setup a Centos7 VM to play around with GraalVM. I downloaded graalvm-1.0.0-rc1, installed Netbeans8.2, and downloaded the FastR extension (via gu). I then wrote a simple java program to test some of the various supported languages. Below is the code I wrote:
package javatest;
import org.graalvm.polyglot.*;
import java.io.PrintStream;
import java.util.Set;
public class JavaTest {
public static void main(String[] args) {
PrintStream output = System.out;
Context context = Context.create();
Set<String> languages = context.getEngine().getLanguages().keySet();
output.println("Current Languages available in GraalVM: " + languages);
// TODO code application logic here
System.out.println("Java: Hello World");
context.eval("js","print('JavaScript: Hello World')");
context.eval("R", "print('R: Hello World');");
}
}
Output is as follows:
run:
Current Languages available in GraalVM: [R, js, llvm]
Java: Hello World
JavaScript: Hello World
FastR unexpected failure: error loading libR from: /usr/local/graalvm-1.0.0-
rc1/jre/languages/R/lib/libR.so.
If running on NFI backend, did you provide location of libtrufflenfi.so as
value of system property 'truffle.nfi.library'?
The current value is '/usr/local/graalvm-1.0.0-
rc1/jre/lib/amd64/libtrufflenfi.so'.
Details: Access to native code is not allowed by the host environment.
Exception in thread "main" org.graalvm.polyglot.PolyglotException
at org.graalvm.polyglot.Context.eval(Context.java:336)
at javatest.JavaTest.main(JavaTest.java:32)
As you can see by the initial call to view the supported languages it recognizes that R is installed but once I call the eval on the language it kicks out. The trufflenfi.so file is there and available. I have defined it as a run parameter (even though I shouldn't need to).
I can find nothing on why the "access to native code is not allowed by the host environment" is being displayed and am at a loss. Any ideas on what I'm doing wrong? Note: I also tried the same test with python and ruby and got the same result but removed for the simplest of test cases.
This is a security feature of polyglot contexts created with the GraalVM polyglot API. By default every language is isolated from the host environment, therefore it is not allowed to acccess Java classes, native access or files in your filesystem. Currently with GraalVM 1.0.0-RC1 the languages Ruby and R need native access to boot their environment up. The languages JavaScript and Python don't need native access to boot.
If you want to create a context with all access you can create the context like this:
Context.newBuilder().allowAllAccess(true).build();
You can also just selectively allow access to native code:
Context.newBuilder().allowNativeAccess(true).build();
Here is your example fixed:
package javatest;
import org.graalvm.polyglot.*;
import java.io.PrintStream;
import java.util.Set;
public class JavaTest {
public static void main(String[] args) {
PrintStream output = System.out;
Context context = Context.newBuilder().allowAllAccess(true).build();
Set<String> languages = context.getEngine().getLanguages().keySet();
output.println("Current Languages available in GraalVM: " + languages);
// TODO code application logic here
System.out.println("Java: Hello World");
context.eval("js","print('JavaScript: Hello World')");
context.eval("R", "print('R: Hello World');");
}
}
Here are some more examples that uses all access for Ruby and R:
http://www.graalvm.org/docs/graalvm-as-a-platform/embed/

Printing a PDF from a Windows Service using GhostScript - How to diagnose permission issue

I have a service written in C#. Running the following code:
public static bool PrintPDF(string ghostScriptPath, int numberOfCopies, string printerName, string pdfFileName)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = $#"-dPrinted -dNoCancel=true -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies={numberOfCopies} -sDEVICE=mswinpr2 -sOutputFile=""\\spool\{printerName}"" ""{pdfFileName}""";
startInfo.FileName = Path.Combine(ghostScriptPath, "gswin64c.exe");
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
Process process = Process.Start(startInfo);
Console.WriteLine(process.StandardError.ReadToEnd() + process.StandardOutput.ReadToEnd());
process.WaitForExit(30000);
if (process.HasExited == false) process.Kill();
return process.ExitCode == 0;
}
Outside of Windows Service, it's working without any problem.
Inside the service, when running as Local System, GhostScript started running but timed out without any output.
After some fiddling around, I finally switched the service to run as Network Service and also set Network Service as owner of the folder from which the service exe and GhostScript exe where placed (Before I did that, I got Access Denied error) - And now the service is running fine.
My questions is - How come Network Service can work where Local System can't? I thought Local System has more privileges. And also, how can I get more info regarding the actual issue? I've found a workaround but it was simply a lucky shot in the dark. I have no idea what the real problem is.
Some more info:
Running Windows 10 64 bit, and using GhostScript v9.29
You need to run the service under a local user account that is dedicated to it.
You also need to login with that user at list one time in order the printer list to be populated!

Can I sign .hlkx file manually using EV certificate to submit on the Microsoft website

I have completed all the tests with my usb device in Hardware Lab Kit and now can prepare the .hlkx driver package to submit on the Microsoft website.
The problem is EV certificate is required for Windows 10 driver. EV certificate is provided with Safenet USB token and this USB token is located far away from computer with Hardware Lab Kit installed, so I can't sign .hlkx package in Hardware Lab Kit automatically.
The question is how can I get my Windows 10 usb drivers signed? I have the unsigned driver (sys, cab, inf ... files) and I have unsigned .hlkx driver package from Hardware Lab Kit. Can I sign my driver without submitting to the Microsoft website?
You can
Install HLK Studio to the computer where EV token is plugged in;
Copy unsigned .hlkx file to the computer with EV token;
When you will launch HLK Studio from pt1, it will promt to open .hlkx file, specify it;
On Package tab of HLK Studio do Create Package as usual.
Answer provided by Alexey didn't work for me, I eventually used the source code from this page:
https://msdn.microsoft.com/en-us/library/windows/hardware/mt674914%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
I had to do some additional tweaking:
Before using this, make sure the EV certificate is in your personal certificate store. Within the tool you have for your USB token you should be able to open the certificate and choose to “Install certificate”.
Create a new console application in visual studio and paste this source code in.
Install the nugget package “WindowsBase” to get System.IO.Packaging namespace.
With some additional source code, we can have this working:
class Program
{
static void Main(string[] args)
{
X509Store store = new X509Store("My");
store.Open(OpenFlags.ReadOnly);
X509Certificate2 evCert = null;
foreach (X509Certificate2 mCert in store.Certificates)
{
if (mCert.Thumbprint == "3DF652D7EyourThumbprintF")
{
evCert = mCert;
}
}
Sign(#"C:\Path\To\Your\HLKXFile.hlkx", evCert);
}
public static void Sign(string package, X509Certificate2 certificate)
{
// Open the package to sign it
Package packageToSign = Package.Open(package);
// Specify that the digital signature should exist
// embedded in the signature part
PackageDigitalSignatureManager signatureManager = new PackageDigitalSignatureManager(packageToSign);
signatureManager.CertificateOption = CertificateEmbeddingOption.InCertificatePart;
// We want to sign every part in the package
List<Uri> partsToSign = new List<Uri>();
foreach (PackagePart part in packageToSign.GetParts())
{
partsToSign.Add(part.Uri);
}
// We will sign every relationship by type
// This will mean the signature is invalidated if *anything* is modified in //the package post-signing
List<PackageRelationshipSelector> relationshipSelectors = new List<PackageRelationshipSelector>();
foreach (PackageRelationship relationship in packageToSign.GetRelationships())
{
relationshipSelectors.Add(new PackageRelationshipSelector(relationship.SourceUri, PackageRelationshipSelectorType.Type, relationship.RelationshipType));
}
try
{
signatureManager.Sign(partsToSign, certificate, relationshipSelectors);
}
finally
{
packageToSign.Close();
}
}
}
Replace the Thumbprint with your EV certificate SHA1.

Firefox Driver hangs on creation when using Jenkins node

I have just installed the Selenium Grid plugin for Jenkins and beginning to explore distributing tests with it. I have created a simple test that just opens a browser, gets a url, and then closes the browser. This seems to work for Chrome (on Mac) and IE (on Windows) but for some reason when using Firefox 18.0.2 on Mac, I see the browser window open but the url I'm supposed to load never shows up in the url bar and things hang and I get an error:
WebDriverException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
It is hanging somewhere in the constructor to create the RemoteDriver. I added a trace statement right after the constructor and the code never gets there.
The weird thing is the test executes just fine if I start up a local Selenium Grid node on the same machine that fails and direct my tests there instead of the Jenkins Selenium Grid hub. So it seems to potentially be an issue with how I set up the Jenkins node but I can't figure out how to troubleshoot this. Any help would be appreciated.
My code is something like this:
WebDriver driver = null;
public Browser(String gridUrl) {
driver = makeFirefox(gridUrl);
driver.get(url);
}
private WebDriver makeFirefox(String gridUrl) {
FirefoxProfile prof = new FirefoxProfile();
prof.setEnableNativeEvents(true);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, prof);
WebDriver driver = null;
try{
driver = new RemoteWebDriver(new URL(gridUrl), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return driver;
}
For anyone who runs into this, I was able to at least temporarily "solve" the problem by downgrading to Firefox 17. Things work fine there, just not Firefox 18.

Resources