Unable to open URL in chrome on virtual machine using batch file - selenium-webdriver

I have automated a flow using selenium webDriver. When I am running this using batch file from my system, it is running properly. But when tried to run the same batch from virtual machine, it is invoking browser but with blank URL. I am not able to run batch from virtual machine for Chrome driver.
Selenium Version: Selenium 3.4.0
I know, I am missing something but not able to find it.
Could anyone help me with solution.
Code inside batch:
start javaw -jar Example.jar
Thanks.

Related

browser does not launch on running react project on wsl (zsh)

I am working on a simple react project on Windows 10 Pro. On trying to run the project with wsl with zsh (npm start) everything works, I get warnings and compilation is done without any errors. The issue I am facing is automatic launch of browser from wsl is not happening.
If I manually open localhost:3000 on my chrome after this command everything works but I would like the wsl terminal to launch my browser on npm start automatically just like it does in most of my other terminals and powershell on windows.
What I have tried:
added a export browser property to my .zshrc with path to chrome from here
Added a bsconfig file to root with following code to set open = true as per from here
I have added the ports from 3000-3999 to my firewall so that wsl can access my host (localhost ip). this fixed previous issue where localhost:3000 would show connection refused error.
I would be happy to provide any more details.
I am very new to wsl and zsh and I would really appreciate any help. Thanks

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.

How to set chrome driver path for centos

I am triying to run my testcase on centos but unable to set the path for driver can anyone help me to come out from this situation
I have one jar file which I want to run on sentos I have installed chrome driver on sentos server but. It is not taking driver path
If you're using the Java bindings for Selenium, you will have to specify the path to the ChromeDriver executable via the webdriver.chrome.driver system property. Depending on how you actually run your tests you can do this for example via the -D command line switch of the java executable:
java -jar mytests.jar -Dwebdriver.chrome.driver=/path/to/chromedriver

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 !

Launch chrome browser

I am trying to launch chrome browser (version 26.0) using webdriver.
I am getting the following error message.
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver.
at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:69)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
at googleSearch.main(googleSearch.java:13)
Code I used:
driver = new ChromeDriver();
driver.navigate().to("http://www.google.com/");
I use mac 10.8.2.
For this to work, you need to:
Install Chrome
Install Chrome Web Driver
Make sure you have the chrome web driver in you path, for example on Windows something pointing to chromedriver2_win32_0.8. You can put that in your path by either: (a) Modifying your windows path environment variable, or; (b) adding the following to your java command line options:
-Dwebdriver.chrome.driver='/path/to/driver'
In case of using selenium grid
-Dwebdriver.chrome.driver='/path/to/driver'
has to be added while creating a node from command line.
1) In case of using selenium without GRID:
System.setProperty("webdriver.chrome.driver","/absolute/path/to/chromedriver");
driver = new ChromeDriver();
does the job.
2) In case of using selenium with GRID:
System.setProperty("webdriver.chrome.driver","/absolute/path/to/chromedriver");
driver = new ChromeDriver();
And from command line, while creating a node for chrome browser one needs to pass
-Dwebdriver.chrome.driver='/absolute/path/to/chromedriver'
The above two changes did the job for me, apart from this I was getting this libnss3.so not found error which I solved by creating a symlink of libnss3.so present in /usr/lib/x86_64-linux-gnu/ folder to /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libnss3.so /usr/lib/libnss3.so
PS: Also make sure that you are using 64bit OR 32bit version of chrome driver as per your system.
For chrome to work with selenium-webdriver you need to have not only a working chrome browser installed, but also the chromedriver executable. Note that these are TWO different executable files that both need to be specified.
change the permission of file and then run your code again.
Open command prompt and navigate to directory where your chrome exe exists and write
chmod 777 filename
Hope it will solve your problem.

Resources