Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b271cbd

Browse files
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‎

Lines changed: 15 additions & 0 deletions
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+
}
Lines changed: 30 additions & 0 deletions
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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎examples/java/build.gradle‎

Lines changed: 2 additions & 1 deletion
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‎

Lines changed: 11 additions & 21 deletions
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‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

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

Lines changed: 10 additions & 4 deletions
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() throwsIOException{
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
Lines changed: 31 additions & 0 deletions
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‎

Lines changed: 1 addition & 1 deletion
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() {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /