Skip to content

Commit

Permalink
add informationtest.java file and added github code lines (#1560)
Browse files Browse the repository at this point in the history
[deploy site]
  • Loading branch information
pallavigitwork committed Jan 30, 2024
1 parent d7cd0f1 commit b63a295
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 266 deletions.
@@ -1,7 +1,71 @@
package dev.selenium.elements;

import dev.selenium.BaseTest;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Rectangle;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.time.Duration;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class InformationTest extends BaseTest {
public class InformationTest {

}
@Test
public void informationWithElements() {

WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
// Navigate to Url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

// isDisplayed
// Get boolean value for is element display
boolean isEmailVisible = driver.findElement(By.name("email_input")).isDisplayed();
assertEquals(isEmailVisible,true);

//isEnabled
//returns true if element is enabled else returns false
boolean isEnabledButton = driver.findElement(By.name("button_input")).isEnabled();
assertEquals(isEnabledButton,true);

//isSelected
//returns true if element is checked else returns false
boolean isSelectedCheck = driver.findElement(By.name("checkbox_input")).isSelected();
assertEquals(isSelectedCheck,true);

//TagName
//returns TagName of the element
String tagNameInp = driver.findElement(By.name("email_input")).getTagName();
assertEquals(tagNameInp,"input");

//GetRect
// Returns height, width, x and y coordinates referenced element
Rectangle res = driver.findElement(By.name("range_input")).getRect();
// Rectangle class provides getX,getY, getWidth, getHeight methods
assertEquals(res.getX(),10);


// Retrieves the computed style property 'font-size' of field
String cssValue = driver.findElement(By.name("color_input")).getCssValue("font-size");
assertEquals(cssValue, "13.3333px");


//GetText
// Retrieves the text of the element
String text = driver.findElement(By.tagName("h1")).getText();
assertEquals(text, "Testing Inputs");


//FetchAttributes
//identify the email text box
WebElement emailTxt = driver.findElement(By.name(("email_input")));
//fetch the value property associated with the textbox
String valueInfo = emailTxt.getAttribute("value");
assertEquals(valueInfo,"admin@localhost");


driver.quit();
}

}
Expand Up @@ -8,7 +8,7 @@
import java.time.Duration;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class InteractionTest {
public class InteractionTest{

@Test
public void interactWithElements() {
Expand Down
Expand Up @@ -24,14 +24,10 @@ executing a large JavaScript function directly.
This function makes many approximations about an element's
nature and relationship in the tree to return a value.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
// Navigate to the url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

// Get boolean value for is element display
boolean isEmailVisible = driver.findElement(By.name("email_input")).isDisplayed();
{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L20-L25" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to the url
Expand Down Expand Up @@ -77,14 +73,9 @@ Returns a boolean value, **True** if the connected element is
**enabled** in the current browsing context else returns **false**.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
//navigates to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

//returns true if element is enabled else returns false
boolean value = driver.findElement(By.name("button_input")).isEnabled();
{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L27-L30" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
Expand Down Expand Up @@ -131,14 +122,9 @@ Returns a boolean value, **True** if referenced element is
**selected** in the current browsing context else returns **false**.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
//navigates to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

//returns true if element is checked else returns false
boolean value = driver.findElement(By.name("checkbox_input")).isSelected();
{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L32-L35" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
Expand Down Expand Up @@ -178,14 +164,9 @@ It is used to fetch the [TagName](https://www.w3.org/TR/webdriver/#dfn-get-eleme
of the referenced Element which has the focus in the current browsing context.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
//navigates to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

//returns TagName of the element
String value = driver.findElement(By.name("email_input")).getTagName();
{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L37-L40" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
Expand Down Expand Up @@ -231,17 +212,9 @@ The fetched data body contain the following details:
* Width of the element

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
// Navigate to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

// Returns height, width, x and y coordinates referenced element
Rectangle res = driver.findElement(By.name("range_input")).getRect();

// Rectangle class provides getX,getY, getWidth, getHeight methods
System.out.println(res.getX());
{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L42-L46" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
Expand Down Expand Up @@ -287,16 +260,9 @@ Retrieves the value of specified computed style property
of an element in the current browsing context.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}

// Navigate to Url
driver.get("https://www.selenium.dev/selenium/web/colorPage.html");

// Retrieves the computed style property 'color' of linktext
String cssValue = driver.findElement(By.id("namedColor")).getCssValue("background-color");

{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L49-L51" >}}
{{< /tab >}}
{{< tab header="Python" >}}

# Navigate to Url
Expand Down Expand Up @@ -343,14 +309,9 @@ val cssValue = driver.findElement(By.id("namedColor")).getCssValue("background-c
Retrieves the rendered text of the specified element.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
// Navigate to url
driver.get("https://www.selenium.dev/selenium/web/linked_image.html");

// Retrieves the text of the element
String text = driver.findElement(By.id("justanotherlink")).getText();
{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L54-L57" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to url
driver.get("https://www.selenium.dev/selenium/web/linked_image.html")
Expand Down Expand Up @@ -393,17 +354,9 @@ DOM attribute. It returns the data associated
with the DOM attribute or property of the element.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
//Navigate to the url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

//identify the email text box
WebElement emailTxt = driver.findElement(By.name(("email_input")));

//fetch the value property associated with the textbox
String valueInfo = eleSelLink.getAttribute("value");
{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L60-L65" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to the url
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
Expand Down
Expand Up @@ -24,13 +24,10 @@ executing a large JavaScript function directly.
This function makes many approximations about an element's
nature and relationship in the tree to return a value.

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" >}}
// Navigate to the url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

// Get boolean value for is element display
boolean isEmailVisible = driver.findElement(By.name("email_input")).isDisplayed();
{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L20-L25" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to the url
Expand Down Expand Up @@ -73,13 +70,9 @@ val = driver.find_element(name: 'email_input').displayed?
**有効(enabled)** になっている場合は **True** 、そうでない場合は **false** を返します。

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" >}}
//navigates to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

//returns true if element is enabled else returns false
boolean value = driver.findElement(By.name("button_input")).isEnabled();
{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L27-L30" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
Expand Down Expand Up @@ -124,13 +117,9 @@ ele = driver.find_element(name: 'button_input').enabled?
ブール値を返し、現在のブラウジングコンテキストで参照された要素が **選択されている** 場合は **True** 、そうでない場合は **false** を返します。

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" >}}
//navigates to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

//returns true if element is checked else returns false
boolean value = driver.findElement(By.name("checkbox_input")).isSelected();
{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L32-L35" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
Expand Down Expand Up @@ -170,13 +159,9 @@ ele = driver.find_element(name: "checkbox_input").selected?
[TagName](https://www.w3.org/TR/webdriver/#dfn-get-element-tag-name) を取得するために使います。

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" >}}
//navigates to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

//returns TagName of the element
String value = driver.findElement(By.name("email_input")).getTagName();
{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L37-L40" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
Expand Down Expand Up @@ -220,17 +205,11 @@ attr = driver.find_element(name: "email_input").tag_name
* 要素の高さ
* 要素の幅

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" >}}
// Navigate to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

// Returns height, width, x and y coordinates referenced element
Rectangle res = driver.findElement(By.name("range_input")).getRect();

// Rectangle class provides getX,getY, getWidth, getHeight methods
System.out.println(res.getX());
{{< /tab >}}
{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L42-L46" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to url
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
Expand Down Expand Up @@ -275,15 +254,9 @@ println(res.getX())
現在のブラウジングコンテキスト内の要素の指定された計算したスタイル属性の値を取得します。

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" >}}

// Navigate to Url
driver.get("https://www.selenium.dev/selenium/web/colorPage.html");

// Retrieves the computed style property 'color' of linktext
String cssValue = driver.findElement(By.id("namedColor")).getCssValue("background-color");

{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L49-L51" >}}
{{< /tab >}}
{{< tab header="Python" >}}

# Navigate to Url
Expand Down Expand Up @@ -331,13 +304,9 @@ val cssValue = driver.findElement(By.id("namedColor")).getCssValue("background-c


{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" >}}
// Navigate to url
driver.get("https://www.selenium.dev/selenium/web/linked_image.html");

// Retrieves the text of the element
String text = driver.findElement(By.id("justanotherlink")).getText();
{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L54-L57" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to url
driver.get("https://www.selenium.dev/selenium/web/linked_image.html")
Expand Down Expand Up @@ -378,16 +347,9 @@ DOM attribute. It returns the data associated
with the DOM attribute or property of the element.

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" >}}
//Navigate to the url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

//identify the email text box
WebElement emailTxt = driver.findElement(By.name(("email_input")));

//fetch the value property associated with the textbox
String valueInfo = eleSelLink.getAttribute("value");
{{< /tab >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L60-L65" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# Navigate to the url
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
Expand Down

0 comments on commit b63a295

Please sign in to comment.