NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

java sele


first- project is nothing but a test suite which can store collection of test cases.

Selenium api in java language

java language- java class file

each java file is one test case


create object for chrome browser





System.out.println("yolo");


System.setProperty("webdriver.chrome.driver", "/Users/ishaanvashist/Documents/chromedriver-2");

WebDriver driver = new ChromeDriver();//class

driver.get("http://.com");

1.to get the title———— System.out.println(driver.getTitle());

2. to get the url———— System.out.println(driver.getCurrentUrl()); //to see if the url is correct


3. to get page source or to print pages in inspect tool right click- System.out.println(driver.getPageSource());



driver.get("http://google.com");
driver.get("http://yahoo.com");
driver.navigate().back();


driver.close();——— to navigate front or back in the browser



driver.close();——— to close the tabs
driver.quit();——— to quit the tabs






“+” is a concatenation operator in Java




——————————————————————————————
——————————————————————————————


basic java program:




int a= 5;
int b=6;
int c= a + b;

System.out.println("sum is" + c);




——————————————————————————————
——————————————————————————————





driver.findElement(By.id("email")).sendKeys("hello");
driver.findElement(By.id("pass")).sendKeys("hegdgdgdgdgdgdgdgdgdgdg");

driver.findElement(By.linkText("ਪਾਸਵਰਡ ਭੁੱਲ ਗਏ ਹੋ?")).click();


find elements by different names, id, link texts , css


miscl——

driver.findElement(By.id("username")).sendKeys("hello");

driver.findElement(By.id("password")).sendKeys("yoloooo");
driver.findElement(By.id("Login")).click();


for x path just right click and hit copy x path - //*[@id="Login”]— convert the double inverted comma to single as the java won’t accept it
for css selector just right click and hit copy css selector-



$x()——————————— this is used to validate the x path or to see if its correct— for x path

for css only $ and no x hence $()



———————————————————————————————— ———————————————————————————————— ———————————————————————————————— ————————————————————————————————





customise path:

code— $x("//input[@id='password’]”)— for console

//tagname[@atttribe=‘value’]


input[type='password’]— for css

Tagname[attritbe=‘value’];




So, basically the objects are used as locators for the webelement. we give the location of the webelement and objects locate them.

if the tag name is select- its static as it won’t change:

the index will always start from 0.


————————————————————————————————————————————————————————————————————————————————————


//dropdown with select tag
1.
// creating an object for the dropdown-select



WebElement staticDropdown= driver.findElement(By.id("ctl00_mainContent_DropDownListCurrency"));
Select dropdown= new Select(staticDropdown);
System.out.println(dropdown.getFirstSelectedOption().getText());

dropdown.selectByIndex(3);



2. normal dropdown



With while loop.





//to print or click 40times

int i=1;
while(i<5)

{
driver.findElement(By.id("hrefIncAdt")).click();
i++;
}

//to make it run for 4 times

driver.findElement(By.id("btnclosepaxoption")).click();





lecture 49
Using the same with for loop:


for(int i=1;i<5;i++)
{


driver.findElement(By.id("hrefIncAdt")).click();


}



driver.findElement(By.id("btnclosepaxoption")).click();

System.out.println(driver.findElement(By.id("divpaxinfo")).getText());







—————————————————————————————————————————


Dynamic dropdown:



just click on the website and the city walls dropdown id uthao and use chromate. easy.

driver.findElement(By.id("ctl00_mainContent_ddl_originStation1_CTXT")).click();




driver.findElement(By.xpath("//a[@value='BLR']")).click();
Thread.sleep(2000L);
driver.findElement(By.xpath("//a[@value='MAA'])[2]")).click();


——————————————————————————————————————————————————————————————————————————————————


checkboxes:





driver.get("https://spicejet.com");
System.out.println(driver.findElement(By.cssSelector("input[id*='SeniorCitizenDiscount']")).isSelected());
driver.findElement(By.cssSelector("input[id*='SeniorCitizenDiscount']")).click();
System.out.println(driver.findElement(By.cssSelector("input[id*='SeniorCitizenDiscount']")).isSelected());


//count the number of checkboxes


System.out.println(driver.findElements(By.cssSelector("input[type='checkbox']")).size());
——————————————————————————————————————————————————————————————————————————————————

——————————————————————————————————————————————————————————————————————————————————

——————————————————————————————————————————————————————————————————————————————————


Test ng has brought assertions:

assertions means true and false. if we expect 1 and result is 6, it comes false .
vise versa.

import org.testng.Assert;— plugin required

Assert.assertFalse(driver.findElement(By.cssSelector("input[id*='SeniorCitizenDiscount']")).isSelected());
or
Assert True to see if its true



Invocation cout is used to run a script n number of time——its also a helper attribute—————(timeout=6000)


parallel=test is used to execute tests in parallel. thread-count-6
——————————————————————————————————————


for class in chropath.

just put. in front of it and spaces with - replace it by a dot(.)




for current date in calendar:
driver.findElement(By.cssSelector(".ui.state.default ui.state.highlight ui.state.active")).click();

——————————————————————————————————————
——————————————————————————————————————
——————————————————————————————————————



Regarding the calendar which is not active:

To see if the calendar button is enabled or not- check automatically with assert and if.

Assert.assertTrue(true)



System.out.println(driver.findElement(By.id("Div1")).getAttribute("style"));
driver.findElement(By.id("ctl00_mainContent_rbtnl_Trip_1")).click();
System.out.println(driver.findElement(By.id("Div1")).getAttribute("style"));

//System.out.println(driver.findElement(By.id("ctl00_mainContent_view_date1")).isEnabled());

if(driver.findElement(By.id("Div1")).getAttribute("style").contains("1"));
{
System.out.println("enabled");
Assert.assertTrue(true)

}
else
{


Assert.assertTrue(False)




very easy.


===============================================================================================






Alerts as in basic alert :

use string to write in bocages string name =“ishaan”;

driver.findElement(By.id("name")).sendKeys(text); —— just grab the id and

driver.switchTo().alert().accept();
driver.swicthto.alert.dismiss






===============================================================================================



/implicit wait

the test which are 100 steps, we tell test globally to wait for n seconds , it will wait for it.

1. advantage is defining it globally. it is active till entire test case.

1. it will not wait for entire 5 second , if it loads earlier it will show results.


disadvantage- 100 test cases plan. wait for 5 second. situation-


/explicit wait-

You can target a specific elements, all hotel location search .if implicit wait is 5 seconds but out hotel result is taking 15 seconds, we can apply that on it.

driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS)
Synchonization- both are important . in real time both are combinely used.




/ thread.sleep— 5 seconds to load
to wait got 5 seconds.— it’ll keep on waiting even if it is loaded unlike implicit wait.





===============================================================================================


Mouse over in selenium.



how do you write something in capital letter, driving and delivering + HOW TO MOVE MOUSE.


Thats done by actions class.



Actions a=new Actions(driver);

a.moveToElement(driver.findElement(By.cssSelector( "a[id=‘nav-link-accountList’]"))).build().perform();







//moves to a specific element


//ass.moveToElement(driver.findElement(By.cssSelector("a[id='nav-link-accountList']"))).build().perform();








to enter text in a text box and highlight it- easy:

Actions ass=new Actions(driver);

//input[id='twotabssearchtextbox']



//the value of move element is put in this one to make it easier
WebElement moo= driver.findElement(By.cssSelector("a[id='nav-link-accountList']"));

ass.moveToElement(driver.findElement(By.id("twotabsearchtextbox"))).click().keyDown(Keys.SHIFT).sendKeys("chalja yaar").doubleClick().build().perform();
//moves to a specific element


ass.moveToElement(moo).contextClick().build().perform();




===============================================================================================


Window handles— basically to move the script from parent to child or one page to other and grab a text or anything of the sort.






driver.findElement(By.cssSelector("a[class='blinkingText']")).click();;

Set<String> windows= driver.getWindowHandles();// [parent id, child id] //get window handles gets both the ids
Iterator<String> it =windows.iterator();
String ParentId=it.next();
String ChildId=it.next();


driver.switchTo().window(ChildId);

System.out.println (driver.findElement(By.cssSelector(".im-para,red")).getText());





//a[class='blinkingText']



driver.findElement(By.cssSelector("a[class='blinkingText']")).click();;

Set<String> windows= driver.getWindowHandles();// [parent id, child id] //get window handles gets both the ids
Iterator<String> it =windows.iterator();
String ParentId=it.next();
String ChildId=it.next();


driver.switchTo().window(ChildId);

System.out.println (driver.findElement(By.cssSelector(".im-para,red")).getText());





==============================================================================================================================================================================================




Framework Learning:






Test ng: also known as a testing framework.

Basic test ng program:


package testngmain;

import org.testng.annotations.Test;

public class Day1 {



@Test //whatevr follows the test annotation runs as a test
public void Demo()//thats how we write in TestNg

{

//now we know hoow to run test in testng

System.out.println("hello"); //automation //annotation followed by@Test followed by methiod public voiddemo(){}


}




}



important points:

1. How we know hoow to run test in testng

2. //annotation followed by@Test followed by methiod public voiddemo(){}

3. test suits>test folder>test cases(test folder is test modeule>





an xml file looks like this:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Loan Department">
<test thread-count="5" name="Personal Loan">
<classes>
<class name="testngmain.Day1"/> //that’s how an xml file looks, suite name is the maine name.
<class name="testngmain.Day2"/> you can put any file under anyone whenever required
<class name="testngmain.Day3"/>
<class name="testngmain.Day4"/> //modularities the test cases based on the functionality and trigger them accordinggly

//different java files like . day 1 for home loan. day 2 for car loan, day 3 for agricultural loan. they all will be different test cases. and all will be combined in an xml file


If we have to skip one test file particular then.





m
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->


Parallel= thread.count in xml file


————————————————————————————————————————————————

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Loan Department">
<test name="Personal Loan">
<classes>

<class name="testngmain.Day1"/>
<class name="testngmain.Day101"/>

</classes>
</test>

<test name="Car Loan">


you can put different test cases in different areas .



<classes>



<class name="testngmain.day102">




</class>



</classes>
————————————————————————————————————————————————————






<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Loan Department">
<test name="Personal Loan">
<classes>

<class name="testngmain.Day1">

<methods>
<include name="blahhh"/>
</methods>

</class>

<class name="testngmain.Day101"/>


</test>

<test name="Car Loan"/>



<classes>

<class name="testngmain.day100"> <!-- -->car loan test cases run please only// modify it.-->

<methods>

<exclude name="WebLoginCarLoan"></exclude>

<!--basically skip one class in this. exclude one metho from day 100, include also works in the same way,if client ask to include one-->

</methods>


</class>



</classes>



></test>



<!-- Test -->
</suite> <!-- Suite -->



basically to include and exclude in this section.

if the client asks to eliminate with. certain keyword that’s would happen as API.* is used to eliminate particular keyword. i xml file




We can also run package by passing package name.

<package name= Test”/>


——————————————————————————————————————————————————————————————


Test NG annotations:


@BeforeTest- it will come to xml file and treat entire as one folder.


@before test will be executed first, it will execute first, giving it in day 101 or anywhere. but it will always execute first.




@AfterTest- vise versa.. it is done in day 100’s wala folder— at the end of test folder only.


@BeforeSuite———its generally if you want to set different environment variables— before test starts- it loads up the url’s etc
it is executed first— write the code in day 101, or anywhere. it will run first.

@AfterSuite— vice versa


@beforemethod—— it is limited to class file. in a file like 101, or 102.

it will execute before every method.

@aftermethod— executes after every method


@Beforeclass- mean the whole class will get executed before, or before executing any method in a class.

@Afterclass-Vise versa


It uses alphabetical order




—clear cut understandings about annotations
—if a client wants to pick up only 4 tests from 100 tests and wants to trigger as per for smoke test.. We use groups for that….


@Test(groups={“smoke”}

Groups are written right after the test name in the xml files.

<groups>
<run>

<include name=“Smoke”/>

</run>

</groups>



——————————————————


@Dependsonmethod is used in class level—one test is executed before the other.


@enabled=false—— it will skip the execution.

There are few errors in applications— @enabled=false; with help of test NG helper attribute.\



If one test case is longer time to load — can use implicit wait, but that’s not advisable.


There we use TimeOut

@Test(timeOut=4000)——— it will not fail during execution.



————————————————————————————————————


PARAMETERIZATION IS TESTNG:



Gobal environment variables;——— its written under suite—


<parameter name=“URL” value=“qaclick


@parameter({“URL”})
@Test
public void() WebloginCar(String url name)———————in this a string is used to store the url name

{

system.out.println(“hello”);
system.out.println(url name);————————here it gets executed
}


You have to use parameter every time there is a need for it.


Global environment variables can be incorporated through selenium. Parametrizing with multiple data sets by running tests with multiple combination
——————————————————————————————————————————————————


Listeners are a part of TestNg and are used to take screenshots of the failed test, btw that’s an example

and on test failures.

Listener will be executed after test failures.
implements all the time.




import org.testng.ITestListener;

public class Listeners implements ITestListener {}





——————————————————————————————————



How to drive the global environmental values from external files:




From one page to another you can get a value: 1st page. is normal java file. 2nd-other-file——name——anything.property






code is below:




public class nigger {

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub


Properties prop=new Properties();


FileInputStream fis= new FileInputStream("/Users/ishaanvashist/eclipse-workspace/Corejavaa/src/coreJava/deta.properties");

prop.load(fis);

System.out.println(prop.getProperty("browser"));

FileOutputStream fos= new FileOutputStream("/Users/ishaanvashist/eclipse-workspace/Corejavaa/src/coreJava/deta.properties");

prop.store(fos,null);

}


————————————————————————————————————————


Maven: is a software project management and building tool for java frameworks. apache maven


they have the jars of every language or project in their repository, central repository to get dependencies.—— so basically you don’t needs to go and find the jars if you have to show it to the other colleague or client, maven will take care of itself with the help of a code given on their website.

2— in a company different people do different things, to bring consistency- they will give common empty skeleton.

3.continuous integrating tool-to provide jenkins for 1000 test cases— as build management tool

all test ng and g quit plugins are available


continuous integration.




why maven ? the answer is above.

— identify by ======= group id—artefact id is jar name or sub object——

maven reads group id and after understanding that— this guy wants something from selenium- then it will go to artefact id—subproject—

after that it will look at the version 3.6.0.

this way group and artefact id plays an important role.



- gives simple skeleton


in real time— with skeleton— then test cases.















     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.