0% found this document useful (0 votes)
147 views

Intellij Selenium Code For Automation

This document contains the code for 4 test methods that perform various validation tests using Selenium WebDriver. The first test enters text into a form, clicks a button, and validates the result. The second test enters numbers, clicks to calculate a total, and validates the result. The third test selects options from a dropdown and validates the selection. The fourth test searches a site and validates the search results.

Uploaded by

Andrei ShadowS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

Intellij Selenium Code For Automation

This document contains the code for 4 test methods that perform various validation tests using Selenium WebDriver. The first test enters text into a form, clicks a button, and validates the result. The second test enters numbers, clicks to calculate a total, and validates the result. The third test selects options from a dropdown and validates the selection. The fourth test searches a site and validates the search results.

Uploaded by

Andrei ShadowS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

@org.testng.annotations.

Test

public void primulTest(){

System.setProperty("webdriver.chrome.driver","D:\\kit\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
String keyword = "primul test";
driver.get("https://www.seleniumeasy.com/test/basic-first-form-demo.html");

WebElement inputField = driver.findElement(By.id("user-message"));


inputField.sendKeys(keyword);
WebElement showMessage = driver.findElement(By.xpath("//*[@id=\"get-
input\"]/button"));
showMessage.click();
WebElement resultMessage = driver.findElement(By.id("display"));
Assert.assertEquals(resultMessage.getText() , keyword);
driver.quit();
}
}

import net.bytebuddy.utility.RandomString;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Test {


@org.testng.annotations.Test

public void primulTest() {

System.setProperty("webdriver.chrome.driver", "D:\\kit\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
String keyword = "primul test";
driver.get("https://www.seleniumeasy.com/test/basic-first-form-demo.html");

WebElement inputField = driver.findElement(By.id("user-message"));


inputField.sendKeys(keyword);
WebElement showMessage = driver.findElement(By.xpath("//*[@id=\"get-
input\"]/button"));
showMessage.click();
WebElement resultMessage = driver.findElement(By.id("display"));
Assert.assertEquals(resultMessage.getText(), keyword);
driver.quit();
}
@org.testng.annotations.Test

public void alDoileaTest() {

System.setProperty("webdriver.chrome.driver", "D:\\kit\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

int nr1 = 4;
int nr2 = 3;
int sum = nr1 + nr2;
driver.get("https://www.seleniumeasy.com/test/basic-first-form-demo.html");

WebElement firstField = driver.findElement(By.id("sum1"));


firstField.sendKeys(String.valueOf(nr1));
WebElement secondField = driver.findElement(By.id("sum2"));
secondField.sendKeys(String.valueOf(nr2));
WebElement getTotal =
driver.findElement(By.xpath("//*[@id=\"gettotal\"]/button"));
getTotal.click();
WebElement totalValue = driver.findElement(By.id("displayvalue"));
driver.quit();

@org.testng.annotations.Test
public void alTreileaTest() {

System.setProperty("webdriver.chrome.driver",
"D:\\kit\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.seleniumeasy.com/test/basic-select-dropdown-
demo.html");
WebElement dropdownButton = driver.findElement(By.id("select-demo"));
Select selector = new Select(dropdownButton);
selector.selectByValue("Monday");
int index;
for(index=0; index <=7; index++);

selector.selectByIndex(index);
WebElement result =
driver.findElement(By.xpath("//*[@id=\"easycont\"]/div/div[2]/div[1]/div[2]/p[2]"))
;
switch(index){
case 1:
Assert.assertEquals(result.getText(), "Day selected :- Sunday") ;
}

@org.testng.annotations.Test

public void alPatruleaTest() {

System.setProperty("webdriver.chrome.driver", "D:\\kit\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.get("https://www.decathlon.ro/");
WebElement decathlonLogo = driver.findElement(By.id("dkt-logo"));
Assert.assertTrue(decathlonLogo.isDisplayed());

WebElement searchBar = driver.findElement(By.id("header-searchbar"));

List<String> listaCautari = new ArrayList<String>();


listaCautari.add("placa de snowboard");
listaCautari.add("gantere");
listaCautari.add("racheta tenis");

Random random = new Random();

String keyword = listaCautari.get(random.nextInt(2));

searchBar.click();
searchBar.sendKeys(keyword);
searchBar.sendKeys(Keys.RETURN);
WebElement searchResult =
driver.findElement(By.xpath("//*[@id=\"middle\"]/div[2]/div[1]/h1"));

Assert.assertEquals(searchResult.getText().toLowerCase(),keyword.toLowerCase());

}
}

You might also like