From b271cbdbb0731ee05ccae0129c4c9f0e15a5513d Mon Sep 17 00:00:00 2001 From: Titus Fortner Date: Fri, 6 Oct 2023 16:34:40 -0500 Subject: [PATCH] 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] --- examples/dotnet/HelloSelenium.cs | 15 ++ .../GettingStarted/FirstScript.cs | 30 +++ ...irstScriptTest.cs => UsingSeleniumTest.cs} | 4 +- .../SeleniumDocs/Hello/HelloSelenium.cs | 16 -- examples/java/build.gradle | 3 +- examples/java/pom.xml | 32 +-- examples/java/src/main/resources/logback.xml | 16 -- .../dev/selenium/browsers/ChromeTest.java | 14 +- .../selenium/getting_started/FirstScript.java | 31 +++ ...ScriptTest.java => UsingSeleniumTest.java} | 2 +- .../dev/selenium/interactions/SavingTest.java | 25 ++ .../tests/getting_started/first_script.py | 21 ++ ...irst_script.py => using_selenium_tests.py} | 0 .../ruby/spec/getting_started/first_script.rb | 20 ++ ..._script_spec.rb => using_selenium_spec.rb} | 2 +- .../content/documentation/_index.en.md | 5 +- .../content/documentation/_index.ja.md | 5 +- .../content/documentation/_index.pt-br.md | 2 +- .../content/documentation/_index.zh-cn.md | 3 +- .../content/documentation/about/style.en.md | 28 +- .../content/documentation/about/style.ja.md | 28 +- .../documentation/about/style.pt-br.md | 28 +- .../documentation/about/style.zh-cn.md | 28 +- .../getting_started/first_script.en.md | 180 +++---------- .../getting_started/first_script.ja.md | 184 ++++--------- .../getting_started/first_script.pt-br.md | 183 ++++--------- .../getting_started/first_script.zh-cn.md | 189 ++++--------- .../getting_started/install_library.en.md | 6 +- .../getting_started/install_library.ja.md | 6 +- .../getting_started/install_library.pt-br.md | 4 +- .../getting_started/install_library.zh-cn.md | 4 +- .../getting_started/using_selenium.en.md | 248 ++++++++++++++++++ .../getting_started/using_selenium.ja.md | 244 +++++++++++++++++ .../getting_started/using_selenium.pt-br.md | 244 +++++++++++++++++ .../getting_started/using_selenium.zh-cn.md | 244 +++++++++++++++++ 35 files changed, 1394 insertions(+), 700 deletions(-) create mode 100644 examples/dotnet/HelloSelenium.cs create mode 100644 examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs rename examples/dotnet/SeleniumDocs/GettingStarted/{FirstScriptTest.cs => UsingSeleniumTest.cs} (93%) delete mode 100644 examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs delete mode 100644 examples/java/src/main/resources/logback.xml create mode 100644 examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java rename examples/java/src/test/java/dev/selenium/getting_started/{FirstScriptTest.java => UsingSeleniumTest.java} (96%) create mode 100644 examples/java/src/test/java/dev/selenium/interactions/SavingTest.java create mode 100644 examples/python/tests/getting_started/first_script.py rename examples/python/tests/getting_started/{test_first_script.py => using_selenium_tests.py} (100%) create mode 100644 examples/ruby/spec/getting_started/first_script.rb rename examples/ruby/spec/getting_started/{first_script_spec.rb => using_selenium_spec.rb} (94%) create mode 100644 website_and_docs/content/documentation/webdriver/getting_started/using_selenium.en.md create mode 100644 website_and_docs/content/documentation/webdriver/getting_started/using_selenium.ja.md create mode 100644 website_and_docs/content/documentation/webdriver/getting_started/using_selenium.pt-br.md create mode 100644 website_and_docs/content/documentation/webdriver/getting_started/using_selenium.zh-cn.md diff --git a/examples/dotnet/HelloSelenium.cs b/examples/dotnet/HelloSelenium.cs new file mode 100644 index 000000000000..01815c130847 --- /dev/null +++ b/examples/dotnet/HelloSelenium.cs @@ -0,0 +1,15 @@ +using OpenQA.Selenium.Chrome; + +namespace SeleniumDocs.Hello; + +public static class HelloSelenium +{ + public static void Main() + { + var driver = new ChromeDriver(); + + driver.Navigate().GoToUrl("https://selenium.dev"); + + driver.Quit(); + } +} \ No newline at end of file diff --git a/examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs b/examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs new file mode 100644 index 000000000000..d47807897fd4 --- /dev/null +++ b/examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs @@ -0,0 +1,30 @@ +using System; +using OpenQA.Selenium; +using OpenQA.Selenium.Chrome; + +namespace SeleniumDocs.GettingStarted; + +public static class FirstScript +{ + public static void Main() + { + IWebDriver driver = new ChromeDriver(); + + driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/web-form.html"); + + var title = driver.Title; + + driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500); + + var textBox = driver.FindElement(By.Name("my-text")); + var submitButton = driver.FindElement(By.TagName("button")); + + textBox.SendKeys("Selenium"); + submitButton.Click(); + + var message = driver.FindElement(By.Id("message")); + var value = message.Text; + + driver.Quit(); + } +} \ No newline at end of file diff --git a/examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs b/examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs similarity index 93% rename from examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs rename to examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs index 2507ddc63dc6..fbae2c3ff023 100644 --- a/examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs +++ b/examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs @@ -6,11 +6,11 @@ namespace SeleniumDocs.GettingStarted { [TestClass] - public class FirstScriptTest + public class UsingSeleniumTest { [TestMethod] - public void ChromeSession() + public void EightComponents() { IWebDriver driver = new ChromeDriver(); diff --git a/examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs b/examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs deleted file mode 100644 index 7d97ad8b4b90..000000000000 --- a/examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs +++ /dev/null @@ -1,16 +0,0 @@ -using OpenQA.Selenium.Chrome; - -namespace SeleniumDocs.Hello -{ - public class HelloSelenium - { - public static void Main() - { - var driver = new ChromeDriver(); - - driver.Navigate().GoToUrl("https://selenium.dev"); - - driver.Quit(); - } - } -} \ No newline at end of file diff --git a/examples/java/build.gradle b/examples/java/build.gradle index 7f379b764250..cf58c37736a1 100644 --- a/examples/java/build.gradle +++ b/examples/java/build.gradle @@ -11,7 +11,8 @@ repositories { dependencies { testImplementation 'org.seleniumhq.selenium:selenium-java:4.13.0' - testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.0' + testImplementation 'org.seleniumhq.selenium:selenium-http-jdk-client:4.13.0' + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0' } test { diff --git a/examples/java/pom.xml b/examples/java/pom.xml index 7f6768f38713..8f92e6eb4628 100644 --- a/examples/java/pom.xml +++ b/examples/java/pom.xml @@ -9,13 +9,9 @@ 1.0.0 - 3.0.0-M7 - 8 - ${java.version} - ${java.version} - UTF-8 - ${project.encoding} - ${project.encoding} + 1.8 + 1.8 + UTF-8 @@ -35,19 +31,14 @@ 4.13.0 - org.slf4j - slf4j-api - 2.0.5 - - - ch.qos.logback - logback-classic - 1.4.6 + org.seleniumhq.selenium + selenium-http-jdk-client + 4.13.0 org.junit.jupiter junit-jupiter-engine - 5.9.2 + 5.10.0 test @@ -57,12 +48,11 @@ org.apache.maven.plugins maven-surefire-plugin - ${maven-surefire-plugin.version} + 3.1.2 - - **/*Test.java - **/*Example.java - + + jdk-http-client + diff --git a/examples/java/src/main/resources/logback.xml b/examples/java/src/main/resources/logback.xml deleted file mode 100644 index 8cf4f8f82662..000000000000 --- a/examples/java/src/main/resources/logback.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n - - - - - - - - - - - diff --git a/examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java b/examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java index 703ee94f08e4..6bc06013094f 100644 --- a/examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java +++ b/examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java @@ -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 { @@ -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 diff --git a/examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java b/examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java new file mode 100644 index 000000000000..3f8f37620692 --- /dev/null +++ b/examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java @@ -0,0 +1,31 @@ +package dev.selenium.getting_started; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; + +import java.time.Duration; + +public class FirstScript { + public static void main(String[] args) { + WebDriver driver = new ChromeDriver(); + + driver.get("https://www.selenium.dev/selenium/web/web-form.html"); + + driver.getTitle(); + + driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500)); + + WebElement textBox = driver.findElement(By.name("my-text")); + WebElement submitButton = driver.findElement(By.cssSelector("button")); + + textBox.sendKeys("Selenium"); + submitButton.click(); + + WebElement message = driver.findElement(By.id("message")); + message.getText(); + + driver.quit(); + } +} diff --git a/examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java b/examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java similarity index 96% rename from examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java rename to examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java index d37179231774..5b314f68be9d 100644 --- a/examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java +++ b/examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java @@ -10,7 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class FirstScriptTest { +public class UsingSeleniumTest { @Test public void eightComponents() { diff --git a/examples/java/src/test/java/dev/selenium/interactions/SavingTest.java b/examples/java/src/test/java/dev/selenium/interactions/SavingTest.java new file mode 100644 index 000000000000..2d0b197fc2c5 --- /dev/null +++ b/examples/java/src/test/java/dev/selenium/interactions/SavingTest.java @@ -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); + } +} diff --git a/examples/python/tests/getting_started/first_script.py b/examples/python/tests/getting_started/first_script.py new file mode 100644 index 000000000000..68a62f8f26b8 --- /dev/null +++ b/examples/python/tests/getting_started/first_script.py @@ -0,0 +1,21 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By + +driver = webdriver.Chrome() + +driver.get("https://www.selenium.dev/selenium/web/web-form.html") + +title = driver.title + +driver.implicitly_wait(0.5) + +text_box = driver.find_element(by=By.NAME, value="my-text") +submit_button = driver.find_element(by=By.CSS_SELECTOR, value="button") + +text_box.send_keys("Selenium") +submit_button.click() + +message = driver.find_element(by=By.ID, value="message") +text = message.text + +driver.quit() diff --git a/examples/python/tests/getting_started/test_first_script.py b/examples/python/tests/getting_started/using_selenium_tests.py similarity index 100% rename from examples/python/tests/getting_started/test_first_script.py rename to examples/python/tests/getting_started/using_selenium_tests.py diff --git a/examples/ruby/spec/getting_started/first_script.rb b/examples/ruby/spec/getting_started/first_script.rb new file mode 100644 index 000000000000..ecfd584eb13d --- /dev/null +++ b/examples/ruby/spec/getting_started/first_script.rb @@ -0,0 +1,20 @@ +require 'selenium-webdriver' + +driver = Selenium::WebDriver.for :chrome + +driver.get('https://www.selenium.dev/selenium/web/web-form.html') + +driver.title + +driver.manage.timeouts.implicit_wait = 500 + +text_box = driver.find_element(name: 'my-text') +submit_button = driver.find_element(tag_name: 'button') + +text_box.send_keys('Selenium') +submit_button.click + +message = driver.find_element(id: 'message') +message.text + +driver.quit diff --git a/examples/ruby/spec/getting_started/first_script_spec.rb b/examples/ruby/spec/getting_started/using_selenium_spec.rb similarity index 94% rename from examples/ruby/spec/getting_started/first_script_spec.rb rename to examples/ruby/spec/getting_started/using_selenium_spec.rb index ed278ee0db71..e371cf3699bc 100644 --- a/examples/ruby/spec/getting_started/first_script_spec.rb +++ b/examples/ruby/spec/getting_started/using_selenium_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe 'First Script' do +RSpec.describe 'Using Selenium' do it 'uses eight components' do driver = Selenium::WebDriver.for :chrome diff --git a/website_and_docs/content/documentation/_index.en.md b/website_and_docs/content/documentation/_index.en.md index 91e46f92826e..c95f43614964 100755 --- a/website_and_docs/content/documentation/_index.en.md +++ b/website_and_docs/content/documentation/_index.en.md @@ -39,7 +39,7 @@ a browser. You can find a more comprehensive example in [Writing your first Sele {{< gh-codeblock path="/examples/python/tests/hello/hello_selenium.py" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs" >}} +{{< gh-codeblock path="/examples/dotnet/HelloSelenium.cs" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< 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" to understand how you can install Selenium and successfully use it as a test automation tool, and scaling simple tests like this to run in large, distributed environments on multiple browsers, on several different operating systems. - - - diff --git a/website_and_docs/content/documentation/_index.ja.md b/website_and_docs/content/documentation/_index.ja.md index 2c6636d9099f..d029d0c6282f 100755 --- a/website_and_docs/content/documentation/_index.ja.md +++ b/website_and_docs/content/documentation/_index.ja.md @@ -26,7 +26,7 @@ Seleniumの中核は[WebDriver]({{< ref "/webdriver.md" >}})であり、様々 {{< gh-codeblock path="/examples/python/tests/hello/hello_selenium.py" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs" >}} +{{< gh-codeblock path="/examples/dotnet/HelloSelenium.cs" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< gh-codeblock path="/examples/ruby/spec/hello/hello_selenium_spec.rb" >}} @@ -48,6 +48,3 @@ Seleniumが適切なツールであるかどうかを判断してください。 Seleniumをインストールし、テスト自動化ツールとして正常に使用する方法を理解し、 このような単純なテストをスケーリングして、複数のブラウザー、 複数の異なるオペレーティングシステムの大規模な分散環境で実行する必要があります。 - - - diff --git a/website_and_docs/content/documentation/_index.pt-br.md b/website_and_docs/content/documentation/_index.pt-br.md index 2ab9802dffe8..e997ed77375f 100755 --- a/website_and_docs/content/documentation/_index.pt-br.md +++ b/website_and_docs/content/documentation/_index.pt-br.md @@ -37,7 +37,7 @@ navegadores. Aqui está uma das instruções mais simples que você pode fazer: {{< gh-codeblock path="/examples/python/tests/hello/hello_selenium.py" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs" >}} +{{< gh-codeblock path="/examples/dotnet/HelloSelenium.cs" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< gh-codeblock path="/examples/ruby/spec/hello/hello_selenium_spec.rb" >}} diff --git a/website_and_docs/content/documentation/_index.zh-cn.md b/website_and_docs/content/documentation/_index.zh-cn.md index 80d7a851b3ce..c504405d119f 100755 --- a/website_and_docs/content/documentation/_index.zh-cn.md +++ b/website_and_docs/content/documentation/_index.zh-cn.md @@ -31,7 +31,7 @@ Selenium 的核心是 [WebDriver]({{< ref "/webdriver.md" >}}),这是一个编 {{< gh-codeblock path="/examples/python/tests/hello/hello_selenium.py" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Hello/HelloSelenium.cs" >}} +{{< gh-codeblock path="/examples/dotnet/HelloSelenium.cs" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< gh-codeblock path="/examples/ruby/spec/hello/hello_selenium_spec.rb" >}} @@ -56,4 +56,3 @@ Selenium 的核心是 [WebDriver]({{< ref "/webdriver.md" >}}),这是一个编 在大型分布式环境, 以及不同操作系统上的环境上 运行多个浏览器的测试. - diff --git a/website_and_docs/content/documentation/about/style.en.md b/website_and_docs/content/documentation/about/style.en.md index ac9ab15b8cfb..4a13447b6c07 100644 --- a/website_and_docs/content/documentation/about/style.en.md +++ b/website_and_docs/content/documentation/about/style.en.md @@ -152,16 +152,16 @@ A basic comparison of code looks like: {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} {{}} @@ -175,16 +175,16 @@ Which looks like this: {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L46-L47" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L46-L47" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L17-L18" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L17-L18" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L39-L40" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L39-L40" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L16-L17" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L16-L17" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L23-L24" >}} @@ -203,11 +203,11 @@ then change the Hugo syntax for the `tab`to use `%` instead of `<` and `>` with {{}} {{%/* tab header="Java" */%}} 1. Start the driver - {{}} + {{}} 2. Navigate to a page - {{}} + {{}} 3. Quit the driver - {{}} + {{}} {{%/* /tab */%}} < ... > {{}} @@ -217,11 +217,11 @@ This produces: {{< tabpane text=true langEqualsHeader=true >}} {{% tab header="Java" %}} 1. Start the driver -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L17" >}} 2. Navigate to a page -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L18" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L18" >}} 3. Quit the driver -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L35" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L35" >}} {{% /tab %}} {{< /tabpane >}} diff --git a/website_and_docs/content/documentation/about/style.ja.md b/website_and_docs/content/documentation/about/style.ja.md index 1a3d622c4b79..b18591f60af6 100644 --- a/website_and_docs/content/documentation/about/style.ja.md +++ b/website_and_docs/content/documentation/about/style.ja.md @@ -151,16 +151,16 @@ A basic comparison of code looks like: {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} {{}} @@ -174,16 +174,16 @@ Which looks like this: {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L46-L47" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L46-L47" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L17-L18" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L17-L18" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L39-L40" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L39-L40" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L16-L17" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L16-L17" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L23-L24" >}} @@ -202,11 +202,11 @@ then change the Hugo syntax for the `tab`to use `%` instead of `<` and `>` with {{}} {{%/* tab header="Java" */%}} 1. Start the driver - {{}} + {{}} 2. Navigate to a page - {{}} + {{}} 3. Quit the driver - {{}} + {{}} {{%/* /tab */%}} < ... > {{}} @@ -216,11 +216,11 @@ This produces: {{< tabpane text=true langEqualsHeader=true >}} {{% tab header="Java" %}} 1. Start the driver -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L17" >}} 2. Navigate to a page -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L18" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L18" >}} 3. Quit the driver -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L35" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L35" >}} {{% /tab %}} {{< /tabpane >}} diff --git a/website_and_docs/content/documentation/about/style.pt-br.md b/website_and_docs/content/documentation/about/style.pt-br.md index 1a3d622c4b79..b18591f60af6 100644 --- a/website_and_docs/content/documentation/about/style.pt-br.md +++ b/website_and_docs/content/documentation/about/style.pt-br.md @@ -151,16 +151,16 @@ A basic comparison of code looks like: {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} {{}} @@ -174,16 +174,16 @@ Which looks like this: {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L46-L47" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L46-L47" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L17-L18" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L17-L18" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L39-L40" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L39-L40" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L16-L17" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L16-L17" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L23-L24" >}} @@ -202,11 +202,11 @@ then change the Hugo syntax for the `tab`to use `%` instead of `<` and `>` with {{}} {{%/* tab header="Java" */%}} 1. Start the driver - {{}} + {{}} 2. Navigate to a page - {{}} + {{}} 3. Quit the driver - {{}} + {{}} {{%/* /tab */%}} < ... > {{}} @@ -216,11 +216,11 @@ This produces: {{< tabpane text=true langEqualsHeader=true >}} {{% tab header="Java" %}} 1. Start the driver -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L17" >}} 2. Navigate to a page -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L18" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L18" >}} 3. Quit the driver -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L35" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L35" >}} {{% /tab %}} {{< /tabpane >}} diff --git a/website_and_docs/content/documentation/about/style.zh-cn.md b/website_and_docs/content/documentation/about/style.zh-cn.md index 1a3d622c4b79..b18591f60af6 100644 --- a/website_and_docs/content/documentation/about/style.zh-cn.md +++ b/website_and_docs/content/documentation/about/style.zh-cn.md @@ -151,16 +151,16 @@ A basic comparison of code looks like: {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} - {{}} + {{}} {{}} {{}} {{}} @@ -174,16 +174,16 @@ Which looks like this: {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L46-L47" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L46-L47" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L17-L18" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L17-L18" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L39-L40" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L39-L40" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L16-L17" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L16-L17" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L23-L24" >}} @@ -202,11 +202,11 @@ then change the Hugo syntax for the `tab`to use `%` instead of `<` and `>` with {{}} {{%/* tab header="Java" */%}} 1. Start the driver - {{}} + {{}} 2. Navigate to a page - {{}} + {{}} 3. Quit the driver - {{}} + {{}} {{%/* /tab */%}} < ... > {{}} @@ -216,11 +216,11 @@ This produces: {{< tabpane text=true langEqualsHeader=true >}} {{% tab header="Java" %}} 1. Start the driver -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L17" >}} 2. Navigate to a page -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L18" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L18" >}} 3. Quit the driver -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L35" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L35" >}} {{% /tab %}} {{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/getting_started/first_script.en.md b/website_and_docs/content/documentation/webdriver/getting_started/first_script.en.md index cd1d68a21d55..d2f1545c989d 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/first_script.en.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/first_script.en.md @@ -9,13 +9,12 @@ description: > Once you have [Selenium installed]({{< ref "install_library.md" >}}), you're ready to write Selenium code. -**Note**: if you get an error about drivers not found, please read about troubleshooting the -[driver location error]({{< ref "../troubleshooting/errors/driver_location.md" >}}) - ## Eight Basic Components Everything Selenium does is send the browser commands to do something or send requests for information. -Most of what you'll do with Selenium is a combination of these basic commands: +Most of what you'll do with Selenium is a combination of these basic commands + +Click on the link to "View full example on GitHub" to see the code in context. ### 1. Start the session @@ -23,16 +22,16 @@ For more details on starting a session read our documentation on [driver session {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L12" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L6" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L4" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L15" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L11" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L7" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L3" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L10" >}} @@ -47,16 +46,16 @@ In this example we are [navigating]({{< ref "/documentation/webdriver/interactio {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L18" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L14" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L8" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L6" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L17" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L13" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L9" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L5" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L16" >}} @@ -73,16 +72,16 @@ can request, including window handles, browser size / position, cookies, alerts, {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L20" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#16" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L10" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L8" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L19" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L15" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L11" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L7" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L18" >}} @@ -107,16 +106,16 @@ Read more about [Waiting strategies]({{< ref "/documentation/webdriver/waits.md" {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L23" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L18" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L13" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L22" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L17" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L14" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L9" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L21" >}} @@ -132,16 +131,16 @@ with one without first [finding an element]({{< ref "/documentation/webdriver/el {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L25-L26" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L20-L21" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L15-L16" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L12-L13" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L24-L25" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L19-L20" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L16-L17" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L11-L12" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L23-L24" >}} @@ -157,16 +156,16 @@ but you will use them frequently. {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L28-L29" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L23-L24" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L18-L19" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L15-L16" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L27-L28" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L22-L23" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L19-L20" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L14-L15" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L26-L27" >}} @@ -181,16 +180,16 @@ Elements store a lot of [information that can be requested]({{< ref "/documentat {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L32" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L27" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L22" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L19" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L31" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L26" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L23" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L18" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L30" >}} @@ -204,19 +203,20 @@ Elements store a lot of [information that can be requested]({{< ref "/documentat This ends the driver process, which by default closes the browser as well. No more commands can be sent to this driver instance. +See [Quitting Sessions]({{< ref "../drivers/#quitting-sessions" >}}). {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L35" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L29" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L25" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L21" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L34" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L28" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L26" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L20" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L13" >}} @@ -226,109 +226,15 @@ No more commands can be sent to this driver instance. {{< /tab >}} {{< /tabpane >}} -## Putting everything together -Let's combine these 8 things into a complete script with assertions that can be executed by a test runner. - -{{< tabpane text=true langEqualsHeader=true >}} -{{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java" >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py" >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb" >}} -{{< /tab >}} -{{< tab header="JavaScript" >}} -{{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js" >}} -{{< /tab >}} -{{< tab header="Kotlin" >}} -{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/getting_started/FirstScriptTest.kt" >}} -{{< /tab >}} -{{< /tabpane >}} - -## Test Runners -If you are using Selenium for testing, -you will want to execute your Selenium code using test runner tools. - -Many of the code examples in this documentation can be found in our example repositories. -There are multiple options in each language, but here is what we are using in our examples: - -{{< tabpane langEqualsHeader=true text=true >}} -{{% tab header="Java" %}} -Install JUnit 5 test runner using a build tool. - -### Maven - -In the project’s `pom.xml` file, specify the dependency: - -{{< gh-codeblock path="examples/java/pom.xml#L53-L58" >}} - -and configure the build plugin: +## Running Selenium File -{{< gh-codeblock path="examples/java/pom.xml#L63-L73" >}} +{{< alert-code >}} +Add example for how to execute each of the above pages via command line +{{< /alert-code >}} -Now, run your tests using: - -```shell -mvn clean test -``` - -### Gradle - -In the project's `build.gradle` file, specify the dependency: - -{{< gh-codeblock path="examples/java/build.gradle#L15" >}} - -and add the following in the `test` task: - -{{< gh-codeblock path="examples/java/build.gradle#L19" >}} - -Now, run your tests using: - -```shell -gradle clean test -``` - -{{< /tab >}} -{{< tab header="Python" >}} -{{< badge-code >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< badge-code >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< badge-code >}} -{{< /tab >}} -{{% tab header="JavaScript" %}} -Install Mocha Test runner using below command in your terminal - -Install with npm globally: - -```shell -npm install -g mocha -``` -or as a development dependency for your project: -```shell -npm install --save-dev mocha -``` -and run your tests using below command -```shell -mocha firstScript.spec.js -``` - -{{< /tab >}} -{{< tab header="Kotlin" >}} -{{< badge-code >}} -{{< /tab >}} -{{< /tabpane >}} ## Next Steps -Take what you've learned and build out your Selenium code. - -As you find more functionality that you need, read up on the rest of our -[WebDriver documentation]({{< ref "/documentation/webdriver/" >}}). +Most Selenium users execute many sessions and need to organize them to minimize duplication and keep the code +more maintainable. Read on to learn about how to put this code into context for your use case with +[Using Selenium]({{< ref "using_selenium.md" >}}). diff --git a/website_and_docs/content/documentation/webdriver/getting_started/first_script.ja.md b/website_and_docs/content/documentation/webdriver/getting_started/first_script.ja.md index 0408fedb6cea..d8255e1c9f31 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/first_script.ja.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/first_script.ja.md @@ -10,30 +10,29 @@ description: > [Seleniumをインストール]({{< ref "install_library.md" >}})し、 すると、Seleniumコードを書く準備が整います。 -**Note**: if you get an error about drivers not found, please read about troubleshooting the -[driver location error]({{< ref "../troubleshooting/errors/driver_location.md" >}}) - ## Eight Basic Components Seleniumが行うことはすべて、ブラウザコマンドを送信して、何かを実行したり、情報の要求を送信したりすることです。 Seleniumで行うことのほとんどは、次の基本的なコマンドの組み合わせです。 +Click on the link to "View full example on GitHub" to see the code in context. + ### 1. ドライバーインスタンスでセッションを開始します For more details on starting a session read our documentation on [driver sessions]({{< ref "../drivers/" >}}) {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L12" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L6" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L4" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L15" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L11" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L7" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L3" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L10" >}} @@ -48,16 +47,16 @@ In this example we are ブラウザが[ナビゲート]({{< ref "/documentation/ {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L18" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L14" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L8" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L6" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L17" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L13" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L9" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L5" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L16" >}} @@ -74,16 +73,16 @@ can request, including window handles, browser size / position, cookies, alerts, {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L20" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#16" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L10" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L8" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L19" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L15" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L11" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L7" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L18" >}} @@ -108,16 +107,16 @@ Read more about [Waiting strategies]({{< ref "/documentation/webdriver/waits.md" {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L23" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L18" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L13" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L22" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L17" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L14" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L9" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L21" >}} @@ -133,16 +132,16 @@ with one without first [finding an element]({{< ref "/documentation/webdriver/el {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L25-L26" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L20-L21" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L15-L16" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L12-L13" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L24-L25" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L19-L20" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L16-L17" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L11-L12" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L23-L24" >}} @@ -158,16 +157,16 @@ but you will use them frequently. {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L28-L29" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L23-L24" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L18-L19" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L15-L16" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L27-L28" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L22-L23" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L19-L20" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L14-L15" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L26-L27" >}} @@ -182,22 +181,22 @@ Elements store a lot of [information that can be requested]({{< ref "/documentat {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L32" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L27" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L22" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L19" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L31" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L26" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L23" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L18" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L30" >}} {{< /tab >}} {{< tab header="Kotlin" >}} -{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/getting_started/FirstScriptTest.kt#L18" >}} +{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/getting_started/FirstScriptTest.kt#L32" >}} {{< /tab >}} {{< /tabpane >}} @@ -206,18 +205,20 @@ Elements store a lot of [information that can be requested]({{< ref "/documentat This ends the driver process, which by default closes the browser as well. No more commands can be sent to this driver instance. +See [Quitting Sessions]({{< ref "../drivers/#quitting-sessions" >}}). + {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L35" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L29" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L25" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L21" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L34" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L28" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L26" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L20" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L13" >}} @@ -227,113 +228,16 @@ No more commands can be sent to this driver instance. {{< /tab >}} {{< /tabpane >}} -## Putting everything together - -これらの8つを組み合わせて、使う必要のあるライブラリを含む完全なスクリプトにしましょう。 - -{{< tabpane text=true langEqualsHeader=true >}} -{{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java" >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py" >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb" >}} -{{< /tab >}} -{{< tab header="JavaScript" >}} -{{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js" >}} -{{< /tab >}} -{{< tab header="Kotlin" >}} -{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/getting_started/FirstScriptTest.kt" >}} -{{< /tab >}} -{{< /tabpane >}} - -## Test Runners -If you are using Selenium for testing, -you will want to execute your Selenium code using test runner tools. - -Many of the code examples in this documentation can be found in our example repositories. -There are multiple options in each language, but here is what we are using in our examples: - -{{< tabpane text=true langEqualsHeader=true >}} -{{% tab header="Java" text=true %}} -Install JUnit 5 test runner using a build tool. - -### Maven - -In the project’s `pom.xml` file, specify the dependency: - -{{< gh-codeblock path="examples/java/pom.xml#L53-L58" >}} -and configure the build plugin: +## Running Selenium File -{{< gh-codeblock path="examples/java/pom.xml#L63-L73" >}} +{{< alert-code >}} +Add example for how to execute each of the above pages via command line +{{< /alert-code >}} -Now, run your tests using: - -```shell -mvn clean test -``` - -### Gradle - -In the project's `build.gradle` file, specify the dependency: - -{{< gh-codeblock path="examples/java/build.gradle#L15" >}} - -and add the following in the `test` task: - -{{< gh-codeblock path="examples/java/build.gradle#L19" >}} - -Now, run your tests using: - -```shell -gradle clean test -``` - -{{< /tab >}} -{{< tab header="Python" >}} -// Add instructions -{{< /tab >}} -{{< tab header="CSharp" >}} -// Add instructions -{{< /tab >}} -{{< tab header="Ruby" >}} -// Add instructions -{{< /tab >}} -{{% tab header="JavaScript" text=true %}} -Install Mocha Test runner using below command in your terminal - -Install with npm globally: - -```shell -npm install -g mocha -``` -or as a development dependency for your project: - -```shell -npm install --save-dev mocha -``` - -and run your tests using below command - -```shell -mocha firstScript.spec.js -``` - -{{< /tab >}} -{{< tab header="Kotlin" >}} -// Add instructions -{{< /tab >}} -{{< /tabpane >}} ## Next Steps -Take what you've learned and build out your Selenium code. - -As you find more functionality that you need, read up on the rest of our -[WebDriver documentation]({{< ref "/documentation/webdriver/" >}}). +Most Selenium users execute many sessions and need to organize them to minimize duplication and keep the code +more maintainable. Read on to learn about how to put this code into context for your use case with +[Using Selenium]({{< ref "using_selenium.md" >}}). diff --git a/website_and_docs/content/documentation/webdriver/getting_started/first_script.pt-br.md b/website_and_docs/content/documentation/webdriver/getting_started/first_script.pt-br.md index 97c7e3e48e1d..be85030e3114 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/first_script.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/first_script.pt-br.md @@ -10,28 +10,27 @@ description: > Assim que você tiver o [Selenium instalado]({{< ref "install_library.md" >}}), você estará pronto para programar códigos Selenium. -**Note**: if you get an error about drivers not found, please read about troubleshooting the -[driver location error]({{< ref "../troubleshooting/errors/driver_location.md" >}}) - ## Oito Componentes Básicos Tudo que o Selenium faz é enviar comandos ao navegador de internet para fazer algo ou solicitar informações dele. -A maior parte do que você irá fazer com o Selenium é uma combinação desses comandos básicos: +A maior parte do que você irá fazer com o Selenium é uma combinação desses comandos básicos. + +Click on the link to "View full example on GitHub" to see the code in context. ### 1. Iniciando uma sessão Para ter mais detalhes sobre como iniciar uma sessão, leia nossa documentação em [driver sessions]({{< ref "../drivers/" >}}) {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L12" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L6" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L4" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L15" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L11" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L7" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L3" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L10" >}} @@ -46,16 +45,16 @@ Nesse exemplo estamos [navegando]({{< ref "/documentation/webdriver/interactions {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L18" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L14" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L8" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L6" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L17" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L13" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L9" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L5" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L16" >}} @@ -71,16 +70,16 @@ pode solicitar, incluindo window handles, tamanho / posição do navegador, cook {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L20" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#16" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L10" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L8" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L19" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L15" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L11" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L7" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L18" >}} @@ -106,16 +105,16 @@ Leia mais sobre [Estratégias de espera]({{< ref "/documentation/webdriver/waits {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L23" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L18" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L13" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L22" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L17" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L14" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L9" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L21" >}} @@ -132,16 +131,16 @@ com um sem o primeiro [encontrando um elemento]({{< ref "/documentation/webdrive {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L25-L26" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L20-L21" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L15-L16" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L12-L13" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L24-L25" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L19-L20" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L16-L17" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L11-L12" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L23-L24" >}} @@ -157,16 +156,16 @@ mas você irá usá-las com frequência. {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L28-L29" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L23-L24" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L18-L19" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L15-L16" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L27-L28" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L22-L23" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L19-L20" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L14-L15" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L26-L27" >}} @@ -181,16 +180,16 @@ Elementos podem guardar muitas [informações que podem ser solicitadas]({{< ref {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L32" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L27" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L22" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L19" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L31" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L26" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L23" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L18" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L30" >}} @@ -205,18 +204,20 @@ Elementos podem guardar muitas [informações que podem ser solicitadas]({{< ref Isso encerra o processo do driver, que por padrão também fecha o navegador. Nenhum outro comando pode ser enviado para esta instância do driver. +See [Quitting Sessions]({{< ref "../drivers/#quitting-sessions" >}}). + {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L35" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L29" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L25" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L21" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L34" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L28" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L26" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L20" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L13" >}} @@ -226,112 +227,16 @@ Nenhum outro comando pode ser enviado para esta instância do driver. {{< /tab >}} {{< /tabpane >}} -## Juntando tudo -Vamos combinar essas 8 coisas em um script completo com asserções que podem ser executadas por um executor de testes. - -{{< tabpane text=true langEqualsHeader=true >}} -{{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java" >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py" >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb" >}} -{{< /tab >}} -{{< tab header="JavaScript" >}} -{{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js" >}} -{{< /tab >}} -{{< tab header="Kotlin" >}} -{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/getting_started/FirstScriptTest.kt" >}} -{{< /tab >}} -{{< /tabpane >}} - -## Executando Testes -Se você esta usando selenium para realizar testes, -você deverá executar seu código usando feramentas para executar testes. - -Muitos exemplos de código encontrado nessa documentação podem ser encontrado no nosso repositório de exemplos. -Existem múltiplas opções em cada linguagem, mas esta será qual usaremos em nossos exemplos: - - -{{< tabpane text=true langEqualsHeader=true >}} -{{% tab header="Java" text=true %}} -Install JUnit 5 test runner using a build tool. - -### Maven - -In the project’s `pom.xml` file, specify the dependency: - -{{< gh-codeblock path="examples/java/pom.xml#L53-L58" >}} - -and configure the build plugin: -{{< gh-codeblock path="examples/java/pom.xml#L63-L73" >}} +## Running Selenium File -Now, run your tests using: +{{< alert-code >}} +Add example for how to execute each of the above pages via command line +{{< /alert-code >}} -```shell -mvn clean test -``` - -### Gradle - -In the project's `build.gradle` file, specify the dependency: - -{{< gh-codeblock path="examples/java/build.gradle#L15" >}} - -and add the following in the `test` task: - -{{< gh-codeblock path="examples/java/build.gradle#L19" >}} - -Now, run your tests using: - -```shell -gradle clean test -``` - -{{< /tab >}} -{{< tab header="Python" >}} -// Add instructions -{{< /tab >}} -{{< tab header="CSharp" >}} -// Add instructions -{{< /tab >}} -{{< tab header="Ruby" >}} -// Add instructions -{{< /tab >}} -{{% tab header="JavaScript" text=true %}} -Install Mocha Test runner using below command in your terminal - -Install with npm globally: - -```shell -npm install -g mocha -``` -or as a development dependency for your project: - -```shell -npm install --save-dev mocha -``` - -and run your tests using below command - -```shell -mocha firstScript.spec.js -``` - -{{< /tab >}} -{{< tab header="Kotlin" >}} -// Add instructions -{{< /tab >}} -{{< /tabpane >}} ## Próximos Passos -Use o que você aprendeu e construa o seu proprio código Selenium. - -À medida que você encontrar mais funcionalidades de que necessita, leia o restante da nossa [documentação do WebDriver]({{< ref "/documentation/webdriver/" >}}). +Most Selenium users execute many sessions and need to organize them to minimize duplication and keep the code +more maintainable. Read on to learn about how to put this code into context for your use case with +[Using Selenium]({{< ref "using_selenium.md" >}}). diff --git a/website_and_docs/content/documentation/webdriver/getting_started/first_script.zh-cn.md b/website_and_docs/content/documentation/webdriver/getting_started/first_script.zh-cn.md index 2bdf367aa7e3..c20c897ef67a 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/first_script.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/first_script.zh-cn.md @@ -8,16 +8,15 @@ description: > 当你完成 [Selenium安装]({{< ref "install_library.md" >}}) 后, 便可以开始书写Selenium脚本了. -**Note**: if you get an error about drivers not found, please read about troubleshooting the -[driver location error]({{< ref "../troubleshooting/errors/driver_location.md" >}}) - ## 八个基本组成部分 Selenium所做的一切, 就是发送给浏览器命令, 用以执行某些操作或为信息发送请求. 您将使用Selenium执行的大部分操作, -都是以下基本命令的组合: +都是以下基本命令的组合 + +Click on the link to "View full example on GitHub" to see the code in context. ### 1. 使用驱动实例开启会话 @@ -25,16 +24,16 @@ Selenium所做的一切, {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L12" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L6" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L4" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L15" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L11" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L7" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L3" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L10" >}} @@ -52,16 +51,16 @@ Selenium所做的一切, {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L18" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L14" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L8" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L6" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L17" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L13" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L9" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L5" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L16" >}} @@ -78,16 +77,16 @@ Selenium所做的一切, {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L20" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#16" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L10" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L8" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L19" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L15" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L11" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L7" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L18" >}} @@ -117,16 +116,16 @@ Selenium所做的一切, {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L23" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L18" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L13" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L22" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L17" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L14" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L9" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L21" >}} @@ -143,16 +142,16 @@ Selenium所做的一切, {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L25-L26" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L20-L21" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L15-L16" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L12-L13" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L24-L25" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L19-L20" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L16-L17" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L11-L12" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L23-L24" >}} @@ -169,16 +168,16 @@ Selenium所做的一切, {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L28-L29" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L23-L24" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L18-L19" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L15-L16" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L27-L28" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L22-L23" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L19-L20" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L14-L15" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L26-L27" >}} @@ -193,16 +192,16 @@ Selenium所做的一切, {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L32" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L27" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L22" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L19" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L31" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L26" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L23" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L18" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L30" >}} @@ -218,18 +217,20 @@ Selenium所做的一切, 默认情况下, 该进程也会关闭浏览器. 无法向此驱动程序实例发送更多命令. +See [Quitting Sessions]({{< ref "../drivers/#quitting-sessions" >}}). + {{< tabpane text=true langEqualsHeader=true >}} {{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L35" >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java#L29" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L25" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/first_script.py#L21" >}} {{< /tab >}} {{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs#L34" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs#L28" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb#L26" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script.rb#L20" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js#L13" >}} @@ -239,118 +240,16 @@ Selenium所做的一切, {{< /tab >}} {{< /tabpane >}} -## 组合所有事情 - -让我们将这8个部分组合成一个完整的脚本, -包括需要使用的库: - -按照选项卡底部的链接查看代码示例, -因为它将使用测试运行程序而不是独立文件执行. - -{{< tabpane text=true langEqualsHeader=true >}} -{{< tab header="Java" >}} -{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java" >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py" >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/FirstScriptTest.cs" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/first_script_spec.rb" >}} -{{< /tab >}} -{{< tab header="JavaScript" >}} -{{< gh-codeblock path="examples/javascript/test/getting_started/firstScript.spec.js" >}} -{{< /tab >}} -{{< tab header="Kotlin" >}} -{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/getting_started/FirstScriptTest.kt" >}} -{{< /tab >}} -{{< /tabpane >}} - -## Test Runners -If you are using Selenium for testing, -you will want to execute your Selenium code using test runner tools. - -Many of the code examples in this documentation can be found in our example repositories. -There are multiple options in each language, but here is what we are using in our examples: - -{{< tabpane text=true langEqualsHeader=true >}} -{{% tab header="Java" text=true %}} -Install JUnit 5 test runner using a build tool. - -### Maven - -In the project’s `pom.xml` file, specify the dependency: - -{{< gh-codeblock path="examples/java/pom.xml#L53-L58" >}} -and configure the build plugin: +## Running Selenium File -{{< gh-codeblock path="examples/java/pom.xml#L63-L73" >}} +{{< alert-code >}} +Add example for how to execute each of the above pages via command line +{{< /alert-code >}} -Now, run your tests using: - -```shell -mvn clean test -``` - -### Gradle - -In the project's `build.gradle` file, specify the dependency: - -{{< gh-codeblock path="examples/java/build.gradle#L15" >}} - -and add the following in the `test` task: - -{{< gh-codeblock path="examples/java/build.gradle#L19" >}} - -Now, run your tests using: - -```shell -gradle clean test -``` - -{{< /tab >}} -{{< tab header="Python" >}} -// Add instructions -{{< /tab >}} -{{< tab header="CSharp" >}} -// Add instructions -{{< /tab >}} -{{< tab header="Ruby" >}} -// Add instructions -{{< /tab >}} -{{% tab header="JavaScript" text=true %}} -Install Mocha Test runner using below command in your terminal - -Install with npm globally: - -```shell -npm install -g mocha -``` -or as a development dependency for your project: - -```shell -npm install --save-dev mocha -``` - -and run your tests using below command - -```shell -mocha firstScript.spec.js -``` - -{{< /tab >}} -{{< tab header="Kotlin" >}} -// Add instructions -{{< /tab >}} -{{< /tabpane >}} ## 接下来的步骤 -利用你所学的知识, -构建你的Selenium代码. - -当您发现需要更多功能时, -请阅读我们的[WebDriver文档]({{< ref "/documentation/webdriver/" >}})的其余部分. +Most Selenium users execute many sessions and need to organize them to minimize duplication and keep the code +more maintainable. Read on to learn about how to put this code into context for your use case with +[Using Selenium]({{< ref "using_selenium.md" >}}). diff --git a/website_and_docs/content/documentation/webdriver/getting_started/install_library.en.md b/website_and_docs/content/documentation/webdriver/getting_started/install_library.en.md index 994a5e98dc9e..1255df8e31a8 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/install_library.en.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/install_library.en.md @@ -25,14 +25,14 @@ View the minimum supported Java version [here](https://github.com/SeleniumHQ/sel Installation of Selenium libraries for Java is accomplished using a build tool. ### Maven -Specify the dependency in the project's `pom.xml` file: +Specify the dependencies in the project's `pom.xml` file: -{{< gh-codeblock path="examples/java/pom.xml#L32-L36" >}} +{{< gh-codeblock path="examples/java/pom.xml#L28-L38" >}} ### Gradle Specify the dependency in the project `build.gradle` file as `testImplementation`: -{{< gh-codeblock path="examples/java/build.gradle#L13" >}} +{{< gh-codeblock path="examples/java/build.gradle#L13-L14" >}} {{% /tab %}} {{% tab header="Python" %}} diff --git a/website_and_docs/content/documentation/webdriver/getting_started/install_library.ja.md b/website_and_docs/content/documentation/webdriver/getting_started/install_library.ja.md index a3eea913d5de..439eba0558a8 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/install_library.ja.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/install_library.ja.md @@ -23,14 +23,14 @@ View the minimum supported Java version [here](https://github.com/SeleniumHQ/sel Installation of Selenium libraries for Java is accomplished using a build tool. ### Maven -Specify the dependency in the project's `pom.xml` file: +Specify the dependencies in the project's `pom.xml` file: -{{< gh-codeblock path="examples/java/pom.xml#L32-L36" >}} +{{< gh-codeblock path="examples/java/pom.xml#L28-L38" >}} ### Gradle Specify the dependency in the project `build.gradle` file as `testImplementation`: -{{< gh-codeblock path="examples/java/build.gradle#L13" >}} +{{< gh-codeblock path="examples/java/build.gradle#L13-L14" >}} {{% /tab %}} {{% tab header="Python" %}} diff --git a/website_and_docs/content/documentation/webdriver/getting_started/install_library.pt-br.md b/website_and_docs/content/documentation/webdriver/getting_started/install_library.pt-br.md index 0817dbf24953..01303ba69ee7 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/install_library.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/install_library.pt-br.md @@ -27,12 +27,12 @@ A instalação da biblioteca Selenium para Java é feita a partir de uma build t ### Maven Especifique a dependência no `pom.xml` do seu projeto. -{{< gh-codeblock path="examples/java/pom.xml#L32-L36" >}} +{{< gh-codeblock path="examples/java/pom.xml#L28-L38" >}} ### Gradle Especifique a dependência no `build.gradle` do seu projeto como `testImplementation`: -{{< gh-codeblock path="examples/java/build.gradle#L13" >}} +{{< gh-codeblock path="examples/java/build.gradle#L13-L14" >}} {{% /tab %}} {{% tab header="Python" %}} diff --git a/website_and_docs/content/documentation/webdriver/getting_started/install_library.zh-cn.md b/website_and_docs/content/documentation/webdriver/getting_started/install_library.zh-cn.md index 63ccfe869be2..e288db28b7d9 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/install_library.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/install_library.zh-cn.md @@ -25,12 +25,12 @@ aliases: [ ### Maven 具体的依赖位于项目中的 `pom.xml` 文件: -{{< gh-codeblock path="examples/java/pom.xml#L32-L36" >}} +{{< gh-codeblock path="examples/java/pom.xml#L28-L38" >}} ### Gradle 具体的依赖位于项目中的 `build.gradle` 文件中的 `testImplementation`: -{{< gh-codeblock path="examples/java/build.gradle#L13" >}} +{{< gh-codeblock path="examples/java/build.gradle#L13-L14" >}} {{% /tab %}} {{% tab header="Python" %}} diff --git a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.en.md b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.en.md new file mode 100644 index 000000000000..9a84cada7415 --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.en.md @@ -0,0 +1,248 @@ +--- +title: "Organizing and Executing Selenium Code" +linkTitle: "Using Selenium" +weight: 10 +description: > + 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. 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 + +Perhaps you need to log into a website and download something, or submit a form. +You can create a Selenium script to run with a service at preset times. + +### Web Scraping + +Are you looking to collect data from a site that doesn't have an API? Selenium +will let you do this, but please make sure you are familiar with the website's +terms of service as some websites do not permit it and others will even block Selenium. + +### 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 + +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](https://www.eclipse.org/) +- [IntelliJ IDEA](https://www.jetbrains.com/idea/) +- [PyCharm](https://www.jetbrains.com/pycharm/) +- [RubyMine](https://www.jetbrains.com/ruby/) +- [Rider](https://www.jetbrains.com/rider/) +- [WebStorm](https://www.jetbrains.com/webstorm/) +- [VS Code](https://code.visualstudio.com/) + +## 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. + +All the code examples in this documentation can be found in (or is being moved to) our +example directories that use test runners and get executed every release to ensure all the code is correct and updated. +Here is a list of test runners with links. The first item is the one that is used by this repository and the one +that will be used for all examples on this page. + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} +- [JUnit](https://junit.org/junit5/) - A widely-used testing framework for Java-based Selenium tests. +- [TestNG](https://testng.org/doc/) - Offers extra features like parallel test execution and parameterized tests. +{{% /tab %}} + +{{% tab header="Python" %}} +- [pytest](https://pytest.org/) - A preferred choice for many, thanks to its simplicity and powerful plugins. +- [unittest](https://docs.python.org/3/library/unittest.html) - Python's standard library testing framework. +{{% /tab %}} + +{{% tab header="CSharp" %}} +- [NUnit](https://nunit.org/) - A popular unit-testing framework for .NET. +- [MS Test](https://docs.microsoft.com/en-us/visualstudio/test/getting-started-with-unit-testing?view=vs-2019) - Microsoft's own unit testing framework. +{{% /tab %}} + +{{% tab header="Ruby" %}} +- [RSpec](https://rspec.info/) - The most widely used testing library for running Selenium tests in Ruby. +- [Minitest](https://github.com/seattlerb/minitest) - A lightweight testing framework that comes with Ruby standard library. +{{% /tab %}} + +{{% tab header="JavaScript" %}} +- [Jest](https://jestjs.io/) - Primarily known as a testing framework for React, it can also be used for Selenium tests. +- [Mocha](https://mochajs.org/) - The most common JS library for running Selenium tests. +{{% /tab %}} + +{{% tab header="Kotlin" %}} + +{{% /tab %}} +{{< /tabpane >}} + + +### Installing + +This is very similar to what was required in [Install a Selenium Library]({{< ref "install_library.md" >}}). +This code is only showing examples for what is being used in our Documentation Examples project. + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} + +**Maven** + +**Gradle** + +{{% /tab %}} +{{% tab header="Python" %}} + +To use it in a project, add it to the `requirements.txt` file: + +{{% /tab %}} +{{% tab header="CSharp" %}} +in the project's `csproj` file, specify the dependency as a `PackageReference` in `ItemGroup`: + +{{% /tab %}} +{{% tab header="Ruby" %}} + +Add to project's gemfile + +{{% /tab %}} +{{% tab header="JavaScript" %}} +In your project's `package.json`, add requirement to `dependencies`: + +{{% /tab %}} +{{< tab header="Kotlin" >}} +{{< /tab >}} +{{< /tabpane >}} + +### Asserting + +{{< tabpane text=true langEqualsHeader=true >}} +{{< tab header="Java" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Setting Up and Tearing Down + +{{< tabpane text=true langEqualsHeader=true >}} +{{< tab header="Java" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Executing + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} +### Maven + +```shell +mvn clean test +``` + +### Gradle + +```shell +gradle clean test +``` + +{{% /tab %}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="JavaScript" %}} +```shell +mocha runningTests.spec.js +``` +{{% /tab %}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Examples + +In [First script]({{< ref "first_script.md" >}}), we saw each of the components of a Selenium script. +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/UsingSeleniumTest.java" >}} +{{< /tab >}} +{{< tab header="Python" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/using_selenium_tests.py" >}} +{{< /tab >}} +{{< tab header="CSharp" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs" >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb" >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +## Next Steps + +Take what you've learned and build out your Selenium code! + +As you find more functionality that you need, read up on the rest of our +[WebDriver documentation]({{< ref "/documentation/webdriver/" >}}). diff --git a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.ja.md b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.ja.md new file mode 100644 index 000000000000..64dbbe32f5e8 --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.ja.md @@ -0,0 +1,244 @@ +--- +title: "Organizing and Executing Selenium Code" +linkTitle: "Using Selenium" +weight: 10 +description: > + 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. 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 + +Perhaps you need to log into a website and download something, or submit a form. +You can create a Selenium script to run with a service at preset times. + +### Web Scraping + +Are you looking to collect data from a site that doesn't have an API? Selenium +will let you do this, but please make sure you are familiar with the website's +terms of service as some websites do not permit it and others will even block Selenium. + +### 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 + +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](https://www.eclipse.org/) +- [IntelliJ IDEA](https://www.jetbrains.com/idea/) +- [PyCharm](https://www.jetbrains.com/pycharm/) +- [RubyMine](https://www.jetbrains.com/ruby/) +- [Rider](https://www.jetbrains.com/rider/) +- [WebStorm](https://www.jetbrains.com/webstorm/) +- [VS Code](https://code.visualstudio.com/) + +## 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. + +All the code examples in this documentation can be found in (or is being moved to) our +example directories that use test runners and get executed every release to ensure all the code is correct and updated. +Here is a list of test runners with links. The first item is the one that is used by this repository and the one +that will be used for all examples on this page. + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} +- [JUnit](https://junit.org/junit5/) - A widely-used testing framework for Java-based Selenium tests. +- [TestNG](https://testng.org/doc/) - Offers extra features like parallel test execution and parameterized tests. +{{% /tab %}} + +{{% tab header="Python" %}} +- [pytest](https://pytest.org/) - A preferred choice for many, thanks to its simplicity and powerful plugins. +- [unittest](https://docs.python.org/3/library/unittest.html) - Python's standard library testing framework. +{{% /tab %}} + +{{% tab header="CSharp" %}} +- [NUnit](https://nunit.org/) - A popular unit-testing framework for .NET. +- [MS Test](https://docs.microsoft.com/en-us/visualstudio/test/getting-started-with-unit-testing?view=vs-2019) - Microsoft's own unit testing framework. +{{% /tab %}} + +{{% tab header="Ruby" %}} +- [RSpec](https://rspec.info/) - The most widely used testing library for running Selenium tests in Ruby. +- [Minitest](https://github.com/seattlerb/minitest) - A lightweight testing framework that comes with Ruby standard library. +{{% /tab %}} + +{{% tab header="JavaScript" %}} +- [Jest](https://jestjs.io/) - Primarily known as a testing framework for React, it can also be used for Selenium tests. +- [Mocha](https://mochajs.org/) - The most common JS library for running Selenium tests. +{{% /tab %}} + +{{% tab header="Kotlin" %}} + +{{% /tab %}} +{{< /tabpane >}} + + +### Installing + +This is very similar to what was required in [Install a Selenium Library]({{< ref "install_library.md" >}}). +This code is only showing examples for what is being used in our Documentation Examples project. + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} + +**Maven** + +**Gradle** + +{{% /tab %}} +{{% tab header="Python" %}} + +To use it in a project, add it to the `requirements.txt` file: + +{{% /tab %}} +{{% tab header="CSharp" %}} +in the project's `csproj` file, specify the dependency as a `PackageReference` in `ItemGroup`: + +{{% /tab %}} +{{% tab header="Ruby" %}} + +Add to project's gemfile + +{{% /tab %}} +{{% tab header="JavaScript" %}} +In your project's `package.json`, add requirement to `dependencies`: + +{{% /tab %}} +{{< tab header="Kotlin" >}} +{{< /tab >}} +{{< /tabpane >}} + +### Asserting + +{{< tabpane text=true langEqualsHeader=true >}} +{{< tab header="Java" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Setting Up and Tearing Down + +{{< tabpane text=true langEqualsHeader=true >}} +{{< tab header="Java" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Executing + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} +### Maven + +```shell +mvn clean test +``` + +### Gradle + +```shell +gradle clean test +``` + +{{% /tab %}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="JavaScript" %}} +```shell +mocha runningTests.spec.js +``` +{{% /tab %}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Examples + +In [First script]({{< ref "first_script.md" >}}), we saw each of the components of a Selenium script. +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/UsingSeleniumTest.java" >}} +{{< /tab >}} +{{< tab header="Python" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/using_selenium_tests.py" >}} +{{< /tab >}} +{{< tab header="CSharp" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs" >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb" >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +## Next Steps + +Take what you've learned and build out your Selenium code! + +As you find more functionality that you need, read up on the rest of our +[WebDriver documentation]({{< ref "/documentation/webdriver/" >}}). diff --git a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.pt-br.md b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.pt-br.md new file mode 100644 index 000000000000..64dbbe32f5e8 --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.pt-br.md @@ -0,0 +1,244 @@ +--- +title: "Organizing and Executing Selenium Code" +linkTitle: "Using Selenium" +weight: 10 +description: > + 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. 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 + +Perhaps you need to log into a website and download something, or submit a form. +You can create a Selenium script to run with a service at preset times. + +### Web Scraping + +Are you looking to collect data from a site that doesn't have an API? Selenium +will let you do this, but please make sure you are familiar with the website's +terms of service as some websites do not permit it and others will even block Selenium. + +### 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 + +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](https://www.eclipse.org/) +- [IntelliJ IDEA](https://www.jetbrains.com/idea/) +- [PyCharm](https://www.jetbrains.com/pycharm/) +- [RubyMine](https://www.jetbrains.com/ruby/) +- [Rider](https://www.jetbrains.com/rider/) +- [WebStorm](https://www.jetbrains.com/webstorm/) +- [VS Code](https://code.visualstudio.com/) + +## 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. + +All the code examples in this documentation can be found in (or is being moved to) our +example directories that use test runners and get executed every release to ensure all the code is correct and updated. +Here is a list of test runners with links. The first item is the one that is used by this repository and the one +that will be used for all examples on this page. + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} +- [JUnit](https://junit.org/junit5/) - A widely-used testing framework for Java-based Selenium tests. +- [TestNG](https://testng.org/doc/) - Offers extra features like parallel test execution and parameterized tests. +{{% /tab %}} + +{{% tab header="Python" %}} +- [pytest](https://pytest.org/) - A preferred choice for many, thanks to its simplicity and powerful plugins. +- [unittest](https://docs.python.org/3/library/unittest.html) - Python's standard library testing framework. +{{% /tab %}} + +{{% tab header="CSharp" %}} +- [NUnit](https://nunit.org/) - A popular unit-testing framework for .NET. +- [MS Test](https://docs.microsoft.com/en-us/visualstudio/test/getting-started-with-unit-testing?view=vs-2019) - Microsoft's own unit testing framework. +{{% /tab %}} + +{{% tab header="Ruby" %}} +- [RSpec](https://rspec.info/) - The most widely used testing library for running Selenium tests in Ruby. +- [Minitest](https://github.com/seattlerb/minitest) - A lightweight testing framework that comes with Ruby standard library. +{{% /tab %}} + +{{% tab header="JavaScript" %}} +- [Jest](https://jestjs.io/) - Primarily known as a testing framework for React, it can also be used for Selenium tests. +- [Mocha](https://mochajs.org/) - The most common JS library for running Selenium tests. +{{% /tab %}} + +{{% tab header="Kotlin" %}} + +{{% /tab %}} +{{< /tabpane >}} + + +### Installing + +This is very similar to what was required in [Install a Selenium Library]({{< ref "install_library.md" >}}). +This code is only showing examples for what is being used in our Documentation Examples project. + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} + +**Maven** + +**Gradle** + +{{% /tab %}} +{{% tab header="Python" %}} + +To use it in a project, add it to the `requirements.txt` file: + +{{% /tab %}} +{{% tab header="CSharp" %}} +in the project's `csproj` file, specify the dependency as a `PackageReference` in `ItemGroup`: + +{{% /tab %}} +{{% tab header="Ruby" %}} + +Add to project's gemfile + +{{% /tab %}} +{{% tab header="JavaScript" %}} +In your project's `package.json`, add requirement to `dependencies`: + +{{% /tab %}} +{{< tab header="Kotlin" >}} +{{< /tab >}} +{{< /tabpane >}} + +### Asserting + +{{< tabpane text=true langEqualsHeader=true >}} +{{< tab header="Java" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Setting Up and Tearing Down + +{{< tabpane text=true langEqualsHeader=true >}} +{{< tab header="Java" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Executing + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} +### Maven + +```shell +mvn clean test +``` + +### Gradle + +```shell +gradle clean test +``` + +{{% /tab %}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="JavaScript" %}} +```shell +mocha runningTests.spec.js +``` +{{% /tab %}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Examples + +In [First script]({{< ref "first_script.md" >}}), we saw each of the components of a Selenium script. +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/UsingSeleniumTest.java" >}} +{{< /tab >}} +{{< tab header="Python" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/using_selenium_tests.py" >}} +{{< /tab >}} +{{< tab header="CSharp" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs" >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb" >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +## Next Steps + +Take what you've learned and build out your Selenium code! + +As you find more functionality that you need, read up on the rest of our +[WebDriver documentation]({{< ref "/documentation/webdriver/" >}}). diff --git a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.zh-cn.md b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.zh-cn.md new file mode 100644 index 000000000000..64dbbe32f5e8 --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.zh-cn.md @@ -0,0 +1,244 @@ +--- +title: "Organizing and Executing Selenium Code" +linkTitle: "Using Selenium" +weight: 10 +description: > + 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. 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 + +Perhaps you need to log into a website and download something, or submit a form. +You can create a Selenium script to run with a service at preset times. + +### Web Scraping + +Are you looking to collect data from a site that doesn't have an API? Selenium +will let you do this, but please make sure you are familiar with the website's +terms of service as some websites do not permit it and others will even block Selenium. + +### 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 + +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](https://www.eclipse.org/) +- [IntelliJ IDEA](https://www.jetbrains.com/idea/) +- [PyCharm](https://www.jetbrains.com/pycharm/) +- [RubyMine](https://www.jetbrains.com/ruby/) +- [Rider](https://www.jetbrains.com/rider/) +- [WebStorm](https://www.jetbrains.com/webstorm/) +- [VS Code](https://code.visualstudio.com/) + +## 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. + +All the code examples in this documentation can be found in (or is being moved to) our +example directories that use test runners and get executed every release to ensure all the code is correct and updated. +Here is a list of test runners with links. The first item is the one that is used by this repository and the one +that will be used for all examples on this page. + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} +- [JUnit](https://junit.org/junit5/) - A widely-used testing framework for Java-based Selenium tests. +- [TestNG](https://testng.org/doc/) - Offers extra features like parallel test execution and parameterized tests. +{{% /tab %}} + +{{% tab header="Python" %}} +- [pytest](https://pytest.org/) - A preferred choice for many, thanks to its simplicity and powerful plugins. +- [unittest](https://docs.python.org/3/library/unittest.html) - Python's standard library testing framework. +{{% /tab %}} + +{{% tab header="CSharp" %}} +- [NUnit](https://nunit.org/) - A popular unit-testing framework for .NET. +- [MS Test](https://docs.microsoft.com/en-us/visualstudio/test/getting-started-with-unit-testing?view=vs-2019) - Microsoft's own unit testing framework. +{{% /tab %}} + +{{% tab header="Ruby" %}} +- [RSpec](https://rspec.info/) - The most widely used testing library for running Selenium tests in Ruby. +- [Minitest](https://github.com/seattlerb/minitest) - A lightweight testing framework that comes with Ruby standard library. +{{% /tab %}} + +{{% tab header="JavaScript" %}} +- [Jest](https://jestjs.io/) - Primarily known as a testing framework for React, it can also be used for Selenium tests. +- [Mocha](https://mochajs.org/) - The most common JS library for running Selenium tests. +{{% /tab %}} + +{{% tab header="Kotlin" %}} + +{{% /tab %}} +{{< /tabpane >}} + + +### Installing + +This is very similar to what was required in [Install a Selenium Library]({{< ref "install_library.md" >}}). +This code is only showing examples for what is being used in our Documentation Examples project. + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} + +**Maven** + +**Gradle** + +{{% /tab %}} +{{% tab header="Python" %}} + +To use it in a project, add it to the `requirements.txt` file: + +{{% /tab %}} +{{% tab header="CSharp" %}} +in the project's `csproj` file, specify the dependency as a `PackageReference` in `ItemGroup`: + +{{% /tab %}} +{{% tab header="Ruby" %}} + +Add to project's gemfile + +{{% /tab %}} +{{% tab header="JavaScript" %}} +In your project's `package.json`, add requirement to `dependencies`: + +{{% /tab %}} +{{< tab header="Kotlin" >}} +{{< /tab >}} +{{< /tabpane >}} + +### Asserting + +{{< tabpane text=true langEqualsHeader=true >}} +{{< tab header="Java" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Setting Up and Tearing Down + +{{< tabpane text=true langEqualsHeader=true >}} +{{< tab header="Java" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Executing + +{{< tabpane text=true langEqualsHeader=true >}} +{{% tab header="Java" %}} +### Maven + +```shell +mvn clean test +``` + +### Gradle + +```shell +gradle clean test +``` + +{{% /tab %}} +{{% tab header="Python" %}} +{{< badge-code >}} +{{% /tab %}} +{{< tab header="CSharp" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< badge-code >}} +{{< /tab >}} +{{% tab header="JavaScript" %}} +```shell +mocha runningTests.spec.js +``` +{{% /tab %}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +### Examples + +In [First script]({{< ref "first_script.md" >}}), we saw each of the components of a Selenium script. +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/UsingSeleniumTest.java" >}} +{{< /tab >}} +{{< tab header="Python" >}} +{{< gh-codeblock path="examples/python/tests/getting_started/using_selenium_tests.py" >}} +{{< /tab >}} +{{< tab header="CSharp" >}} +{{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs" >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb" >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-code >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-code >}} +{{< /tab >}} +{{< /tabpane >}} + +## Next Steps + +Take what you've learned and build out your Selenium code! + +As you find more functionality that you need, read up on the rest of our +[WebDriver documentation]({{< ref "/documentation/webdriver/" >}}).