Skip to content

Commit

Permalink
rename page and add section on Usage
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 15, 2023
1 parent 7be8bee commit 1145be8
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
namespace SeleniumDocs.GettingStarted
{
[TestClass]
public class RunningTestsTest
public class UsingSeleniumTest
{

[TestMethod]
public void ChromeSession()
public void EightComponents()
{
IWebDriver driver = new ChromeDriver();

Expand Down
14 changes: 10 additions & 4 deletions examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Pdf;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
import org.openqa.selenium.print.PrintOptions;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.regex.Pattern;

public class ChromeTest {
Expand All @@ -35,9 +36,14 @@ public void quit() {
}

@Test
public void basicOptions() {
public void basicOptions() throws IOException {
ChromeOptions options = new ChromeOptions();
driver = new ChromeDriver(options);
driver.get("https://www.selenium.dev");

String content = driver.print(new PrintOptions()).getContent();
byte[] bytes = Base64.getDecoder().decode(content);
Files.write(Paths.get("printed.pdf"), bytes);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

public class RunningTestsTest {
public class UsingSelenium {

@Test
public void eightComponents() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.selenium.interactions;

import dev.selenium.BaseChromeTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.print.PrintOptions;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;

public class SavingTest extends BaseChromeTest {
@Test
public void prints() throws IOException {
driver.get("https://www.selenium.dev");

String content = ((RemoteWebDriver) driver).print(new PrintOptions()).getContent();
byte[] bytes = Base64.getDecoder().decode(content);
Files.write(Paths.get("selenium.pdf"), bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'spec_helper'

RSpec.describe 'Running Tests' do
RSpec.describe 'Using Selenium' do
it 'uses eight components' do
driver = Selenium::WebDriver.for :chrome

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,52 @@
---
title: "Organizing and Executing Selenium in Tests"
linkTitle: "Running Tests"
title: "Organizing and Executing Selenium Code"
linkTitle: "Using Selenium"
weight: 10
description: >
Scaling Selenium execution with a Test Runner Framework
Scaling Selenium execution with an IDE and a Test Runner library
---

{{< alert-content >}}
This page is very incomplete and has placeholders for things that need to be added or expounded on.
{{< /alert-content >}}

If you want to run more than a handful of one-off scripts, you need to
be able to organize and work with your code.
Most people use Selenium for testing, so that is the context that often
gets used to talk about executing Selenium code, so it is worth giving
an overview of how to use Selenium in this context.
Running Selenium in tests requires making assertions and using common setup and teardown code.
It often involves running multiple sessions in parallel,
and sometimes running specific subsets of sessions.
be able to organize and work with your code. This page should give you
ideas for how to actually do productive things with your Selenium code.

## Common Uses

Most people use Selenium to execute automated tests for web applications,
but Selenium support any use case of browser automation.

### Repetitive Tasks

### Testing

Running Selenium for testing requires making assertions on actions taken by Selenium.
So a good assertion library is required. Additional features to provide structure for tests
require use of [Test Runner](#test-runners)


## IDEs

First and foremost, you won't be very effective in building out a test suite without a good
Regardless of how you use Selenium code,
you won't be very effective writing or executing it without a good
Integrated Developer Environment. Here are some common options...

* Eclipse
* IntelliJ
* PyCharm
* RubyMine
* Rider
* WebStorm
* VS Code

## Test Runners
## Test Runner

Even if you aren't using Selenium for testing, if you have advanced use cases, it might make
sense to use a test runner to better organize your code. Being able to use before/after hooks
and run things in groups or in parallel can be very useful.

### Choosing
There are many different test runners available.
Expand Down Expand Up @@ -145,7 +169,7 @@ Use the Java bindings for Kotlin.
### Executing

{{< tabpane text=true langEqualsHeader=true >}}
{{< tab header="Java" >}}
{{% tab header="Java" %}}
### Maven

```shell
Expand All @@ -158,7 +182,7 @@ mvn clean test
gradle clean test
```

{{< /tab >}}
{{% /tab %}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{% /tab %}}
Expand All @@ -168,11 +192,11 @@ gradle clean test
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{% tab header="JavaScript" %}}
```shell
mocha runningTests.spec.js
```
{{< /tab >}}
{{% /tab %}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -185,16 +209,16 @@ Here's an example of that code using a test runner:

{{< tabpane text=true langEqualsHeader=true >}}
{{< tab header="Java" >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/RunningTestsTest.java" >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="examples/python/tests/getting_started/test_running_tests.py" >}}
{{< gh-codeblock path="examples/python/tests/getting_started/using_selenium_tests.py" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/RunningTestsTest.cs" >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< gh-codeblock path="examples/ruby/spec/getting_started/running_tests_spec.rb" >}}
{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
---
title: "Organizing and Executing Selenium in Tests"
linkTitle: "Running Tests"
title: "Organizing and Executing Selenium Code"
linkTitle: "Using Selenium"
weight: 10
description: >
Scaling Selenium execution with a Test Runner Framework
Scaling Selenium execution with an IDE and a Test Runner library
---

If you want to run more than a handful of one-off scripts, you need to
be able to organize and work with your code.
Most people use Selenium for testing, so that is the context that often
gets used to talk about executing Selenium code, so it is worth giving
an overview of how to use Selenium in this context.
Running Selenium in tests requires making assertions and using common setup and teardown code.
It often involves running multiple sessions in parallel,
and sometimes running specific subsets of sessions.
be able to organize and work with your code. This page should give you
ideas for how to actually do productive things with your Selenium code.

## Common Uses

Most people use Selenium to execute automated tests for web applications,
but Selenium support any use case of browser automation.

### Repetitive Tasks

### Testing

Running Selenium for testing requires making assertions on actions taken by Selenium.
So a good assertion library is required. Additional features to provide structure for tests
require use of [Test Runner](#test-runners)


## IDEs

First and foremost, you won't be very effective in building out a test suite without a good
Regardless of how you use Selenium code,
you won't be very effective writing or executing it without a good
Integrated Developer Environment. Here are some common options...

* Eclipse
* IntelliJ
* PyCharm
* RubyMine
* Rider
* WebStorm
* VS Code

## Test Runner

## Test Runners
Even if you aren't using Selenium for testing, if you have advanced use cases, it might make
sense to use a test runner to better organize your code. Being able to use before/after hooks
and run things in groups or in parallel can be very useful.

### Choosing
There are many different test runners available.
Expand Down Expand Up @@ -145,7 +165,7 @@ Use the Java bindings for Kotlin.
### Executing

{{< tabpane text=true langEqualsHeader=true >}}
{{< tab header="Java" >}}
{{% tab header="Java" %}}
### Maven

```shell
Expand All @@ -158,7 +178,7 @@ mvn clean test
gradle clean test
```

{{< /tab >}}
{{% /tab %}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{% /tab %}}
Expand All @@ -168,11 +188,11 @@ gradle clean test
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{% tab header="JavaScript" %}}
```shell
mocha runningTests.spec.js
```
{{< /tab >}}
{{% /tab %}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -185,16 +205,16 @@ Here's an example of that code using a test runner:

{{< tabpane text=true langEqualsHeader=true >}}
{{< tab header="Java" >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/RunningTestsTest.java" >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="examples/python/tests/getting_started/test_running_tests.py" >}}
{{< gh-codeblock path="examples/python/tests/getting_started/using_selenium_tests.py" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/RunningTestsTest.cs" >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< gh-codeblock path="examples/ruby/spec/getting_started/running_tests_spec.rb" >}}
{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
Expand Down
Loading

0 comments on commit 1145be8

Please sign in to comment.