Execute Selenium at the startup - java

I'm using Selenium to automate a browser in a Server from a client, but I want that the server execute selenium automatically at the startup.
I have 3 files in /etc/init:
proxyserver.conf:
respawn
start on runlevel [23]
script
exec java -jar selenium-server-standalone-2.20.0.jar -role hub -port 1111
end script
proxyserver2.conf and proxyserver3.conf that are the same thing and change only the content of "script":
exec java -Dwebdriver.chrome.driver=/home/marco/selenium-client/chromedriver -jar selenium-server-standalone-2.20.0.jar -role node -port 2222 -hub http://192.168.1.12:1111 -browserName=chrome,maxInstances=5
If I execute this commands at the startup with this method, when I execute Selenium on the Client, it give me this error:
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
But if I execute in the terminal the same commands that I use in /etc/init, all works perfectly... why?!
One last thing, if I execute:
ps aux | grep selenium
when the server the scripts at the startup it gives me:
root 746 0.0 12.1 677080 124468 ? Ssl Apr23 8:10 java -Dwebdriver...
root 749 0.0 12.7 685552 130280 ? Ssl Apr23 8.09 java -Dwebdriver...
root 755 0.0 1.9 680168 20240 ? Ssl Apr23 8.08 java -jar selenium...
when I execute in the terminal it gives me:
1000 9764 6.6 3.0 679236 30992 pts/0 Sl+ 10.33 0:01 java -jar...
1000 9783 14.0 3.0 677112 31752 pts/1 Sl+ 10.33 0:01 java -Dwebdriver...
1000 9792 12.6 3.0 675472 30944 pts/2 Sl+ 10.34 0:01 java -Dwebdriver...
Why it can't works?
thanks!!

I have seen this error when the chromedriver path is wrong. If you see the RC console it should have the chromedriver not found error message.
The chromedriver environment property should be passed as parameter to selenium jar file.
exec java -Dwebdriver.chrome.driver=/home/marco/selenium-client/chromedriver -jar selenium-server-standalone-2.20.0.jar -role node -port 2222 -hub http://192.168.1.12:1111 -browserName=chrome,maxInstances=5
should be changed to
exec java -jar selenium-server-standalone-2.20.0.jar -role node -port 2222 -hub http://192.168.1.12:1111 -browserName=chrome,maxInstances=5 -Dwebdriver.chrome.driver=/home/marco/selenium-client/chromedriver

Related

Can not open Multiple Browser by using selenium grid

I am new to selenium grid. I want to do testing in parallel mode. I tried as like following. But it won't open the multiple browsers. I don't know what I have done wrongly.
My Code :
for(int i=0;i<=10;i++){
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox());
driver.navigate().to("http://gmail.com");
}
Selenium Hub:
java -jar selenium-server-standalone-2.52.0.jar -role hub
Selenium Node:
java -jar selenium-server-standalone-2.52.0.jar -role node -hub http://localhost:4444/grid/register -port 5560 -browser browserName=firefox,maxInstance=3 -maxSession 3
Info Prints in Hub :
16:38:28.581 INFO - Available nodes: [http://192.168.1.28:5560]
16:38:28.581 INFO - Trying to create a new session on node http://192.168.1.28:5560
Configuration
I have found the solution for this.
I only did the mistake in the command.
I should used maxInstance instead of maxInstances
The command should be like this
java -jar selenium-server-standalone-2.52.0.jar -role node -hub http://localhost:4444/grid/register -port 5580 -browser browserName=firefox,maxInstances=3 -maxSession=3
maxInstance=3 in your command is wrong. It should be 'maxInstances=3'.

How to Install Selenium as a Unix daemon?

How to put the following commands to run in the background as a service on Ubuntu?
Start the hub
java -jar selenium-server-standalone-2.48.2.jar -role hub &
Start the nodes
java -jar selenium-server-standalone-2.48.2.jar -role node -hub http://localhost:4444/grid/register &
Whenever I close my ssh session can not access the selenium grid service even putting '&' character at the end of each command. Would someone give me a help?
I've tried to make selenium-server-standalone running as a service, but it failed to launch browser (I've tried chrome and firefox).
So it is better to do as Mahsum Akbas says.
Here is an example of how you could make it as a service:
bash - Start Java jar by service (linux)...
But it will not launch real browsers.
I was using jenkins service to launch real browser, but it failed too.
I had success in launching tests using headless browser. But there was the problem with some tests were failing.
And also, you could try this
EDITED: I've achieved it in such way using systemd:
sudo vim /etc/systemd/system/selenium-server-hub.service
[Unit]
Description=Selenium Server Standalone hub
StartLimitIntervalSec=5
After=syslog.target
[Service]
Type=simple
Restart=always
RestartSec=8
User=spacer
ExecStart=/bin/bash -c "export DISPLAY=:10 && /usr/bin/java -jar /home/spacer/seleniumserver/selenium-server.jar -role hub"
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
sudo vim /etc/systemd/system/selenium-server-hub.service
[Unit]
Description=Selenium Server node
StartLimitIntervalSec=0
After=selenium-server-hub.target
[Service]
Type=simple
Restart=always
RestartSec=8
User=spacer
ExecStart=/bin/bash -c "export DISPLAY=:10 && /usr/bin/java -Dwebdriver.chrome.driver=/bin/chromedriver -jar /home/spacer/seleniumserver/selenium-server.jar -role node -hub 'http://192.168.0.101:4444/grid/register/'"
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
I connect to my linux server through RDP and it opens display :10. Your display could be different.
You could check your displays by command:
ps e | grep -Po " DISPLAY=[\.0-9A-Za-z:]* " | sort -u
PS: Chrome and Firefox are starting, even though chromedriver could not be started when I was launching selenium-server hub and node from terminal as usual.
you can use nohup command. so, you can redirect output to nohup file and there will not be kill session after disconnect ssh.
nohup java -jar selenium-server-standalone-2.48.2.jar -role hub &
nohup java -jar selenium-server-standalone-2.48.2.jar -role node -hub http://localhost:4444/grid/register &

can i use selenium grid on single machine

I don't have multiple machines at my job. I have one window and one mac for script execution. I was wondering if i can use selenium grid for script execution on single machine.I never used selenium grid. Any article, links or suggestion is highly appreciated.
Yes, you can start a selenium gird with multiple node on single machine, but RAM should be at least 8GB because it will running test suites with more than 4 browser instance it need more RAM if not browser gets closed.
http://selenium-release.storage.googleapis.com/index.html Download standalone jar.
java -jar selenium-server-standalone-2.45.0.jar -role hub
It will start hub .
To start nodes open different cmd and type following command to start 'n' number nodes. The command is below:
java -jar lib/selenium-server-standalone-2.43.1.jar -role node -hub http://localhost:4444/grid/register -port 5555
java -jar lib/selenium-server-standalone-2.43.1.jar -role node -hub http://localhost:4444/grid/register -port 6666
java -jar lib/selenium-server-standalone-2.43.1.jar -role node -hub http://localhost:4444/grid/register -port 7777
If you want to run same test case in different browser download the browser drivers here
Run the following command to start different browsers:
For example:
java -jar selenium-server-standalone-2.45.0.jar -role webdriver -hub http://localhost:4444/grid/register -Dwebdriver.chrome.driver=C:\Users\xyz\Desktop\chromedriver.exe
java -jar selenium-server-standalone-2.45.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 6666 -Dwebdriver.chrome.driver=C:\Users\xyz\Desktop\chromedriver.exe.
This will start chrome browser and node.
Yes you can use set up Selenium Grid on a single machine. You can download the jar file from this download link
After download, start the hub with the following command:
java -jar selenium-server-standalone-2.46.0.jar -role hub
Then register nodes to it with the following command:
java -jar selenium-server-standalone-2.46.0.jar -role node -hub http://localhost:4444/grid/register
Refer the following link for more information, the example there is for the single machine scenario with Ruby but it is similar in java.
http://elementalselenium.com/tips/52-grid
You can also run a grid locally using Docker. Selenium provide images for a hub, Chrome and Firefox on Ubuntu.
You can but not sure why would you. If you want to execute in a single machine you can just go ahead and create multiple instances of the web driver for different browsers and achieve that. IMHO the whole purpose of grid is to distribute the load across nodes with different browsers,OS etc ..
But to answer your question yes you can. You can run the hub and node in the same machine and test it out if that's what you want to do.

Selenium hub and node issue

I am newbie to selenium. I am trying to run some test cases, for this I tried to start selenium hub and node..Following is batch file to start hub and node.
set path=%path%;C:\SeleniumConfig;C:\Program Files (x86)\Java\jdk1.7.0_21\bin;C:\Program Files (x86)\Java\jre1.6.0_45\lib;
set webdriver.ie.driver=C:\SeleniumConfig\IEDriverServer.exe
start java -jar selenium-server-standalone-2.42.2.jar -role hub -hubConfig config-hub.json
start java -jar selenium-server-standalone-2.42.2.jar -role node -nodeConfig config-node.json -hub http://localhost:4444/grid/register
When I tried to run hub and node using following command , I dont see any issue on command prompt. but dont see anythings is running on http://MyHost:4444/
"start java -jar selenium-server-standalone-2.42.2.jar -role hub -hubConfig config-hub.json"
With the above command some window opens and close immediately.
Please advice
selenium-server-standalone-2.42.2.jar file must be at same path . Or you can give jar file path. e.g. start java -jar C:/selenium-server-standalone-2.42.2.jar -role ......

Running stanford NER classifier in server mode

To make the NER classification faster I am trying to execute it in server mode listerning on port xxxx, so that it can give faster result when request is send.
Here is the original execution command without server that I am using.
java -mx1500m -cp $1/stanford-ner.jar edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier $1/classifiers/ner-eng-ie.crf-3-all2008-distsim.ser.gz -textFile $2
(this command is in .sh file and executed by python script. $1 is input file name)
This documentation explain how it can be run in server mode - Link
Here how the server get started:
java -mx400m -cp stanford-ner.jar edu.stanford.nlp.ie.NERServer -loadClassifier classifiers/ner-eng-ie.crf-3-all2008.ser.gz 1234
Now server is in listerning mode on port 1234.
How can I make call using input text file for this server?
I followed this tut : Link and executed this command:
java -cp stanford-ner.jar edu.stanford.nlp.ie.NERServer -port 1234 -client
But it just print this message:
Usage: NERServer [-loadFile file|-loadJarFile resource] portNumber
I am working on linux system.
To run the NER in server mode, you have to use the following command line :
java -mx400m -cp stanford-ner.jar edu.stanford.nlp.ie.NERServer -loadClassifier classifiers/ner-eng-ie.crf-3-all2008.ser.gz -port 1234
(-port is missing in the README file, it works well for me)

Categories