Skip to content

Navigation Menu

Sign in
Appearance settings

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

Provide feedback

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

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Innazh/add browser options examples java #1865

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
c817f76
add browser options test examples in java
innazh Aug 16, 2024
b9bbea1
add java examples to /drivers/options.en.md
innazh Aug 17, 2024
140428f
rename variables in the added to OptionsTest file functions
innazh Aug 17, 2024
d964cce
update the line nums in options.en.md
innazh Aug 17, 2024
cff3f9d
update options.ja.md file with java examples for driver options
innazh Aug 17, 2024
4350411
update options.pt-br.md file with java examples
innazh Aug 17, 2024
2faea60
update options.zh-cn.md file with java examples
innazh Aug 17, 2024
10b21c8
remove toString() method from a string var
innazh Aug 17, 2024
2da5d05
addressed the feedback and now using Assertions library
innazh Aug 18, 2024
426b83d
Update all line num in the docs
innazh Aug 18, 2024
48cd7db
Fixing nightly version retrieval
diemol Aug 19, 2024
bce6030
Merge branch 'trunk' into innazh/add-browser-options-examples-java
diemol Aug 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/java-examples.yml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
command: |
pip install yq
xml_content=$(curl -sf https://oss.sonatype.org/service/local/repositories/snapshots/content/org/seleniumhq/selenium/selenium-java/)
latest_snapshot=$(echo $xml_content | xq '.content.data."content-item"' | jq -r 'sort_by(.lastModified) | reverse | .[0] | .text')
latest_snapshot=$(echo $xml_content | xq '.content.data."content-item"' | jq -r .text)
echo $latest_snapshot
cd examples/java
mvn -B -U test -Dselenium.version="$latest_snapshot"
Expand All @@ -81,7 +81,7 @@ jobs:
command: |
pip install yq
$xml_content = Invoke-WebRequest -Uri "https://oss.sonatype.org/service/local/repositories/snapshots/content/org/seleniumhq/selenium/selenium-java/"
$latest_snapshot = $xml_content.Content | xq '.content.data.\"content-item\"' | jq -r 'sort_by(.lastModified) | reverse | .[0] | .text'
$latest_snapshot = $xml_content.Content | xq '.content.data.\"content-item\"' | jq -r .text
Write-Output $latest_snapshot
cd examples/java
mvn -B -U test "-Dselenium.version=$latest_snapshot"
109 changes: 109 additions & 0 deletions examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {
Expand Down Expand Up @@ -60,5 +67,107 @@ public void setAcceptInsecureCerts() {
driver.quit();
}
}

@Test
public void getBrowserName() {
ChromeOptions chromeOptions = new ChromeOptions();
String name = chromeOptions.getBrowserName();
Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
}

@Test
public void setBrowserVersion() {
ChromeOptions chromeOptions = new ChromeOptions();
String version = "latest";
chromeOptions.setBrowserVersion(version);
Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
}

@Test
public void setPlatformName() {
ChromeOptions chromeOptions = new ChromeOptions();
String platform = "OS X 10.6";
chromeOptions.setPlatformName(platform);
Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
}

@Test
public void setScriptTimeout() {
ChromeOptions chromeOptions = new ChromeOptions();
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
chromeOptions.setScriptTimeout(duration);

WebDriver driver = new ChromeDriver(chromeOptions);
try {
Duration timeout = driver.manage().timeouts().getScriptTimeout();
Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
} finally {
driver.quit();
}
}

@Test
public void setPageLoadTimeout() {
ChromeOptions chromeOptions = new ChromeOptions();
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
chromeOptions.setPageLoadTimeout(duration);

WebDriver driver = new ChromeDriver(chromeOptions);
try {
Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
} finally {
driver.quit();
}
}

@Test
public void setImplicitWaitTimeout() {
ChromeOptions chromeOptions = new ChromeOptions();
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
chromeOptions.setImplicitWaitTimeout(duration);

WebDriver driver = new ChromeDriver(chromeOptions);
try {
Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
} finally {
driver.quit();
}
}

@Test
public void setUnhandledPromptBehaviour() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
//verify the capability object is not null
Object capabilityObject = chromeOptions.getCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR);
Assertions.assertNotNull(capabilityObject, "Capability UNHANDLED_PROMPT_BEHAVIOUR should not be null.");
Assertions.assertEquals(capabilityObject.toString(), UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY.toString());
}

@Test
public void setWindowRect() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
//verify the capability object is not null
Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

Boolean capability = (Boolean) capabilityObject;
Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
}

@Test
public void setStrictFileInteractability() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
//verify the capability object is not null
Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

Boolean capability = (Boolean) capabilityObject;
Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
}
}

View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Browser name is set by default when using an Options class instance.

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L73-74" >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="examples/python/tests/drivers/test_options.py#L36" >}}
Expand All @@ -58,7 +58,7 @@ it will be automatically downloaded by [Selenium Manager]({{< ref "../../seleniu

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L80-82" >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="examples/python/tests/drivers/test_options.py#L37" >}}
Expand Down Expand Up @@ -114,7 +114,7 @@ event fire is returned.
{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L14-L16">}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L21-L23">}}
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L9-L10">}}
Expand Down Expand Up @@ -171,7 +171,7 @@ event fire is returned.
{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L27-L29">}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L34-L36">}}
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L19-L20">}}
Expand Down Expand Up @@ -227,7 +227,7 @@ WebDriver only waits until the initial page is downloaded.
{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L40-L42">}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L47-L49">}}
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L29-L30">}}
Expand Down Expand Up @@ -287,7 +287,7 @@ setting `platformName` sets the OS at the remote-end.

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L88-L90">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L38">}}
Expand Down Expand Up @@ -325,7 +325,7 @@ effect for the entire session.

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L60-L61">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L39-40">}}
Expand Down Expand Up @@ -360,7 +360,7 @@ is imposed when a new session is created by WebDriver.

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L96-L98">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L47-48">}}
Expand Down Expand Up @@ -389,7 +389,7 @@ _TimeoutException_.

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L111-L113">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L55-56">}}
Expand All @@ -416,7 +416,7 @@ is imposed when a new session is created by WebDriver.

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L126-L128">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L63-64">}}
Expand Down Expand Up @@ -454,7 +454,7 @@ user prompt encounters at the remote-end. This is defined by

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L141-L142">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L71-72">}}
Expand All @@ -479,7 +479,7 @@ Indicates whether the remote end supports all of the [resizing and repositioning

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L151-L152">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L79-80">}}
Expand Down Expand Up @@ -507,7 +507,7 @@ when using _Element Send Keys_ with hidden file upload controls.

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L163-L164">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L87-88">}}
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Browser name is set by default when using an Options class instance.

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L73-74" >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="examples/python/tests/drivers/test_options.py#L36" >}}
Expand Down Expand Up @@ -59,7 +59,7 @@ it will be automatically downloaded by [Selenium Manager]({{< ref "../../seleniu

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L80-82" >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="examples/python/tests/drivers/test_options.py#L37" >}}
Expand Down Expand Up @@ -112,7 +112,7 @@ WebDriver は [load](https://developer.mozilla.org/ja/docs/Web/API/Window/load_e

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L14-L16">}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L21-L23">}}
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L9-L10">}}
Expand Down Expand Up @@ -168,7 +168,7 @@ WebDriver は、[DOMContentLoaded](https://developer.mozilla.org/ja/docs/Web/API

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L27-L29">}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L34-L36">}}
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L19-L20">}}
Expand Down Expand Up @@ -223,7 +223,7 @@ WebDriver は、最初のページがダウンロードされるまで待機し

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L40-L42">}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L47-L49">}}
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L29-L30">}}
Expand Down Expand Up @@ -281,7 +281,7 @@ fun main() {

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L88-L90">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L38">}}
Expand Down Expand Up @@ -313,7 +313,7 @@ fun main() {

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L60-L61">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L39-40">}}
Expand Down Expand Up @@ -345,7 +345,7 @@ WebDriverの `セッション` には特定の `セッションタイムアウ

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L96-L98">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L47-48">}}
Expand All @@ -371,7 +371,7 @@ WebDriverの `セッション` には特定の `セッションタイムアウ

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L111-L113">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L55-56">}}
Expand All @@ -396,7 +396,7 @@ WebDriverの `セッション` には特定の `セッションタイムアウ

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L126-L128">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L63-64">}}
Expand Down Expand Up @@ -433,7 +433,7 @@ WebDriverの `セッション` には特定の `セッションタイムアウ

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L141-L142">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L71-72">}}
Expand All @@ -459,7 +459,7 @@ WebDriverの `セッション` には特定の `セッションタイムアウ

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L151-L152">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L79-80">}}
Expand All @@ -486,7 +486,7 @@ WebDriverの `セッション` には特定の `セッションタイムアウ

{{< tabpane text=true >}}
{{< tab header="Java" >}}
{{< badge-code >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java#L163-L164">}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L87-88">}}
Expand Down
Loading

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