Need to check how to use sikuli with Selenium in Docker - docker

I am using Selenium and Sikuli in Windows and Ubuntu in Java programing.
For example, I am giving other sample code.
package com.sikuli.demo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;
import org.openqa.selenium.chrome.ChromeDriver;
public class SikuliDemo {
public static void main(String[] args) throws FindFailed {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
String filepath = "D:\\Guru99Demo\\Files\\";
String inputFilePath = "D:\\Guru99Demo\\Files\\";
Screen s = new Screen();
Pattern fileInputTextBox = new Pattern(filepath + "FileTextBox.PNG");
Pattern openButton = new Pattern(filepath + "OpenButton.PNG");
WebDriver driver;
// Open Chrome browser
driver = new ChromeDriver();
driver.get("http://demo.guru99.com/test/image_upload/index.php");
// Click on Browse button and handle windows pop up using Sikuli
driver.findElement(By.xpath(".//*[#id='photoimg']")).click();
s.wait(fileInputTextBox, 20);
s.type(fileInputTextBox, inputFilePath + "Test.docx");
s.click(openButton);
// Close the browser
driver.close();
}
}
I need to execute code in Docker (installed Docker on Ubuntu machine).
Using one docker file as of now.
docker pull selenium/standalone-chrome
If you can suggest how to integrated Sikuli in any docker image it will great. (like selenium-chrome base image..need to integrate Sikuli with the same)
Basically, i have created few keyword driven framework which is using Selenium and Sikuli. But, if I need to execute in docker. need to check how both selenium and sikuli work together.

Since you have tests running on Ubuntu you know how to install Sikuli.
Do same installation for the docker using dokerfile
Then make sure your docker has real UI - not headless. You need this since Sukuli is real UI automation tool and needs UI to run against

Related

simple docker run target in goland can't find package main

I'm trying to do some testing with go1.18 and thought I'd give docker run targets a shot from within goland Build #GO-213.6461.23, built on December 16, 2021.
It's simple hello world application and I'm trying to use the docker image setup. It seems to have found the docker server and the docker image OK, but when I try and set the run target to this config, I get a warning that it cannot find package main.
I've plonked in a screen shot of the config. It's got me tossed.
The error message is displayed in the screen shot above at the bottom.
The code is a simple hello wordld
package main
import (
"fmt"
"time"
)
func main() {
var test string
test = "Hi there"
fmt.Println(test)
time.Sleep(time.Second * 5)
}
which of course runs fine if run on the local machine.
The run target is configured as follows
That should be enough to reproduce the set up I'm trying to use.
Make sure that you use the module name from go.mod file. According to your screenshot, it seems that your Package path should be awesomeProject instead of main.
From GoLand documentation (https://www.jetbrains.com/help/go/running-applications.html#create-go-build-configuration):
Package path: a full import path of the package that you want to compile (for example, github.com/gorilla/mux). This field is available only when you select the Package run kind.
Alternatively, you can run your application using gutter icons and GoLand creates run configuration with the correct Package path automatically.
After that, you can invoke Run | Edit Configurations and select Run Target to Docker one.

.Net Core web API Docker (Linux) - unable to load libMyCpp.so file

I have a .NetCore web API and and need to connect with a C++ shared library (libCppAppOutput.so). For this I am using DllImport inside the controller of the Web API as in the below code:
[DllImport("libCppAppOutput.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "methodNameinCppProject")]
public static extern int MethodNameInWebAPI(string param1, string param2);
When I am debugging it in Visual studio with Windows environment, I am getting an exception like
An attempt was made to load a program with an incorrect format.
(0x8007000B).
This may be because of trying to access a Linux file in Windows environment, if I am using a CppAppOutput.dll in place of libCppAppOutput.so I can successfully call the methods inside the dll. But my actual requirement is to run the entire application in Linux environment and to be proceed with .so file only, so I have created a docker image with target OS as Linux and tried to call the methods inside it from running docker with the below command :
docker run -p 8081:80 name_of_docker_image:tagname
Then I am getting an exception like:
Unable to load shared library 'libCppAppOutput.so' or one of its dependencies. In order to help diagnose loading problems, consider
setting the LD_DEBUG environment variable: libCppAppOutput.so: cannot
open shared object file: No such file or directory.
But I can see the file, libCppAppOutput.so is present inside the docker image by using the following commands,
docker create --name name_of_container name_of_docker_image:tagname
docker start name_of_container
docker exec -ti name_of_container /bin/bash
root#xyzabc:/app# ls
I am using below URL to test the application
http://localhost:8081/launchUrl/MethodNameInWebAPI/param1/param2
Please help me in this regard like how can I call a .so file from the Linux docker.
if this issue to be elaborated more, kindly comment and I will do.
Thanks in advance.
I could able to solve this issue with help from my colleagues and friends.
There was a dependency with libCppAppOutput.so (an XML parser). Even though that dependency package is installed in the container, it was missed to configure while creating the libCppAppOutput.so.
This was identified by executing ldl libCppAppOutput.so command in bash.
Thank you all for spend time on reading and analyzing the question !
Have more N more great coding days!

Debug groovy script within a container

I'm building a jenkins container and want to set the KeycloakSecurityRealm in the initial flow. I already have a script which works fine for default settings:
import hudson.*
import hudson.model.*
import jenkins.*
import jenkins.model.*
import java.util.logging.Logger
import hudson.security.*
import java.util.*
import com.michelin.cio.hudson.plugins.rolestrategy.*
import java.lang.reflect.*
import org.jenkinsci.plugins
/*
NOTE: that megascript should be split someday, when my groovy skills improves.
*/
Thread.start {
//vbles definition
def logger = Logger.getLogger("")
def instance = Jenkins.getInstance()
def pm = instance.getPluginManager()
def uc = instance.getUpdateCenter()
def installed = false
// More code...
//No plugins to update. Security can be set
logger.info("All plugins are up to date")
logger.info("Setting security")
// logger.info("Creating initial user")
// hudsonRealm.createAccount("USER","USER")
logger.info("Creating reaml")
def keycloakSecurityRealm = keycloakRealm.createSecurityComponents()
//realm based on jenkins database
logger.info("Setting Security realm to KEYCLOAK")
instance.setSecurityRealm(keycloakSecurityRealm)
//not anonymous read allowed
This code crashes without any information. I whould like to debug the container so I've checked I can run the step where the container crashes to attach an interactive console:
Can do
docker run -ti 3ed
And I have access to the container as root.
Problem is I can't debug the script. I've checked there are some ways as using jdb but in all cases it is neccessary a mail java class for running it. The original script worked when called without changes so it runs file without any classes.
How could I debug this kind of java scripts inside a container?
Thanks.
Once inside container, make sure to run your code in debug mode.
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887 ...
In case you have no chance to start java by yourself, you can always use _JAVA_OPTIONS
export _JAVA_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887
Attach your debugger (e.g. IntelliJ) to remote machine (your Docker based container). Debug the code from the IDE started outside the container.
It should do the trick.
For a sample (used for profiling) take a look here:
https://github.com/mkowsiak/ProfilerDocker
It's not the same thing, but it's similar in a sense that Docker based code (Java) is executed inside container, while profiler (running outside container) is attached to remote machine.

How to start browserstack locale as a background process in jenkins using WINDOWS for protractor end to end testing in jenkins

Can anyone please help me to start browserstack locale as a background process in jenkins using WINDOWS for protractor end to end testing .
I was going through this link but this is for linux,I need for windows .
https://janmolak.com/jenkins-2-0-pipelines-and-browserstack-bd5a4ed3010d#.gf9pxyhgc
I have already installed browserstack binary for win 32 in jenkins.
Have you tried the Jenkins plugin for BrowserStack? You can refer to the details here - https://www.browserstack.com/automate/jenkins.
Since you are not using Java you will not be able to use the reporting functionality of the plugin. You can however use the following features that the plugin offers.
1) Manage your BrowserStack credentials globally or per build job.
2) Set up and teardown BrowserStackLocal for testing internal, dev or staging environments.
Here's how I got it working:
Install the BrowserStackLocal binary from their website.
Install the Jenkins Browserstack Plugin how to
Configure the plugin with your username and access key and point it at the downloaded binary.
In order for the session to route ip traffic locally, we have to pass a local identifier from the binary into our desired capabilities when the test runs. (as Ashwin Gonsalves pointed out.)
public DesiredCapabilities GetCapabilities(Browser browser, bool isBSLocal)
{
DesiredCapabilities capability = new DesiredCapabilities();
// Get BSID for local ip routing
if (isBSLocal)
{
string BSID = System.Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL_IDENTIFIER");
capability.SetCapability("browserstack.localIdentifier", BSID);
}
switch (browser.ToString())
{
case "Chrome":
capability.SetCapability("os", "Windows");
capability.SetCapability("os_version", "10");
capability.SetCapability("browser", "Chrome");
capability.SetCapability("browser_version", ChromeVersion);
capability.SetCapability("browserstack.chrome.driver", "2.42");
capability.SetCapability("resolution", "1920x1200");
capability.SetCapability("project", TestOps.GetParent);
capability.SetCapability("name", TestOps.GetTestName);
capability.SetCapability("browserstack.local", "true");
capability.SetCapability("browserstack.debug", "true");
capability.SetCapability("browserstack.selenium_version", ChromeSeleniumVersion);
capability.SetCapability("browserstack.user", USERNAME);
capability.SetCapability("browserstack.key", AUTOMATE_KEY);
break;

Which API does Java's jps tool use internally?

I need to recreate the functionalities of the jps tool programmatically. I need to find out all Java running processes along with their id so I can attach to that process (similar to what JConsole does).
I thought the VirtualMachine API would help, but did not get expected result when I run the following
public class ProcessList {
public static void main(String[] args){
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
for(VirtualMachineDescriptor vm : vms){
System.out.println (vm.id());
}
}
}
When I run the code above, it returns just one ID, but when I run jps on the same machine I see several other processes.
jps uses an internal class - MonitoredHost of the Oracle/Sun JRE. The activeVMs() method is used to obtain the list of all active VMs on a host. You can refer to the source of the sun.tools.jps.Jps class of OpenJDK, to find out how the jps tool works under the hood.
This is the correct API, ultimately 'MonitoredHost#activeVMs()' and 'VirtualMachine.list()' use the same discovery code via jstat technology. Do you run jps on the command line as a different user? In that case, you would see different JVMs.
See here how JPS is implemented.
you can do following :
1) Create platform specific script files (.bat for windows, .sh for linux etc)
2)Use "wmic process"(Windows), "ps -ef"(linux) etc commands in those scripts to list the processes (pipe on the result to get the java processes).
3)Launch the above scripts using Runtime's API and get the output result

Resources