I'm currently working with Jenkins + Selenium Plugin for Jenkins. I have a hub and some nodes. Both Hub and Nodes are in my localhost.
I realized that, when I run my tests locally (That means, using chrome, firefox, IE webdrivers), then the browsers will appear and the tests will be executed.
driver = webdriver.Chrome() # Open Chrome Browser
On the other hand, if I run the tests through a remote webdriver, then the browsers appear to be headless.
capabilities = {"platform" : "VISTA"}
capabilities["browserName"] = "chrome"
driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', desired_capabilities=capabilities)
# Hub and Node are running locally, windows chrome won't open (Headless?)
Are these remote browsers (selenium grid) "headless" by default?
How could I verify if they're really running in headless mode?
If they are not headless, how can I make them headless? (jenkins +
selenium grid)
I've been trying to do some research but can't find any documentation that specifies this. I just found this post:
http://grokbase.com/t/gg/selenium-users/15b64b173p/selenium-grid-browser-appears-headless
Thanks!
RemoteWebDriver is not headless by default, it is running where you want it to run, it can run on user account as a normal browser or it can run in background on LocalSystem account.
Which OS are you using? If you are running jenkins as a windows service your test will run in background, it's normal behavior because of windows service 0 policy.
Related
I'm using selenium chromedriver with Google Chrome profiles on Mac OS and Windows. As I understand it, in the usual case the selenium script will not work if another profile in Google Chrome is open. This causes some inconvenience as a regular google chrome user - every time before I run the script I have to close the browser completely.
I would not be comfortable switching to the gecko driver because firefox does not allow me to install the extensions I need. Are there any other options on how to solve this problem?
I have a system VPN (I am using pptp protocol) and I am going to use Selenium to test our website, but since only internal users are able to access that website without using a VPN, I cannot access the website to test. When I am using Selenium in GUI mode (not headless) it works fine without any problems but when I switch to headless mode using this command:
chrome_options = Options()
chrome_options.add_argument("--headless")
I get an error because my VPN does not work in the headless mode. Is there any way to use and set my VPN in headless mode in Selenium?
I am using Selenium to open a certain website (for example YouTube) on the server, but it can't seem to open the website. However, the code works just fine with a different website. This code also works fine without any problems on my local PC.
I don't know if I have problems with my Chrome Driver or Selenium but it can't open youtube.com as it only outputs: "Before getting the website" and that's it. There are no exceptions/errors that are shown but the script still runs and I have to manually end stop it.
Why can't Selenium open certain URLs on the server, but it works fine on my PC?
options = webdriver.ChromeOptions()
options.add_argument("no-sandbox")
options.add_argument('--headless')
options.add_argument("--start-maximized")
PATH = "./chromedriver"
global driver
driver = webdriver.Chrome(PATH, chrome_options=options)
print("Before getting the website")
driver.get("https://youtube.com")
print("opened", driver.current_url)
I had a exactly same problem. Perhaps i don't know why this happened.
NOTE:
When you are scraping working on Ubuntu ec2 with no GUI you have to provide some GUI interface for chrome to run and for me Xvfb solved it.
"Xvfb (short for X virtual framebuffer) is an in-memory display server for UNIX-like operating system (e.g., Linux). It enables you to run graphical applications without a display (e.g., browser tests on a CI server) while also having the ability to take screenshots."
SOLUTION
Install Xvfb for ubuntu: sudo apt install xvfb
Now execute your script as: xvfb-run python[version] script.py
IMPORTANT NOTE:
If your program stuck during initialization does not show any output just make sure that you did not add chrome_option.add_argument("disable-dev-shm-usage").
If this argument is added in your chrome header then it would disable the /dev/shm. Not sure but it is some shared memory and xvfb is in-memory display server which i think need it.
This worked for me.
I write some code with python selenium using chrome driver as web driver. When I run code in my system ( mac os ), the code works. Chrome browser was opened, and selenium works correctly. But when I want to run my code in Centos 7 without GUI, selenium can't match with web driver and run the code. Although I install google-chrome-stable and use the same web driver for it, selenium can't run web driver.
driver = webdriver.Chrome(driver_path=chromedrive75)
So, I don't know how to fix the code and running on my centos operating system.
#Vahid, please check the chrome web browser version which is compatible with server, also try running in headless mode.
I am wondering if there is a way within py2app to include the Firefox browser, or if there is a way for Selenium to use Firefox without having to install Firefox on the host machine.
I have created an app with py2app that uses Selenium, however, I have Firefox installed on my machine, but not everyone that will receive the app will have Firefox installed. I am looking for a way to either include Firefox in the distribution or go around this.
Script will not run if Firefox is not preinstalled.
You can test your script with other browser, for example Chrome. If it works on Chrome also, then you can edit script like this:
from selenium.common.exceptions import WebDriverException
try:
driver = webdriver.Firefox()
except WebDriverException:
driver = webdriver.Chrome()
You can add same for few more browsers (IE, Opera, Safari...) to be sure that script will run on users machine