Skip to content

Commit b271cbd

Browse files
authoredOct 6, 2023
Create new Getting Started page for Running Tests (#1479)
* first script should not use a test runner and can be executed standalone * move hello selenium out of SeleniumDocs * rename page and add section on Usage * add examples and links [deploy site]
1 parent c5e63e2 commit b271cbd

35 files changed

+1394
-700
lines changed
 

‎examples/dotnet/HelloSelenium.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using OpenQA.Selenium.Chrome;
2+
3+
namespace SeleniumDocs.Hello;
4+
5+
public static class HelloSelenium
6+
{
7+
public static void Main()
8+
{
9+
var driver = new ChromeDriver();
10+
11+
driver.Navigate().GoToUrl("https://selenium.dev");
12+
13+
driver.Quit();
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using OpenQA.Selenium;
3+
using OpenQA.Selenium.Chrome;
4+
5+
namespace SeleniumDocs.GettingStarted;
6+
7+
public static class FirstScript
8+
{
9+
public static void Main()
10+
{
11+
IWebDriver driver = new ChromeDriver();
12+
13+
driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/web-form.html");
14+
15+
var title = driver.Title;
16+
17+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);
18+
19+
var textBox = driver.FindElement(By.Name("my-text"));
20+
var submitButton = driver.FindElement(By.TagName("button"));
21+
22+
textBox.SendKeys("Selenium");
23+
submitButton.Click();
24+
25+
var message = driver.FindElement(By.Id("message"));
26+
var value = message.Text;
27+
28+
driver.Quit();
29+
}
30+
}

‎examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs renamed to ‎examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
namespace SeleniumDocs.GettingStarted
77
{
88
[TestClass]
9-
public class FirstScriptTest
9+
public class UsingSeleniumTest
1010
{
1111

1212
[TestMethod]
13-
public void ChromeSession()
13+
public void EightComponents()
1414
{
1515
IWebDriver driver = new ChromeDriver();
1616

‎examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs

-16
This file was deleted.

‎examples/java/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ repositories {
1111

1212
dependencies {
1313
testImplementation 'org.seleniumhq.selenium:selenium-java:4.13.0'
14-
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
14+
testImplementation 'org.seleniumhq.selenium:selenium-http-jdk-client:4.13.0'
15+
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
1516
}
1617

1718
test {

‎examples/java/pom.xml

+11-21
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99
<version>1.0.0</version>
1010

1111
<properties>
12-
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
13-
<java.version>8</java.version>
14-
<maven.compiler.target>${java.version}</maven.compiler.target>
15-
<maven.compiler.source>${java.version}</maven.compiler.source>
16-
<project.encoding>UTF-8</project.encoding>
17-
<project.build.sourceEncoding>${project.encoding}</project.build.sourceEncoding>
18-
<project.reporting.outputEncoding>${project.encoding}</project.reporting.outputEncoding>
12+
<maven.compiler.target>1.8</maven.compiler.target>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1915
</properties>
2016

2117
<repositories>
@@ -35,19 +31,14 @@
3531
<version>4.13.0</version>
3632
</dependency>
3733
<dependency>
38-
<groupId>org.slf4j</groupId>
39-
<artifactId>slf4j-api</artifactId>
40-
<version>2.0.5</version>
41-
</dependency>
42-
<dependency>
43-
<groupId>ch.qos.logback</groupId>
44-
<artifactId>logback-classic</artifactId>
45-
<version>1.4.6</version>
34+
<groupId>org.seleniumhq.selenium</groupId>
35+
<artifactId>selenium-http-jdk-client</artifactId>
36+
<version>4.13.0</version>
4637
</dependency>
4738
<dependency>
4839
<groupId>org.junit.jupiter</groupId>
4940
<artifactId>junit-jupiter-engine</artifactId>
50-
<version>5.9.2</version>
41+
<version>5.10.0</version>
5142
<scope>test</scope>
5243
</dependency>
5344
</dependencies>
@@ -57,12 +48,11 @@
5748
<plugin>
5849
<groupId>org.apache.maven.plugins</groupId>
5950
<artifactId>maven-surefire-plugin</artifactId>
60-
<version>${maven-surefire-plugin.version}</version>
51+
<version>3.1.2</version>
6152
<configuration>
62-
<includes>
63-
<include>**/*Test.java</include>
64-
<include>**/*Example.java</include>
65-
</includes>
53+
<systemPropertyVariables>
54+
<webdriver.http.factory>jdk-http-client</webdriver.http.factory>
55+
</systemPropertyVariables>
6656
</configuration>
6757
</plugin>
6858
</plugins>

‎examples/java/src/main/resources/logback.xml

-16
This file was deleted.

‎examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
import org.junit.jupiter.api.Assertions;
66
import org.junit.jupiter.api.Test;
77
import org.openqa.selenium.By;
8+
import org.openqa.selenium.Pdf;
89
import org.openqa.selenium.WebElement;
910
import org.openqa.selenium.chrome.ChromeDriver;
1011
import org.openqa.selenium.chrome.ChromeDriverService;
1112
import org.openqa.selenium.chrome.ChromeOptions;
1213
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
14+
import org.openqa.selenium.print.PrintOptions;
1315

14-
import java.io.File;
15-
import java.io.IOException;
16-
import java.io.PrintStream;
16+
import java.io.*;
1717
import java.nio.file.Files;
1818
import java.nio.file.Path;
1919
import java.nio.file.Paths;
20+
import java.util.Base64;
2021
import java.util.regex.Pattern;
2122

2223
public class ChromeTest {
@@ -35,9 +36,14 @@ public void quit() {
3536
}
3637

3738
@Test
38-
public void basicOptions() {
39+
public void basicOptions() throws IOException {
3940
ChromeOptions options = new ChromeOptions();
4041
driver = new ChromeDriver(options);
42+
driver.get("https://www.selenium.dev");
43+
44+
String content = driver.print(new PrintOptions()).getContent();
45+
byte[] bytes = Base64.getDecoder().decode(content);
46+
Files.write(Paths.get("printed.pdf"), bytes);
4147
}
4248

4349
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dev.selenium.getting_started;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.WebDriver;
5+
import org.openqa.selenium.WebElement;
6+
import org.openqa.selenium.chrome.ChromeDriver;
7+
8+
import java.time.Duration;
9+
10+
public class FirstScript {
11+
public static void main(String[] args) {
12+
WebDriver driver = new ChromeDriver();
13+
14+
driver.get("https://www.selenium.dev/selenium/web/web-form.html");
15+
16+
driver.getTitle();
17+
18+
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
19+
20+
WebElement textBox = driver.findElement(By.name("my-text"));
21+
WebElement submitButton = driver.findElement(By.cssSelector("button"));
22+
23+
textBox.sendKeys("Selenium");
24+
submitButton.click();
25+
26+
WebElement message = driver.findElement(By.id("message"));
27+
message.getText();
28+
29+
driver.quit();
30+
}
31+
}

‎examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java renamed to ‎examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

13-
public class FirstScriptTest {
13+
public class UsingSeleniumTest {
1414

1515
@Test
1616
public void eightComponents() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dev.selenium.interactions;
2+
3+
import dev.selenium.BaseChromeTest;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
import org.openqa.selenium.By;
7+
import org.openqa.selenium.NoSuchElementException;
8+
import org.openqa.selenium.print.PrintOptions;
9+
import org.openqa.selenium.remote.RemoteWebDriver;
10+
11+
import java.io.IOException;
12+
import java.nio.file.Files;
13+
import java.nio.file.Paths;
14+
import java.util.Base64;
15+
16+
public class SavingTest extends BaseChromeTest {
17+
@Test
18+
public void prints() throws IOException {
19+
driver.get("https://www.selenium.dev");
20+
21+
String content = ((RemoteWebDriver) driver).print(new PrintOptions()).getContent();
22+
byte[] bytes = Base64.getDecoder().decode(content);
23+
Files.write(Paths.get("selenium.pdf"), bytes);
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from selenium import webdriver
2+
from selenium.webdriver.common.by import By
3+
4+
driver = webdriver.Chrome()
5+
6+
driver.get("https://www.selenium.dev/selenium/web/web-form.html")
7+
8+
title = driver.title
9+
10+
driver.implicitly_wait(0.5)
11+
12+
text_box = driver.find_element(by=By.NAME, value="my-text")
13+
submit_button = driver.find_element(by=By.CSS_SELECTOR, value="button")
14+
15+
text_box.send_keys("Selenium")
16+
submit_button.click()
17+
18+
message = driver.find_element(by=By.ID, value="message")
19+
text = message.text
20+
21+
driver.quit()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'selenium-webdriver'
2+
3+
driver = Selenium::WebDriver.for :chrome
4+
5+
driver.get('https://www.selenium.dev/selenium/web/web-form.html')
6+
7+
driver.title
8+
9+
driver.manage.timeouts.implicit_wait = 500
10+
11+
text_box = driver.find_element(name: 'my-text')
12+
submit_button = driver.find_element(tag_name: 'button')
13+
14+
text_box.send_keys('Selenium')
15+
submit_button.click
16+
17+
message = driver.find_element(id: 'message')
18+
message.text
19+
20+
driver.quit

‎examples/ruby/spec/getting_started/first_script_spec.rb renamed to ‎examples/ruby/spec/getting_started/using_selenium_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe 'First Script' do
5+
RSpec.describe 'Using Selenium' do
66
it 'uses eight components' do
77
driver = Selenium::WebDriver.for :chrome
88

‎website_and_docs/content/documentation/_index.en.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ a browser. You can find a more comprehensive example in [Writing your first Sele
3939
{{< gh-codeblock path="/examples/python/tests/hello/hello_selenium.py" >}}
4040
{{< /tab >}}
4141
{{< tab header="CSharp" >}}
42-
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs" >}}
42+
{{< gh-codeblock path="/examples/dotnet/HelloSelenium.cs" >}}
4343
{{< /tab >}}
4444
{{< tab header="Ruby" >}}
4545
{{< gh-codeblock path="/examples/ruby/spec/hello/hello_selenium_spec.rb" >}}
@@ -59,6 +59,3 @@ You should continue on to [Getting Started]({{< ref "webdriver/getting_started"
5959
to understand how you can install Selenium and successfully use it as a test
6060
automation tool, and scaling simple tests like this to run in large, distributed
6161
environments on multiple browsers, on several different operating systems.
62-
63-
64-

‎website_and_docs/content/documentation/_index.ja.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Seleniumの中核は[WebDriver]({{< ref "/webdriver.md" >}})であり、様々
2626
{{< gh-codeblock path="/examples/python/tests/hello/hello_selenium.py" >}}
2727
{{< /tab >}}
2828
{{< tab header="CSharp" >}}
29-
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs" >}}
29+
{{< gh-codeblock path="/examples/dotnet/HelloSelenium.cs" >}}
3030
{{< /tab >}}
3131
{{< tab header="Ruby" >}}
3232
{{< gh-codeblock path="/examples/ruby/spec/hello/hello_selenium_spec.rb" >}}
@@ -48,6 +48,3 @@ Seleniumが適切なツールであるかどうかを判断してください。
4848
Seleniumをインストールし、テスト自動化ツールとして正常に使用する方法を理解し、
4949
このような単純なテストをスケーリングして、複数のブラウザー、
5050
複数の異なるオペレーティングシステムの大規模な分散環境で実行する必要があります。
51-
52-
53-

‎website_and_docs/content/documentation/_index.pt-br.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ navegadores. Aqui está uma das instruções mais simples que você pode fazer:
3737
{{< gh-codeblock path="/examples/python/tests/hello/hello_selenium.py" >}}
3838
{{< /tab >}}
3939
{{< tab header="CSharp" >}}
40-
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs" >}}
40+
{{< gh-codeblock path="/examples/dotnet/HelloSelenium.cs" >}}
4141
{{< /tab >}}
4242
{{< tab header="Ruby" >}}
4343
{{< gh-codeblock path="/examples/ruby/spec/hello/hello_selenium_spec.rb" >}}

‎website_and_docs/content/documentation/_index.zh-cn.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Selenium 的核心是 [WebDriver]({{< ref "/webdriver.md" >}}),这是一个编
3131
{{< gh-codeblock path="/examples/python/tests/hello/hello_selenium.py" >}}
3232
{{< /tab >}}
3333
{{< tab header="CSharp" >}}
34-
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs" >}}
34+
{{< gh-codeblock path="/examples/dotnet/HelloSelenium.cs" >}}
3535
{{< /tab >}}
3636
{{< tab header="Ruby" >}}
3737
{{< gh-codeblock path="/examples/ruby/spec/hello/hello_selenium_spec.rb" >}}
@@ -56,4 +56,3 @@ Selenium 的核心是 [WebDriver]({{< ref "/webdriver.md" >}}),这是一个编
5656
在大型分布式环境,
5757
以及不同操作系统上的环境上
5858
运行多个浏览器的测试.
59-

0 commit comments

Comments
 (0)