Posts

Showing posts from 2023

Selenium 4 with Java

Image
 Chrome Driver: import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; System. setProperty ( "webdriver.chrome.driver" , "C:\\libs\\drivers\\chromedriver.exe" ); WebDriver driver = new ChromeDriver(); Gecko Driver: System. setProperty ( "webdriver.gecko.driver" , "C:\\libs\\drivers\\geckodriver.exe" ); WebDriver driver = new FirefoxDriver(); Set Drivers in system path: Note : If your browser is upgraded, you have to download a compatible browser driver and copy it to the directory which you added to the path environment variable

Protractor Typescript Cucumber.

Protractor Framework Setup: https://github.com/angular/protractor/blob/5.4.4/exampleTypescript/tsconfig.json 1- npm init  Will create a package.json in the project folder package.json: All the dependencies. 2- npm install In package.json add all dependencies required for protractor, cucumber. { "name": "protractortypescriptcucumber", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "sudheer", "license": "ISC", "dependencies": { "protractor": "^7.0.0", "typescript": "~5.2.2", "jasmine": "~5.1.0", "@types/jasmine":"4.3.5", "@types/jasminewd2": "2.0.10", "ts-node": "1...

Type Script

 is a additiondal feature for java script typescrip= additional +typescript /* ES5- our current browser cannot understand es6 typescript also cannot understand. **-typescript convert script to javascript,es5-browser and protractor will understand-. **-scan the existing intenstiosn , symantics 1- npm install -g typescript 2-create a class bascis.ts 3-tsc basics.ts 4-it will create the js file -basics.js 5-run node basics.js */ basics.ts for ( var i = 0 ; i < 5 ; i ++ ){ setTimeout ( function (){ console . log ( i );}, 100 * i ); } basics.js for ( var i = 0 ; i < 5 ; i ++ ) { setTimeout ( function () { console . log ( i ); }, 100 * i ); } Export -- export class classDemo { // variable is called in class as property //Class consists of properties,methods,constructor //This - refere to current class property username : string ; password : string ; ssn : number ; //default constructor constructor ( ssn : number ){ this . ssn = ssn ...
 Selenium Grid
 Cucumber Notes What is Cucumber in selenium? Cucumber Framework in Selenium is an open-source testing framework that supports Behavior Driven Development for automation testing of web applications. The tests are first written in a simple scenario form that describes the expected behavior of the system from the user’s perspective. What is a feature file? A standalone unit or a single functionality (such as a login) for a project can be called a Feature. Each of these features will have scenarios that must be tested using Selenium integrated with Cucumber. A file that stores data about features, their descriptions, and the scenarios to be tested is called a Feature File Keywords such as GIVEN, WHEN, and THEN used to write the test in Cucumber are called Annotations. GIVEN user navigates to the login page by opening Firefox WHEN user enters correct <username> AND <password> values THEN user is directed to the homepage What is step Definition? A Steps Definitions file stor...

Synczation-js

  const { protractor , element } = require ( "protractor" ); describe ( '' , function (){ it ( '' , function (){ browser . waitForAngularEnabled ( false ); browser . get ( 'https://demos.telerik.com/aspnet-ajax/ajaxmanager/functionality/validation/defaultcs.aspx?product=ajaxpanel' ); element ( by . id ( 'ctl00_ContentPlaceholder1_tbName' )). sendKeys ( 'sudheer' ); element ( by . id ( 'ctl00_ContentPlaceholder1_tbEmail' )). sendKeys ( 'sudheer@qa.com' ); element ( by . name ( 'ctl00$ContentPlaceholder1$RegisterButton' )). click (); //Synczation-js var EC = protractor . ExpectedConditions ; // Waits for the element with id 'abc' to be visible on the dom. browser . wait ( EC . visibilityOf ( element ( by . id ( 'ctl00_ContentPlaceholder1_Label3' ))), 5000 ); browser . element ( by . id ( 'ctl00_ContentPlaceholder1_...

Frames-JS

describe ( '' , function (){ it ( '' , function (){ browser . waitForAngularEnabled ( false ); browser . get ( 'https://rahulshettyacademy.com/AutomationPractice/' ); browser . driver . manage (). window (). maximize (); browser . switchTo (). frame ( 'iframe-name' ); element ( by . css ( "a[href*='sign_in']" )). getText (). then ( function ( text ){ console . log ( text ); }) }); });

Alerts- Accept() Dismiss()

  const { func } = require ( "assert-plus" ); const { element } = require ( "protractor" ); describe ( '' , function (){ it ( 'Non angulat website Alets' , function (){ browser . waitForAngularEnabled ( false ); browser . get ( 'https://rahulshettyacademy.com/AutomationPractice/' ); element ( by . id ( 'confirmbtn' )). click (). then ( function (){ browser . sleep ( '5000' ); }); // browser.switchTo().alert().accept() browser . switchTo (). alert (). dismiss (). then ( function (){ browser . sleep ( '5000' ); }) }) })

JS-Window handling-SwitchTabs

 - when you click on link it will open a new tab , to handle that suitation we use browser . switchTo().window(nameOrHandle). browser.open(//); element.getAllWindowHandlers().then(function(handlers){ // handlers- get the list of window browser.switchto().window( handlers[1] );//child window switchback to parent window browser.switchto().window( handlers[0] );//Parent window ) const { element , browser } = require ( "protractor" ); describe ( '' , function (){ it ( '' , function (){ browser . waitForAngularEnabled ( false ); browser . get ( 'https://rahulshettyacademy.com/AutomationPractice/' ); expect ( browser . getTitle ()). toBe ( 'Practice Page' ); browser . getTitle (). then ( function ( text ){ console . log ( text ); }); element ( by . id ( 'opentab' )). click (). then ( function (){ browser . sleep ( '3000' ); }) browser . getA...

Element.All()

 E-commerce - to get the count of all products we use count ()-method. Number of element eg: element.all(by.cs("tag[att='value']")).count(); Get by index: element.all(by.cs("tag[att='value']")).get(0).click(); //first and last: element.all(locator).first(); element.all(locator).last(); Add assertions to this expect(element.all(by.cs("tag[att='value']")).count()).toEqual(7));
 FrameWork Design Steps: file:///C:/Users/abc/Downloads/OpenCart_Selenium_Java_Framework+with+POM_Hybrid%20(2).pdf

JS Assertions

  describe ( '' , function (){ it ( '' , function (){ console . log ( 'Hello how are you' ); browser . get ( 'http://juliemr.github.io/protractor-demo/' ); element ( by . model ( 'first' )). sendKeys ( '12' ). then ( function (){ browser . sleep ( '3000' ); }); element ( by . css ( "input[ng-model='second']" )). sendKeys ( '14' ). then ( function (){ browser . sleep ( '4000' ); }); element ( by . id ( 'gobutton' )). click (). then ( function (){ browser . sleep ( '6000' ); }) //get text from page element ( by . css ( "h2[class='ng-binding']" )). getText (). then ( function ( text ){ console . log ( text ); console . log ( typeof ( text )); }) //assertions expect ( element ( by . css ( "h2[class...

JS MouseOver

  describe ( '' , function (){ it ( '' , function (){ browser . ignoreSynchronization = true ; browser . get ( "https://www.wikipedia.org/" ); //predicive search-selection browser . actions (). mouseMove ( element ( by . name ( 'search' )). sendKeys ( 'INDIA' )). perform (); browser . actions (). sendKeys ( protractor . Key . ARROW_DOWN ). perform (); browser . actions (). sendKeys ( protractor . Key . ENTER ). perform (); browser . element ( by . id ( 'firstHeading' )). getText (). then ( function ( text ){ console . log ( text ); expect ( text ). toBe ( 'India' ); }) }); }); const { browser , element , protractor } = require ( "protractor" ) describe ( '' , function (){ it ( '' , function (){ browser . waitForAngularEnabled ( false ); browser . get ( 'https://www.wikipedia.org/...

JS- Dropdown and Web Table data retrieve

Image
Webtable: Using all,repeater,each function getwebtableResults (){ element . all ( by . repeater ( "result in memory" )). each ( function ( item ){ //chain locators item . element ( by . css ( "td:nth-child(3)" )). getText (). then ( function ( text ){ console . log ( text ); }); }) } Get values of the dropdown and select the value .   element . all ( by . tagName ( "option" )). each ( function ( item ){ item . getAttribute ( 'value' ). then ( function ( values ){ console . log ( values ); }) describe ( '' , function (){ function calculate ( a , b , c ){ element ( by . model ( "first" )). sendKeys ( a ); element ( by . model ( "second" )). sendKeys ( b ); element . all ( by . tagName ( "option" )). each ( function ( item ){ item . getAttribute ( 'value...

selenium commands

 *Handling Frames: Difference between Frame and Iframe:   Frame is a HTML tag that is used to divide the web page into various frames/windows. Used as <frame> tag, it specifies each frame within a frameset tag.  Iframe as <iframe> is also a tag used in HTML but it specifies an inline frame which means it is used to embed some other document within the current HTML document. * Syntax for handing frame: we can identified frame in three approaches driver.switchTo().frame(name/id) driver.switchTo().frame(WebElement) driver.switchTo().frame(index) 1) driver.switchTo().frame("packageListFrame");  we use switchto() in order to switch between the frames and we pass Specific frame name  2)WebElement frame2=driver.findElement(By.xpath("//frame[@src='frame_2.html']")); driver.switchTo().frame(frame2); here we identified the frame as webelement  and stored in variable and passes that variable in frame() 3) driver.switch.frame(0); here we used index of the f...