I'm using appium to automate desktop .net application and when the test starts I execute the tscon script to disconnect from vps and keep the session alive. If I run tscon before creating appium driver it says cannot find process id and if I run it after I create the driver it says window has been closed.
this is the script:
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
%windir%\System32\tscon.exe %%s /dest:console
)
Related
I am currently administering a Selenium Grid with 20 remote PCs acting as nodes to a single Hub located on a server. At the moment I have to remote in to each machine when I want to restart the hub or nodes and clear up any stale chromedriver or chrome instances. I am trying to automate this process via Powershell.
So far I have manage to write the ps scripts to kill any instances of chrome, chromedriver and java on the PCs and then restart the hub or node. They work when started locally on each machine when but fail when I try and execute them via a PSSession.
I have enabled remote sessions on each machine successfully and I can Invoke-Commands that will kill the existing instances of java and chrome but I can't restart the hub or nodes.
Example of Hub powershell script:
#This script kills any existing java process and runs StartHub.bat
Set-Location C:\Selenium
kill -Name java -Force -PassThru -ErrorAction Continue
Start-Process -FilePath "C:\Selenium\StartHub.bat" -PassThru -Verbose
The bat file is as follows:
java -jar C:\Selenium\selenium-server-standalone-3.4.0.jar -role hub -hubConfig "V:\ServerFiles\hubconfig.json"
I have been testing with the execution policy unrestricted and my network administrator has changed GPO's to allow my to start java processes remotely but it's just not working. I've tried several approaches which I have listed below:
1: Entering a PSSession on remote server and calling the ps1 file:
C:\RestartHub.ps1
The result being that the existing hub instance is killed but a new one does not open.
2: I have then tried to Start a job with a ScriptBlock calling the cmd script to start the batch file:
Set-Location C:\Selenium
kill -Name java -Force -PassThru -ErrorAction Continue
Start-Job -ScriptBlock{cmd /c start "C:\Selenium\StartHub.bat"} -Name Hub -Verbose
This again kills the existing hub instance but the start script does not run or fails silently.
I have looked through the security logs on the remote machine to see if there are any issues there but the PSSession seems to be correct using the right user with full admin rights.
I have also changed the ExecutionPolicy on the remote machine to restricted to see if an access denied error is display, which it was. I changed back to unrestricted and error went away.
I'd be grateful for any ideas.
Start-Process will start a process from an executable, you cannot use a bat file as an executable, -FilePath expects an executable's path
See below,
Start-Process cmd -Argumentlist "C:\Selenium\StartHub.bat" -PassThru -Verbose
I've got two Remote Desktops hosted by a Hyper-V.
On Remote Desktop "A", I've got a .bat file, which I want to execute.
On Remote Desktop "B", I've got a cmd open with psexec cmd ready to invoke .bat file on machine "A".
"path-to\\psexec.exe" \\ip -u domain\username -p pswd -i cmd.exe /c "path-to\\myFile.bat %*"
The script contained in .bat file on machine "A" operates on the UI and thus requires a real screen to be open, so I am connected to two RDs simultaneously. However, when I call psexec command on machine "B", the cmd returns an error, but if I open RD "A" directly through the server's Hyper-V manager's interface, the psexec command works as expected.
Can someone explain please why this happens?
The UI of Windows runs on session 0. To run a program remotely that uses session 0, it will need to run as the System user (-s flag), and you can specify the session to use (-i flag). This answer has a few related tips too.
I want to set up the node in different machines using a bit of java code it is not possible always to start a node every time so I want to open nodes automatically from hub machine.i tried some of the executable jars like Selenium-Grid-Extras but it's not useful.
if you want to start a node automatically from hub, you can write a bit of code to to start the hub as well as starting nodes based on the machine details where the node should execute. You can use ssh to start a node on a linux instance. There are libraries available for doing so in Java. About Windows I am not sure, but there should be libraries to remotely start applications through java.
Hope this helps.
What I've done in windows is to create scheduled tasks on each node machine-- e.g.
schtasks /create /tn RestartNode /tr c:\SeleniumGridExtras\RestartNode.bat /sc ONSTART
(the sc doesn't seem to work but whatever)
then from jenkins you can call the scheduled task with
schtasks /end /tn RestartNode /s [HOSTNAME] /u [DOMAIN]\[USERNAME] /p [PASSWORD]
Is it possible to make Jenkins use actual browser instead of headless browser? I a running some tests written in TestNG (using Selenium webdriver). When I run the testng.xml file in Eclipse, the browser starts and the tests run. But when I use Jenkins and run the tests with maven, it doesn't start any browsers.
If your jenkins is hosted in a Windows machine, there are some special configurations you should know about services that are allow to use the interface.
By the way, the easiest way to see the browsers running is starting jenkins using the command line:
java -jar jenkins.war
In linux you could use the same command or use xvfb plugin to run browsers in background.
Hope helps
In addition to this, the main reason for not launching the browser is JNLP (java network launch protocol) , when we execute the war we can interact with the desktop applications.
Using Selenium Grid will allow you to execute the test on Jenkins but open the browser on a remote slave.
To achieve this you need to create an instance RemoteWebdriver than ChromeDriver, IEDriver etc I
For linux. If jenkins is running as a daemon, you could specify active display to connect to and run your browser on it. Check what display you could connect to:
ps e | grep -Po " DISPLAY=[\.0-9A-Za-z:]* " | sort -u
My output is:
DISPLAY=:10.0
DISPLAY=:2
DISPLAY=:2.0
Then go to your jenkins project -> Configure -> Build and add the next string above your main build configuration through "Add build step -> Execute shell"
/bin/bash -c "export DISPLAY=:10"
Edited: I've encountered the issue again recently. To resolve it:
I've given for the jenkins' user ability to interact with the desktop of my current user:
xhost +si:localuser:jenkins
so if I connect to my linux system through ssh using jenkins' user credentials, export display of my current user (export DISPLAY=:10) and run, for example google-chrome or firefox inside of putty's terminal, they are launching on my current user's desktop.
After this I've checked If I could start "mvn test" command inside of workspace/MyTests folder from my putty so it will start browser and execute tests.
At the end I've created simple script in the root of my current user:
vi ~/.startup.sh
#!/bin/bash
xhost +si:localuser:jenkins
and added it to my Xfce4 GUI: Application -> Settings -> Session and Startup -> Application Autostart, specifying command field as:
sh -c $HOME/.startup.sh
It's because of this script should work only when desktop is loaded to share my current user's display with jenkins' user. After reboot and connecting to this server through RDC desktop loads with xhost command applied. And after this jenkins could interract with desktop even when I close the RDP connection but leaving current user's session alive.
I've removed Build step in my jenkins' project configuration that was stated "Invoke top-level Maven targets". It could not start my browsers.
I've changed my "Add build step -> Execute shell" to:
export DISPLAY=:10
cd /var/lib/jenkins/workspace/MyTests
mvn test
I've tried grid also, turning selenium-server-standalone -hub and -node into daemons. But it was slower than launching browsers with WebDriver in the such way.
Jenkins version: 1.574
I created a simple job which performs the following:
Using "Execute shell script on remote host using SSH" as one of the BUILD steps, I'm just calling a shell script. This shell script performs stop and start operations on Tomcat to restart an application on the target machine.
I have a valid username, password, port defined for the target SSH server in Jenkins Global settings.
I saw this behavior that when I run a Jenkins job and call the restart script (which gets the application name as parameter $1), it works fine, but as soon as "Execute shell script on remote host using SSH" step completes, I see the new process dies on the remote/target application server.
If I run the script from the target/remote server itself, everything works fine and the new process/PID remains live forever, but running the same script from Jenkins, though I don't see any errors and everything works as expected, the new process dies as soon as the above mentioned SSH step is complete and control comes back to the next BUILD step in Jenkins job OR the Jenkins job is complete.
I saw a few posts/blogs and tried setting: BUILD_ID=dontKillMe in the Jenkins job (in various places i.e. Prepare Environment variables and also using Inject Environment variables...). When the job's particular build# is complete, I can see Environment Variables for that build# does say BUILD_ID=dontKillMe as its value (instead of the default Timestamp tag value).
I tried putting nohup before calling the restart script, i.e.,
nohup restart_tomcat.sh "${app}"
I also tried:
BUILD_ID=dontKillMe nohup restart_tomcat.sh "${app}"
This doesn't give any error and creates a nohup.out file on the remote server (but I'm not worried about it as the restart_tomcat.sh script itself creates its own LOG file which I'm "cat"ing after the restart_tomcat.sh script is complete. cat'ing on the log file is performed using another "Execute shell script on remote host using SSH" build step, and it successfully shows the log file created by the restart script).
I don't know what I'm missing at this point, but as soon as the restart_tomcat.sh step is complete, the new PID/process on the remote/target server dies.
How can I fix this?
I've been through this myself.
On my first iteration, before I knew about Jenkins ProcessTreeKiller, I ended up just daemonizing Tomcat. The Apache Tomcat documentation includes a section on running as a daemon.
You can also try disabling the ProcessTreeKiller for your whole Jenkins instance, if it's relatively small (read the first link for information).
The BUILD_ID=dontKillMe should be passed to the shell, and therefore it should be in your command line, not in Jenkins global configuration or job parameters.
BUILD_ID=dontKillMe restart_tomcat.sh "${app}" should have worked without problems.
You can also try nohup restart_tomcat.sh "${app}" & with the & at the end.
My solution (it worked after trying everything else) in Ubuntu 14.04 (Trusty Tahr) (Amazon AWS - Amazon EC2), Jenkins 1.601:
Exec command: (setsid COMMAND < /dev/null > /dev/null 2>&1 &);
Exec in PTY: DISABLED
// Example COMMAND=socat TCP4-LISTEN:1337,fork TCP4:127.0.0.1:1338
I created this Transfer as my last one.
#!/bin/ksh
export BUILD_ID=dontKillMe
I added the above line to the start of my script and the issue was resolved.