Home > Mobile >  What does Selenium Service class do?
What does Selenium Service class do?

Time:05-25

I'm curious what the Selenium class called "Service" is.

Would this be useful for setting up a Chrome driver as opposed to invoking a webdriver through my_driver = webdriver.Chrome(...)?

I looked up the docs but they're not helpful in describing the purpose:

CodePudding user response:

Service is the new class introduced in selenium 4 to start a webdriver:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

driver = webdriver.Chrome(service=Service(your_chromedriver_path))

The previous method is deprecated:

driver = webdriver.Chrome(executable_path=your_chromedriver_path)

in fact if you run it, then it raises a warning

DeprecationWarning: executable_path has been deprecated, please pass in a Service object

CodePudding user response:

This service is introduce to manage the driver process. So that you can kill it after your tests are done.

Basically invoking quit does not put any obligations to webdriver to stop existing as the process. On the contrary webdriver is a service that is aimed to process concurrent sessions from different clients. So once your tests are stopped the webdriver might still be running.

When you start your tests using Service you now get an interface to kill that remote process using the obtained reference.

  • Related