Convert Figma logo to code with AI

tebeka logoselenium

Selenium/Webdriver client for Go

2,544
411
2,544
163

Top Related Projects

30,518

A browser automation framework and ecosystem.

89,091

JavaScript API for Chrome and Firefox

46,847

Fast, easy and reliable testing for anything that runs in a browser.

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

18,791

Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol

Quick Overview

The tebeka/selenium repository is a Go package that provides a simple and lightweight wrapper around the Selenium WebDriver API. It allows developers to automate web browsers and perform various testing and automation tasks using the Go programming language.

Pros

  • Cross-platform Compatibility: The package supports multiple web browsers, including Chrome, Firefox, and Safari, making it suitable for cross-browser testing.
  • Lightweight and Efficient: The package is designed to be lightweight and efficient, with a focus on simplicity and ease of use.
  • Actively Maintained: The project is actively maintained, with regular updates and bug fixes.
  • Extensive Documentation: The project has detailed documentation, including examples and usage guides, making it easy to get started.

Cons

  • Limited Browser Support: While the package supports multiple browsers, it may not have the same level of support and functionality as some other Selenium-based libraries.
  • Dependency on Selenium WebDriver: The package relies on the Selenium WebDriver, which means that users must have the appropriate WebDriver installed and configured for their target browser.
  • Potential Performance Issues: Depending on the complexity of the automation tasks, the package may experience performance issues, especially when working with large or complex web applications.
  • Limited Community Support: Compared to some other Selenium-based libraries, the tebeka/selenium package may have a smaller community and fewer resources available for troubleshooting and support.

Code Examples

Here are a few examples of how to use the tebeka/selenium package:

// Create a new Chrome browser instance
driver, err := selenium.NewChromeDriver()
if err != nil {
    // Handle error
}
defer driver.Quit()

// Navigate to a website
if err := driver.Get("https://www.example.com"); err != nil {
    // Handle error
}

// Find an element by its ID and click it
elem, err := driver.FindElement(selenium.ByID, "my-button")
if err != nil {
    // Handle error
}
if err := elem.Click(); err != nil {
    // Handle error
}
// Create a new Firefox browser instance
driver, err := selenium.NewFirefoxDriver()
if err != nil {
    // Handle error
}
defer driver.Quit()

// Navigate to a website and wait for a specific element to be present
if err := driver.Get("https://www.example.com"); err != nil {
    // Handle error
}
if err := driver.WaitForElement(selenium.ByID, "my-element", 10); err != nil {
    // Handle error
}
// Create a new Safari browser instance
driver, err := selenium.NewSafariDriver()
if err != nil {
    // Handle error
}
defer driver.Quit()

// Navigate to a website, find an element by its CSS selector, and send keys to it
if err := driver.Get("https://www.example.com"); err != nil {
    // Handle error
}
elem, err := driver.FindElement(selenium.ByCSSSelector, "input[name='my-input']")
if err != nil {
    // Handle error
}
if err := elem.SendKeys("Hello, World!"); err != nil {
    // Handle error
}

Getting Started

To get started with the tebeka/selenium package, follow these steps:

  1. Install the package using Go's package manager:

    go get github.com/tebeka/selenium
    
  2. Import the package in your Go code:

    import "github.com/tebeka/selenium"
    
  3. Create a new browser instance and interact with the web page:

    // Create a new Chrome browser instance
    driver, err := selenium.NewChromeDriver()
    if err != nil {
        // Handle error
    }
    defer driver.Quit()
    
    // Navigate to a website
    if err := driver.Get("https://www.example.com"); err != nil {
        // Handle error
    }
    
    // Find an element by its ID and click it
    elem, err := driver.FindElement(selenium.ByID, "my-button")
    if err != nil {
    

Competitor Comparisons

30,518

A browser automation framework and ecosystem.

Pros of SeleniumHQ/selenium

  • Larger and more active community with more contributors and issues/pull requests
  • Wider range of supported browsers and platforms
  • More comprehensive documentation and resources available

Cons of SeleniumHQ/selenium

  • Larger codebase and more complex to set up and configure
  • Slower release cycle and potentially longer wait times for bug fixes or new features
  • Steeper learning curve for new users

Code Comparison

tebeka/selenium:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.example.com")
print(driver.title)
driver.quit()

SeleniumHQ/selenium:

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

service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
driver.get("https://www.example.com")
print(driver.title)
driver.quit()
89,091

JavaScript API for Chrome and Firefox

Pros of Puppeteer

  • Puppeteer provides a more modern and streamlined API compared to Selenium, making it easier to write and maintain automated tests.
  • Puppeteer is a Node.js library, allowing for seamless integration with JavaScript-based web development workflows.
  • Puppeteer offers better performance and reliability compared to Selenium, especially for modern web applications.

Cons of Puppeteer

  • Puppeteer is primarily focused on Chrome/Chromium-based browsers, while Selenium supports a wider range of browsers, including Firefox, Safari, and Edge.
  • Puppeteer may have limited support for legacy browsers or older web technologies, which can be a concern for some projects.
  • Puppeteer's dependency on Node.js may not be suitable for all development environments, where Selenium's cross-platform support can be an advantage.

Code Comparison

Selenium (tebeka/selenium):

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://www.example.com")
element = driver.find_element(By.TAG_NAME, "h1")
print(element.text)
driver.quit()

Puppeteer (puppeteer/puppeteer):

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://www.example.com');
  const text = await page.$eval('h1', el => el.textContent);
  console.log(text);
  await browser.close();
})();
46,847

Fast, easy and reliable testing for anything that runs in a browser.

Pros of Cypress

  • Cypress provides a more user-friendly and intuitive API compared to Selenium, making it easier for developers to write and maintain tests.
  • Cypress has built-in support for time-travel debugging, which allows developers to step through their tests and see exactly what's happening at each step.
  • Cypress has a strong focus on end-to-end testing, with features like automatic waiting for elements and automatic retrying of failed commands.

Cons of Cypress

  • Cypress is primarily focused on end-to-end testing, while Selenium is a more general-purpose web automation tool that can be used for a wider range of tasks.
  • Cypress has a more limited set of supported browsers compared to Selenium, which supports a wide range of browsers and platforms.
  • Cypress may not be as suitable for testing complex, enterprise-level applications with a large number of dependencies and integrations.

Code Comparison

Selenium:

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://www.example.com")
element = driver.find_element(By.ID, "my-element")
element.click()

Cypress:

cy.visit('https://www.example.com')
cy.get('#my-element').click()

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

Pros of Playwright

  • Playwright provides a more modern and streamlined API compared to Selenium, making it easier to write and maintain test code.
  • Playwright supports multiple browsers (Chromium, Firefox, and WebKit) out of the box, reducing the need for browser-specific code.
  • Playwright's built-in support for handling common web application challenges, such as handling network requests and managing cookies, can simplify test implementation.

Cons of Playwright

  • Playwright is a newer project compared to Selenium, which has a larger community and more third-party libraries and tools available.
  • Playwright's cross-browser support, while improved, may still not be as comprehensive as Selenium's.
  • Migrating existing Selenium-based tests to Playwright may require significant effort and code changes.

Code Comparison

Selenium:

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://www.example.com")
element = driver.find_element(By.TAG_NAME, "h1")
print(element.text)
driver.quit()

Playwright:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("https://www.example.com")
    print(page.query_selector("h1").inner_text())
    browser.close()
18,791

Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol

Pros of Appium

  • Appium supports a wide range of mobile platforms, including iOS, Android, and Windows Phone, while Selenium primarily focuses on web browsers.
  • Appium provides a more comprehensive set of features for mobile app testing, including support for gestures, sensors, and device capabilities.
  • Appium's architecture is more modular and extensible, allowing for easier integration with other tools and frameworks.

Cons of Appium

  • Appium can be more complex to set up and configure, especially for beginners, compared to the relatively straightforward setup of Selenium.
  • Appium's performance and stability can be more variable, depending on the specific mobile devices and platforms being tested.

Code Comparison

Selenium:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.example.com")
title = driver.title
print(title)
driver.quit()

Appium:

from appium import webdriver
desired_caps = {
    "platformName": "Android",
    "deviceName": "emulator-5554",
    "appPackage": "com.example.app",
    "appActivity": "com.example.app.MainActivity"
}
driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
driver.find_element_by_id("button_id").click()
driver.quit()

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

The most complete, best-tested WebDriver client for Go

GoDoc Travis Go Report Card

About

This is a WebDriver client for Go. It supports the WebDriver protocol and has been tested with various versions of Selenium WebDriver, Firefox and Geckodriver, and Chrome and ChromeDriver,

selenium is currently maintained by Eric Garrido (@minusnine).

Installing

Run

go get -t -d github.com/tebeka/selenium

to fetch the package.

The package requires a working WebDriver installation, which can include recent versions of a web browser being driven by Selenium WebDriver.

Downloading Dependencies

We provide a means to download the ChromeDriver binary, the Firefox binary, the Selenium WebDriver JARs, and the Sauce Connect proxy binary. This is primarily intended for testing.

$ cd vendor
$ go run init.go --alsologtostderr  --download_browsers --download_latest
$ cd ..

Re-run this periodically to get up-to-date versions of these binaries.

Documentation

The API documentation is at https://godoc.org/github.com/tebeka/selenium. See the example and unit tests(for sauce, selenium and service) for better usage information.

Known Issues

Any issues are usually because the underlying browser automation framework has a bug or inconsistency. Where possible, we try to cover up these underlying problems in the client, but sometimes workarounds require higher-level intervention.

Please feel free to file an issue if this client doesn't work as expected.

Below are known issues that affect the usage of this API. There are likely others filed on the respective issue trackers.

Selenium 2

No longer supported.

Selenium 3

  1. Selenium 3 NewSession does not implement the W3C-specified parameters.

Geckodriver (Standalone)

  1. Geckodriver does not support the Log API because it hasn't been defined in the spec yet.
  2. Firefox via Geckodriver (and also through Selenium) doesn't handle clicking on an element.
  3. Firefox via Geckodriver doesn't handle sending control characters without appending a terminating null key.

Chromedriver

  1. Headless Chrome does not support running extensions.

Breaking Changes

There are a number of upcoming changes that break backward compatibility in an effort to improve and adapt the existing API. They are listed here:

22 August 2017

The Version constant was removed as it is unused.

18 April 2017

The Log method was changed to accept a typed constant for the type of log to retrieve, instead of a raw string. The return value was also changed to provide a more idiomatic type.

Hacking

Patches are encouraged through GitHub pull requests. Please ensure that:

  1. A test is added for anything more than a trivial change and that the existing tests pass. See below for instructions on setting up your test environment.

  2. Please ensure that gofmt has been run on the changed files before committing. Install a pre-commit hook with the following command:

    $ ln -s ../../misc/git/pre-commit .git/hooks/pre-commit

See the issue tracker for features that need implementing.

Testing Locally

Install xvfb and Java if they is not already installed, e.g.:

sudo apt-get install xvfb openjdk-11-jre

Run the tests:

$ go test
  • There is one top-level test for each of:

    1. Chromium and ChromeDriver.
    2. A new version of Firefox and Selenium 3.
    3. HTMLUnit, a Java-based lightweight headless browser implementation.
    4. A new version of Firefox directly against Geckodriver.

    There are subtests that are shared between both top-level tests.

  • To run only one of the top-level tests, pass one of:

    • -test.run=TestFirefoxSelenium3,
    • -test.run=TestFirefoxGeckoDriver,
    • -test.run=TestHTMLUnit, or
    • -test.run=TestChrome.

    To run a specific subtest, pass -test.run=Test<Browser>/<subtest> as appropriate. This flag supports regular expressions.

  • If the Chrome or Firefox binaries, the Selenium JAR, the Geckodriver binary, or the ChromeDriver binary cannot be found, the corresponding tests will be skipped.

  • The binaries and JAR under test can be configured by passing flags to go test. See the available flags with go test --arg --help.

  • Add the argument -test.v to see detailed output from the test automation framework.

Testing With Docker

To ensure hermeticity, we also have tests that run under Docker. You will need an installed and running Docker system.

To run the tests under Docker, run:

$ go test --docker

This will create a new Docker container and run the tests in it. (Note: flags supplied to this invocation are not curried through to the go test invocation within the Docker container).

For debugging Docker directly, run the following commands:

$ docker build -t go-selenium testing/
$ docker run --volume=$(pwd):/code --workdir=/code -it go-selenium bash
root@6c7951e41db6:/code# testing/docker-test.sh
... lots of testing output ...

Testing With Sauce Labs

Tests can be run using a browser located in the cloud via Sauce Labs.

To run the tests under Sauce, run:

$ go test --test.run=TestSauce --test.timeout=20m \
  --experimental_enable_sauce \
  --sauce_user_name=[username goes here] \
  --sauce_access_key=[access key goes here]

The Sauce access key can be obtained via the Sauce Labs user settings page.

Test results can be viewed through the Sauce Labs Dashboard.

License

This project is licensed under the MIT license.

NPM DownloadsLast 30 Days