The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.
Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by Saurabh Kamble, 2023-01-02 02:22:12

Selenium Notes

Selenium Notes

password.sendKeys("Password");
Thread.sleep(3000);

//login button

WebElement loginButton = driver.findElement(By.id("u_0_5_eH"));
loginButton.click();

}

}
Program-3 orange hrm login

package automationPractice;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import io.opentelemetry.exporter.logging.SystemOutLogExporter;

public class ORangeHRMProgram
{

public static void main(String[] args) throws
InterruptedException

{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan

Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://opensource-demo.orangehrmlive.com/");

Thread.sleep(3000);

//username
WebElement userName =
driver.findElement(By.name("txtUsername"));
userName.sendKeys("Admin");
Thread.sleep(3000);

//password

// WebElement password =
driver.findElement(By.linkText("Password"));

//or -->partial value of html text
// WebElement password =
driver.findElement(By.partialLinkText("Pass"));

WebElement password =
driver.findElement(By.id("txtPassword"));

password.sendKeys("admin123");
Thread.sleep(3000);

//login
WebElement loginButton =
driver.findElement(By.id("btnLogin"));
loginButton.click();

System.out.println("end of program");

}

}











Assignement

Program-1 saucedemo website

package automationPractice;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class SauceDemo1
{

public static void main(String[] args) throws
InterruptedException

{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan

Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();
driver.get("https://www.saucedemo.com/");

Thread.sleep(3000);

//username,password,loginButton
//xpath by attribute

// username xpath -->
WebElement username

=driver.findElement(By.xpath("//input[@id='user-name']"));
username.sendKeys("standard_user");
Thread.sleep(3000);

//password xpath

WebElement password =
driver.findElement(By.xpath("//input[@name='password']"));

password.sendKeys("secret_sauce");
Thread.sleep(3000);

//login xpath
WebElement loginButton =
driver.findElement(By.xpath("//input[@value='Login']"));
loginButton.click();

System.out.println("end of program");

}

}
Program2-orangehrm website

package automationPractice;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class OrangeHRM
{

public static void main(String[] args) throws
InterruptedException

{
System.setProperty("webdriver.chrome.driver",

"D:\\Back-up Data\\Desktop-Backup\\Pavan
Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://opensource-demo.orangehrmlive.com/");

Thread.sleep(3000);

//username xpath
//xpath by text
// WebElement username =
driver.findElement(By.xpath("//span[text()='Username']"));
// username.sendKeys("Admin");
// Thread.sleep(3000);
//
// //password
// WebElement password =
driver.findElement(By.xpath("//span[text()='Password']"));
// password.sendKeys("admin123");
// Thread.sleep(3000);
//
// //login
// WebElement loginButton =
driver.findElement(By.xpath("//div[@id='divLoginButton']"));
// loginButton.click();

//try this xpath by text
WebElement forgetPassword =
driver.findElement(By.xpath("//a[text()='Forgot your password?']"));
forgetPassword.click();
}

}









Program1

package automationPractice;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class OrangeHRMProgram1
{

public static void main(String[] args) throws
InterruptedException

{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan

Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get("https://opensource-demo.orangehrmlive.com/");

Thread.sleep(3000);

//case-I
//xpath by attribute

// WebElement userName =
driver.findElement(By.xpath("//input[@id='txtUsername']"));
// userName.sendKeys("Admin");
// Thread.sleep(3000);
//
// WebElement password =
driver.findElement(By.xpath("//input[@id='txtPassword']"));
// password.sendKeys("admin123");
// Thread.sleep(3000);
//
// WebElement loginButton =
driver.findElement(By.xpath("//input[@id='btnLogin']"));
// loginButton.click();
// Thread.sleep(3000);

//--------------------
// case-II
// xpath by contains
// WebElement username =
driver.findElement(By.xpath("//input[contains(@id, 'txtUsername')]"));
// username.sendKeys("Admin");
// Thread.sleep(3000);
//
// WebElement password =
driver.findElement(By.xpath("//input[contains(@id, 'txtPassword')]"));
// password.sendKeys("admin123");
// Thread.sleep(3000);

// WebElement loginButton =
driver.findElement(By.xpath("//input[contains(@id, 'btnLogin')]"));
// loginButton.click();

//--------------------
//case-III
// xpath by conatins by text

// WebElement forgotPassword =
driver.findElement(By.xpath("//a[contains(text(), 'Forgot your
password?')]"));
// forgotPassword.click();

}

}
Program2
package automationPractice;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class SauceDemo2
{

public static void main(String[] args) throws
InterruptedException

{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan

Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.saucedemo.com/");

Thread.sleep(3000);

//case-IV-xpath by index

WebElement userName =
driver.findElement(By.xpath("(//input[@class='input_error
form_input'])[1]"));

userName.sendKeys("standard_user");

Thread.sleep(3000);

WebElement password =
driver.findElement(By.xpath("(//input[@class='input_error
form_input'])[2]"));

password.sendKeys("secret_sauce");
Thread.sleep(3000);

WebElement login =
driver.findElement(By.xpath("//input[@class='submit-button
btn_action']"));

login.click();

}

}
Difference of xpath methods

Case-1

Case-2
Xpath by index approach

Automation Practice Website
1.
https://opensource-demo.orangehrmlive.com/index.php/auth/login

2.
https://www.saucedemo.com/

3. for scenario practice
http://practice.automationtesting.in/test-cases/

4. test scenarios for multiple situations
https://artoftesting.com/test-scenario-examples

























package automationPractice;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class SauceDemo3
{

public static void main(String[] args) throws
InterruptedException

{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan

Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.saucedemo.com/");

Thread.sleep(3000);

//absoulte xpath
//username,password, loginbutton

// WebElement userName =
driver.findElement(By.xpath("/html/body/div/div/div[2]/div[1]/div[1]/d
iv/form/div[1]/input"));
// userName.sendKeys("standard_user");
// Thread.sleep(3000);

//
// WebElement password =
driver.findElement(By.xpath("/html/body/div/div/div[2]/div[1]/div[1]/d
iv/form/div[2]/input"));
// password.sendKeys("secret_sauce");
// Thread.sleep(3000);

//relative xpath

WebElement userName =
driver.findElement(By.xpath("//form//div[1]//input"));

userName.sendKeys("standard_user");
Thread.sleep(3000);

WebElement password =
driver.findElement(By.xpath("//form//div[2]//input"));

password.sendKeys("secret_sauce");
Thread.sleep(3000);

//absolute
WebElement loginButton =

driver.findElement(By.xpath("/html/body/div/div/div[2]/div[1]/div[1]/d
iv/form/input"));

loginButton.click();
Thread.sleep(3000);

//relative xpath for login button on sauceDemo

}

}

Document object model and how to write a script
package automationPractice;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class SauceDemo3
{

public static void main(String[] args) throws InterruptedException
{

//DOM model --> Document object model

System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan Velo\\Automation

Batch Material\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
System.out.println("Browser is opened");

driver.manage().window().maximize();
System.out.println("Browser is maximized");

driver.get("https://www.saucedemo.com/");
System.out.println("URL is opened");
Thread.sleep(3000);

WebElement userName = driver.findElement(By.xpath("//form//div[1]//input"));
userName.clear(); //-->caches/cookies clear
userName.sendKeys("standard_user");
System.out.println("Username is entered");
Thread.sleep(3000);

WebElement password = driver.findElement(By.xpath("//form//div[2]//input"));
password.clear();
password.sendKeys("secret_sauce");
System.out.println("Password is entered");
Thread.sleep(3000);

WebElement loginButton =
driver.findElement(By.xpath("/html/body/div/div/div[2]/div[1]/div[1]/div/form/input"));

loginButton.click();
System.out.println("Clicked on login Button");
Thread.sleep(3000);

//verify whether u went on home page or not
//getCurrentURL
//getTitle

String expectedTitle = "Swag Labs"; //given

String actualTitle = driver.getTitle(); //actual

if(expectedTitle.equals(actualTitle))
{

System.out.println("we have successfully logined to saucedmo ");
System.out.println("Test case is passed");
}
else
{

System.out.println("Test case is failed");
}

driver.close();
System.out.println("broswer is closed");

}

}

package automationPractice;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class MethodOfWebElement2
{

public static void main(String[] args) throws
InterruptedException

{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan

Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");

WebDriver driver = new ChromeDriver();
System.out.println("Browser is opened");

driver.manage().window().maximize();
System.out.println("Browser is maximized");

driver.get("https://www.saucedemo.com/");
System.out.println("URL is opened");
Thread.sleep(3000);

WebElement userName =
driver.findElement(By.xpath("//form//div[1]//input"));

//this method will bring a attribute value of id attribute
String attributeValue = userName.getAttribute("id");
System.out.println("attributeValue-"+attributeValue);

//get text method--html text bring

String htmlText = userName.getText();
System.out.println("htmlText-"+htmlText);

//tagname
String tagName = userName.getTagName();
System.out.println("tagName-"+tagName);

}

}





package automationPractice;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class IsDisplayedMethod
{

public static void main(String[] args) throws
InterruptedException

{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan

Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://vctcpune.com/selenium/practice.html");

Thread.sleep(5000);

//1.isDisplayed method

// //hideButton

// WebElement hideButton =

driver.findElement(By.xpath("//input[@id='hide-textbox']"));

// hideButton.click();

// Thread.sleep(5000);

//

// //textBox

// WebElement textBox =

driver.findElement(By.xpath("//input[@id='displayed-text']"));

//

// boolean result = textBox.isDisplayed();

// System.out.println(result); //false

// Thread.sleep(5000);

//

// //showButton

// WebElement showButton =

driver.findElement(By.xpath("//input[@id='show-textbox']"));

// showButton.click();

// Thread.sleep(5000);

//

// boolean result1 = textBox.isDisplayed();

// System.out.println("after clicking on show button-"

+result1); //true

//

// if(result1 == true)

// {

// textBox.sendKeys("INDIA");

// }

// else

// {

// showButton.click();

// textBox.sendKeys("INDIA");

// }

//2 isEnabled Method

// WebElement textBox =
driver.findElement(By.xpath("//input[@id='displayed-text']"));
//
// boolean result = textBox.isEnabled(); //true
// System.out.println(result);
//

// if(result == true)
// {
// textBox.sendKeys("India");
// }
// else
// {
// System.out.println("we cant enter the value in the
text the text box");
// }

//3.isSelected

WebElement radioButton =
driver.findElement(By.xpath("//input[@value='Radio1']"));

boolean result = radioButton.isSelected();
System.out.println("initailly-"+result); //false

if(result ==false)
{

radioButton.click();
boolean result1 = radioButton.isSelected();
System.out.println("after clicking-"+result1);
}
else
{
System.out.println("radio button is already
selected");
}

}

}



package automationPractice;

import org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.chrome.ChromeDr
iver;

import
org.openqa.selenium.support.ui.Sele
ct;

public class DropDownHandle
{

public static void main(String[]
args) throws InterruptedException

{

System.setProperty("webdriver.ch
rome.driver",

"D:\\Back-up
Data\\Desktop-Backup\\Pavan
Velo\\Automation Batch
Material\\Downloads\\chromedriver_w
in32\\chromedriver.exe");

WebDriver driver = new
ChromeDriver();

System.out.println("Browser is
opened");

driver.manage().window().maximiz
e();

System.out.println("Browser is
maximized");

driver.get("https://vctcpune.com
/selenium/practice.html");

System.out.println("URL is
opened");

Thread.sleep(3000);

//dropdown handle
//dropdown element inspect

WebElement dropDown =
driver.findElement(By.xpath("//sele
ct[@id='dropdown-class-
example']"));

dropDown.click();

//selenium Select class

Select s = new
Select(dropDown);

// s.selectByIndex(1);
//or

//value attribute-->attribute
value pass
// s.selectByValue("option2");

//or
//pass the html text

s.selectByVisibleText("Option3")
;


Click to View FlipBook Version