To schedule crontab on linux env for selenium - selenium-webdriver

I am running my selenium test case using "mvn clean test" and its working fine.
When tried to run it from crontab , getting error chrome driver crashed.
Tried to write shell script and provide pom , code directory etc but its of no help
any suggestions?

Suggesting to inject into your cron script 2nd line:
source /home/<your username>/.bash_profile
This will insert into your cron script all the required environment context and paths.

Related

How can I run unit test script in cakephp shell?

In composer.json file php unit is added
"phpunit/phpunit": "^9.5",
I am just trying to run a test script in cmd
In project folder I have given command
vendor/bin/phpunit
Getting below result
How I will run test script using php unit in cakephp application ? My cakephp version : 4.x
In windows you have to write the command by back slash not by forward slash.
project>vendor\bin\phpunit

Tosca and Jenkins

Does anybody work with Tosca and Jenkins?
I have problems to run my batch script from Jenkins. It does not open browser, but job is finished successfully. Batch script runs normally when I try to run in on Windows, without Jenkins.
Anybody has an experience using these two tools together?
In order to use Tosca CI with Jenkins you need to:
Configure your Jenkins build project
Add an additional build step (Execute Windows batch command)
Call ToscaCIClient.exe/ToscaCIClient.jar with parameters
e.g. "PathToTosca\ToscaCI\Client\ToscaCIClient.exe" -t junit -r PathToResults\result.xml
Further information can be found here: https://support.tricentis.com/community/article.do?number=KB0012411
The issue your facing is because your running Jenkins as windows service, in this case headless execution happens technically your script is executed for other user account.
Solution
Instead of installing Jenkins host it on Apache Tomcat server
Download Jenkins war file
Copy it inside webapps folder of Tomcat
Run startup.bat
Refer-
https://www.tutorialspoint.com/jenkins/jenkins_tomcat_setup.htm
I had faced the same issue.
I am guessing your slave machine running the test has jenkins services installed as services.
Uninstall the service. (.jenkins/jenkins-slave.exe uninstall)
Use the .jnlp or slave.jar to connect the machine as a slave.
Your test should run fine after that.
If it does just create a batch file to connect the machine as slave whenever it is logged in.
I tried that. But in any case, Jenkins does not open the browser, so Tests from Execution List and I do not know why.
We use Tosca 10.

Jenkins/Windows - Launch TestNG suite from .bat

Stackoverflow helped me a lot to reach that point but now I'm completely stuck, here is my problem :
I'm currently developing several tests to check a website. I code with Java in Eclipse, using testNG plugin with ReportNG for report, all of this using Windows 7 pro.
My tests work, and my report is well generated, so now I have to put it on Jenkins for my company so they will run my tests every X hours.
In order to launch my tests, I have made a file, named Run.bat, which runs the Java code, I tested it and it works, here is the code :
Run.bat
set classpath=blex_test_v1\bin;blex_test_v1\lib\*
java org.testng.TestNG blex_test_v1\blex_test_v1.xml
I now try to launch the tests on Jenkins, creating a new job and configuring it with the build section :
Run.bat
And this is my problem, I've tried everything (relative path, only the name of the file etc...) I always get this error :
java.io.IOException: Cannot run program "cmd" (in directory "/var/jenkins_home/jobs/blex_functional_test/workspace"): error=2, No such file or directory
So I checked the Jenkins workspace but my Run.bat is in it :
Workspace
I have read that Jenkins is in Linux so it might cause problem with bat files, so I tried to create a script but I didn't succeed either ..
So my question is : How can I run my test on Jenkins using my file Run.bat ? What am I doing wrong here ?
Thanks a lot !
Finally I can add an answer :
Jenkins is installed on a Unix machine so you can't run a bat file, it has to be a bash script.
To create a bash script, refer here.
Then you have to make sure that the plugin Xvfb is installed (and works) on the computer where Jenkins is installed.
I use testNG with reportNg and it doesn't work with the last firefox version so you I use firefox v34.0.5 and this version must be installed also on the Jenkins computer.
If you want to open the report after the execution, install another plugin and configure it (report HTML or something like that)
God it took me about a week but it's good to see it working !

Unable to execute TestNG Suite file via command line

I am trying to execute a TestNG Suite file via the command line in order to initiate a regression run.
Currently I am doing this through my Eclipse IDE successfully by right-click on the "testng.xml" file then selecting Run As > TestNG Suite.
However, when I try to run it via the command line, I get an error message. Steps below:
I navigate to the directory where my "testng.xml" file is saved. e.g. C:\Users\xxx\Documents\eclipse projects\Automated Testing\config
Run the command:
java org.testng.TestNG testng.xml
The above command generates the below response:
Error: Could not find or load main class org.testng.TestNG
I tried setting the classpath to include all of the selenium and testNG Jar files as per below:
set classpath C:/Users/xxxx/Downloads/selenium-java-2.25.0/selenium-2.25.0/libs/*
However, this generates the below error message:
Environment variable classpath C:/Users/xxxx/Downloads/selenium-java-2.25.0/selenium- 2.25.0/libs/* not defined
I have looked on the testNG Documentation (http://testng.org/doc/documentation-main.html) and this just says that testNG has to be in your classpath, so now I am a bit stuck. Any help would be greatly appreciated.
Either methods work :)
Method #1
cd C:\Workspace\projectname
java -cp C:\Workspace\projectname\lib\*;C:\Workspace\projectname\bin org.testng.TestNG testng.xml
Method #2
cd C:\Workspace\projectname
set ProjectPath=C:\Workspace\projectname
echo %ProjectPath%
set classpath=%ProjectPath%\bin;%ProjectPath%\lib\*
echo %classpath%
java org.testng.TestNG %ProjectPath%\testng.xml
Thanks #siemic, I have finally got it working now. Basically you just need
to run the two commands below:
set classpath=..\bin;C:\libs\selenium-java-2.25.0.jar;C:\libs\testng-6.0.1-nobsh
noguice.jar;C:\libs*
java org.testng.TestNG
It was the first command that I was having trouble with, so just to elaborate I needed to set the following three items on the classpath:
The BIN Directory of my project. This is because the java files that I have developed are located here.
The Selenium.jar file, this is because I am using the selenium framework
The testng.jar file, needed because this is my unit testing framework
Then finally I used a wildcard to include all other JAR files within my libraries folder. The weird thing
is I needed to fully specificy the name of the selenium and testng jar files, or else the tests don't work. Not too sure why.
Anyway it is working fine now and I am able to execute the tests via the command line.

execute cron with shell using cake php

currently I am using command to execute cron is
cd appfolder.
../cake/console/cake cronname
it is working on local linux server
but,
(1)
/home/chpltv/public_html/cron/cron/cake/console/cake -app "/home/chpltv/public_html/cron/cron/app" news_import_basic >> /home/chpltv/public_html/cron/a.txt
(2) sh ../home/chpltv/boxyourtvtrial.com/cake/console/cake.php -app "/home/chpltv/boxyourtvtrial.com/public_html/cron/cron/app/" news_import_basic >> /home/chpltv/public_html/cron/a.txt
it is not working.
I dont know wht is issue......
Please Help me
please tell me command to run cron in cake php
A shell is run from the app/vendors/shells directory within the application you have created. When you create the shell, if must also follow the same class structure as the other class based code in cake:
class ThisNewNameShell extends Shell {
// functions here
}
Then this shell is called run with the following command:
/path/to/cake/console/cake {name_of_shell} {name_of_function} {args} -app /path/to/app
If you still are not getting the desired results, turn on debugging and run the shell manually to see the output and fix any issues. Once they are resolved, you will have a working cron.
Happy Coding!
Without any error messages, it's hard to diagnose a problem.
Check your email or cron logs (possibly /var/log/cron) for error messages, they may help.
Check the permissions on your files to ensure the cron user can run the cake console etc.
Assuming you have php cli working fine (should be ok if you can run it manually on the same server), is it in the path when the cron executes?
Consider appending 2>/tmp/news_import_basic.err to the cron commands to capture any error messages to a log file.

Resources