Repository navigation
Restore translated documentation pages removed by the Docsy upgrade #2831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b7df450
32aedb8
9dfb419
ebbccc6
3d078e4
2fef9c2
c442748
c7cc4cc
4f661ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.openqa.selenium.PageLoadStrategy; | ||
| import org.openqa.selenium.Proxy; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Driver option snippets show wrong lines The new Proxy import at line 11 of OptionsTest.java shifts every existing example below the imports without adjusting its established gh-codeblock ranges. The driver index and options pages in English, Japanese, Portuguese, and Chinese therefore select neighboring lines for their pre-existing Java samples whenever Hugo renders them. Agent Prompt
|
||
| import org.openqa.selenium.UnexpectedAlertBehaviour; | ||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.chrome.ChromeOptions; | ||
|
|
@@ -169,5 +170,17 @@ public void setStrictFileInteractability() { | |
| Boolean capability = (Boolean) capabilityObject; | ||
| Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true."); | ||
| } | ||
|
|
||
| @Test | ||
| public void setsProxy() { | ||
| Proxy proxy = new Proxy(); | ||
| proxy.setHttpProxy("myproxy.com:8080"); | ||
| ChromeOptions options = getDefaultChromeOptions(); | ||
| options.setCapability("proxy", proxy); | ||
|
|
||
| Object capabilityObject = options.getCapability("proxy"); | ||
| Assertions.assertNotNull(capabilityObject, "Capability proxy should not be null."); | ||
| Assertions.assertEquals("myproxy.com:8080", ((Proxy) capabilityObject).getHttpProxy()); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package dev.selenium.grid; | ||
|
|
||
| import dev.selenium.BaseTest; | ||
| import java.net.URL; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.chrome.ChromeOptions; | ||
| import org.openqa.selenium.remote.RemoteWebDriver; | ||
|
|
||
| public class GettingStartedTest extends BaseTest { | ||
|
|
||
| @Test | ||
| public void addsMetadataToASession() throws Exception { | ||
| URL gridUrl = startStandaloneGrid(); | ||
|
|
||
| ChromeOptions chromeOptions = getDefaultChromeOptions(); | ||
| // Showing a test name instead of the session id in the Grid UI | ||
| chromeOptions.setCapability("se:name", "My simple test"); | ||
| // Other type of metadata can be seen in the Grid UI by clicking on the | ||
| // session info or via GraphQL | ||
| chromeOptions.setCapability("se:sampleMetadata", "Sample metadata value"); | ||
| WebDriver driver = new RemoteWebDriver(gridUrl, chromeOptions); | ||
| this.driver = driver; | ||
| driver.get("https://www.selenium.dev"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,29 @@ | ||
| package dev.selenium.support; | ||
|
|
||
| import dev.selenium.BaseTest; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.support.ThreadGuard; | ||
|
|
||
| public class ThreadGuardTest extends BaseTest { | ||
|
|
||
| @Test | ||
| public void protectsDriverFromCrossThreadUse() throws InterruptedException { | ||
| WebDriver protectedDriver = ThreadGuard.protect(startChromeDriver()); | ||
|
|
||
| Throwable[] caughtOnOtherThread = new Throwable[1]; | ||
| Runnable callFromOtherThread = () -> { | ||
| try { | ||
| protectedDriver.get("https://www.selenium.dev"); | ||
| } catch (Throwable t) { | ||
| caughtOnOtherThread[0] = t; | ||
| } | ||
| }; | ||
| Thread otherThread = new Thread(callFromOtherThread); | ||
| otherThread.start(); | ||
| otherThread.join(); | ||
|
|
||
| Assertions.assertNotNull(caughtOnOtherThread[0]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 10. Unrelated failures pass guard tests protectsDriverFromCrossThreadUse considers any captured Throwable sufficient instead of verifying ThreadGuard's expected thread-safety exception. If cross-thread protection regresses while navigation fails for an unrelated browser, network, or JVM reason, this test still passes. Agent Prompt
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package dev.selenium.test_practices; | ||
|
|
||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openqa.selenium.By; | ||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.WebElement; | ||
| import org.openqa.selenium.chrome.ChromeDriver; | ||
| import org.openqa.selenium.support.PageFactory; | ||
|
|
||
| class AccountPage { | ||
| } | ||
|
|
||
| class LoginPage { | ||
| private final WebDriver driver; | ||
|
|
||
| public LoginPage(WebDriver driver) { | ||
| this.driver = driver; | ||
| } | ||
|
|
||
| /** | ||
| * Takes a username and password, fills out the fields, and clicks "login". | ||
| * | ||
| * @return An instance of the AccountPage | ||
| */ | ||
| public AccountPage loginAsUser(String username, String password) { | ||
| WebElement loginField = driver.findElement(By.id("loginField")); | ||
| loginField.clear(); | ||
| loginField.sendKeys(username); | ||
|
|
||
| // Fill out the password field. The locator we're using is "By.id", and we should | ||
| // have it defined elsewhere in the class. | ||
| WebElement passwordField = driver.findElement(By.id("password")); | ||
| passwordField.clear(); | ||
| passwordField.sendKeys(password); | ||
|
|
||
| // Click the login button, which happens to have the id "submit". | ||
| driver.findElement(By.id("submit")).click(); | ||
|
|
||
| // Create and return a new instance of the AccountPage (via the built-in Selenium | ||
| // PageFactory). | ||
| return PageFactory.initElements(driver, AccountPage.class); | ||
| } | ||
| } | ||
|
|
||
| public class DomainSpecificLanguageExample { | ||
|
|
||
| @Test | ||
| @Disabled("Illustrative only: LoginPage targets a fictional application, not a live site") | ||
| void loginAsUserAbstractsTheLoginFormFromTheTest() { | ||
| WebDriver driver = new ChromeDriver(); | ||
| try { | ||
| LoginPage loginPage = new LoginPage(driver); | ||
| loginPage.loginAsUser("cbrown", "cl0wn3"); | ||
| } finally { | ||
| driver.quit(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package dev.selenium.test_practices; | ||
|
|
||
| import java.time.Duration; | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openqa.selenium.By; | ||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.chrome.ChromeDriver; | ||
| import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
|
||
| abstract class BasePage { | ||
| protected WebDriver driver; | ||
|
|
||
| public BasePage(WebDriver driver) { | ||
| this.driver = driver; | ||
| } | ||
| } | ||
|
|
||
| class GoogleSearchPage extends BasePage { | ||
| public GoogleSearchPage(WebDriver driver) { | ||
| super(driver); | ||
| // Generally do not assert within pages or components. | ||
| // Effectively throws an exception if the lambda condition is not met. | ||
| new WebDriverWait(driver, Duration.ofSeconds(3)).until(d -> d.findElement(By.id("logo"))); | ||
| } | ||
|
|
||
| public GoogleSearchPage setSearchString(String sstr) { | ||
| driver.findElement(By.id("gbqfq")).sendKeys(sstr); | ||
| return this; | ||
| } | ||
|
|
||
| public void clickSearchButton() { | ||
| driver.findElement(By.id("gbqfb")).click(); | ||
| } | ||
| } | ||
|
|
||
| public class FluentApiExample { | ||
|
|
||
| @Test | ||
| @Disabled("Illustrative only: targets Google's live, frequently changing search page markup") | ||
| void queryTheGoogleSearchPageUsingAFluentApi() { | ||
| WebDriver driver = new ChromeDriver(); | ||
| try { | ||
| driver.get("http://www.google.com/webhp?hl=en&tab=ww"); | ||
| GoogleSearchPage gsp = new GoogleSearchPage(driver); | ||
| gsp.setSearchString("cheese").clickSearchButton(); | ||
| } finally { | ||
| driver.quit(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package dev.selenium.test_practices; | ||
|
|
||
| import dev.selenium.BaseTest; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.firefox.FirefoxDriver; | ||
|
|
||
| public class FreshBrowserPerTestTest extends BaseTest { | ||
|
|
||
| @Test | ||
| public void startsAFreshBrowserForTheTest() { | ||
| WebDriver driver = new FirefoxDriver(); | ||
| this.driver = driver; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| const chrome = require('selenium-webdriver/chrome') | ||
| const proxy = require('selenium-webdriver/proxy') | ||
| const assert = require('node:assert') | ||
|
|
||
| describe('Options Test', function () { | ||
| it('Sets proxy', function () { | ||
| const options = new chrome.Options() | ||
| options.setProxy(proxy.manual({ http: 'myproxy.com:8080' })) | ||
|
|
||
| const capability = options.getProxy() | ||
| assert.notStrictEqual(capability, undefined) | ||
| assert.strictEqual(capability.httpProxy, 'myproxy.com:8080') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package dev.selenium.drivers | ||
|
|
||
| import dev.selenium.BaseTest | ||
| import org.junit.jupiter.api.Assertions | ||
| import org.junit.jupiter.api.Test | ||
| import org.openqa.selenium.Proxy | ||
| import org.openqa.selenium.chrome.ChromeOptions | ||
|
|
||
| class OptionsTest : BaseTest() { | ||
|
|
||
| @Test | ||
| fun setsProxy() { | ||
| val proxy = Proxy() | ||
| proxy.setHttpProxy("myproxy.com:8080") | ||
| val options = ChromeOptions() | ||
| options.setCapability("proxy", proxy) | ||
|
|
||
| val capabilityObject = options.getCapability("proxy") as Proxy | ||
| Assertions.assertNotNull(capabilityObject) | ||
| Assertions.assertEquals("myproxy.com:8080", capabilityObject.httpProxy) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Documentation fix carries test tuning
📘 Rule violation⚙ MaintainabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools