Tuesday, October 5, 2021

 


Java Program: Take 2 arrays, write a method to - Insert array2 in to array1 at given position

//Output: {12, 13,14,5,6,15}


package qasign;

import java.util.ArrayList;

import java.util.Arrays;

public class SampleTest {

public static void main(String[] args) {

Integer array1[]={12, 13,14,15};

Integer array2[]={5, 6};

int position=3;

List<Integer> list1=new ArrayList<>(Arrays.asList(array1));

System.out.println();

Arrays.asList(array2);

List<Integer> list2=new ArrayList<>(Arrays.asList(array2));

list1.addAll(position, list2);

System.out.println(list1);

}

}

 

1) Reverse each word in a string Input: hello world java   

  //Output: olleh dlrow avaj

String str="hello world java";

String[] tokens=str.split(" ");

for(int i=0;i<tokens.length;i++) {

for(int j=tokens[i].length()-1;j>=0;j--) {

System.out.print(tokens[i].charAt(j));

}

System.out.print(" ");

}

 


package qasignpackage;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Map.Entry;

public class SampleTest {

    public static void main(String[] args) {

  HashMap<String, String> hmap=new HashMap<String,String>();

                  hmap.put("1", "qa"); 

                  hmap.put("2", "sign"); 

                  hmap.put("3", "selenium");

  for (Entry<String,String> entry: hmap.entrySet()) {

  System.out.println("Key = " + entry.getKey() +

                      ", Value = " + entry.getValue());

  }

  }

 

Tuesday, August 17, 2021

What is method overload and method override?

Method Overload:method overload means methods contain with same name and difference in the parameters

This difference may be in the 

-> sequence of the parameters

-> number of the parameters

-> type of the parameters

Method Override: Method Override means methods with same name and same parameters. This override performs in parent and child classes


What is a static keyword in Java?

If applies static to the member of a class. You can directly access that with the classname without creating any object.

  • The value of the  static variable is shared by all objects of a class means same set of copy available to all the objects.


What is final keyword in Java?

Final means fixed. No changes can be happened on it. If applies final

    -> to a variable then, that variable value can not be changed.

    -> to a method then, that method can not be override

    -> to a class then that class can not be inherited.


What are the Access Modifiers?

Access Modifiers are:

1. public

2. private

3. default

4. protected

-> public means that member of a class can be visible and accessed anywhere in the project.

-> private means that member can be visible and accessed with in a method or class.

-> default means that member can be visible and accessed with in a package. If no access modifier is used, it considers as default

-> protected means that member can be visible and accessed with in a package and in child classes of another package.


What is Selenium?

Selenium is a automation tool which is used to automate the web applications.

Advantages of Selenium?

1. Selenium is an Open-Source

2. Selenium supports multiple languages like Java, c#, Python, Ruby, Perl etc.,

3. We can write the automation scripts in multiple browsers like chrome, firefox, IE, Microsoft Edge etc.,

4. Selenium supports multiple Operating Systems Windows, Linux, Mac etc.,

5. Supports Android and iOS


What is a WebDriver?

WebDriver is an Interface, it is implemented by respective Browser Drivers like ChromeDriver, FirefoxDriver etc.,


Write a simple Selenium Script or Code?

System.setProperties("webdriver.chrome.driver","Path of the Driver File");

WebDriver driver=new ChromeDriver();

driver.get("URL");


What are different Locators in Selenium?

Locator: Locator means an address of an WebElement. We have Locators in Selenium like

1. id

2. name

3. className

4. tagName

5. linkText

6. partialLinkText

7. xpath

8. cssSelector


What is absolute xpath and relative xpath?

absolute xpath starts with '/' and it identifies the element from route node to child node.

relative xpath starts with '//' and it identifies the element directly where it present in the HTML DOM.

Note: / -> single forward slash, // -> double forward slashes


How to write xpath?

We can write the xpath using tagName, attribute and values like

//tagName(@attribute='value')

Also we can write xpath with

1. text() method

2. contains() method

3. xpath axes like parent, ancestor, preceding-sibling and forwarding-sibling etc.,


What is a Page Object?

A Page Object is class which is created for each and every page of an application.

This class contains all the WebElements of the page and getter methods for respective webElements.


What is the PageFacory?

PageFacory is a class which is used to initialize the PageObject.


Diference between findElement and findElements()?

findElement() is used for Single elements and return type is WebElement.

findElements() is used for List of WebElements and return type is List<WebElement>.


What are the waits in Selenium?

Selenium provides waits like

1. implicitwait

2. explicitwait

3. fluentwait


What is the difference between implicit wait and explicit wait?

implicit wait is used to provide waiting time for all the WebElements

explicit wait is used to provide the waiting time for a specific condition or WebElement.


Write a code for implicit wait?

driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;


Write a code for explicit wait?

WebDriverWait wait = new WebDriverWait(driver,30);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("locator")));


How to enter the data into the textbox?

using sendKeys() method of selenium library, we can enter the data.


How to click on a button?

using click() method, we can click on a button


How to get the text of a WebElement?

using getText(), we can get the Text.


How to initialize the webdriver?

WebDriver driver =new FirefoxDriver();

Here, we create the object for the class 'FirefoxDriver' and store it in reference variable of the Webdriver Interface.


How to launch a browser and pass the URL?

    1. First, we need to set the property for the driver like

    System.setProperty("webdriver.gecho.driver", "path of the driver file");

    2. Intialize the driver like

    WebDriver driver =new FirefoxDriver();

    3. Use the get() method to pass the URL like

    driver.get("URL");


what is the difference between quit() and close()?

quit() method closes all the window instances opened by the driver

close() method closes only current window instance.


How to handle/select dropdown element in the selenium?

We can handle dropdown element using Select class. The class contains the methods like

selectByIndex()

selectByValue()

selecByVisibleText()

Example: 

Select select=new Select(driver.findElement(By.xpath("locator")));

select.selectByVisibleText();


How to do mouse over action and click()?

We can take the help of Actions class to this. 
1st create an object for actions class
2nd Perform the mouse hover action using moveToElement method.
3rd click on the link using click method.

Example:
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("<xpath>"))).perform();
action.click().build().perform()

How to Handle multiple Windows in Selenium?

getWindowHandle(), getWindowHandles() and switchTo() methods help to work with multiple windows.

All Opened window Ids get and store in Set reference variable and switch them with switchTo() method.

How to take a screenshot in Selenium?

We can take the help of "TakesScreenshot" Interface. This interface has the method "getScreenshotAs()". Using this, we can  take the screenshot and save it in a file.

Code Snippet:

    TakesScreenshot scrShot =((TakesScreenshot)webdriver);
    File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(SrcFile, "C:/Test.png");

What is textng.xml file format?

<suite name="SuiteName">

  <test name="TestName ">

      <classes>

      <class name="packagename.classname"/>

      </classes>

  </test>

</suite>


What are different testng Annotations?

@BeforeSuite

   @BeforeTest

      @BeforeClass

         @BeforeMethod

           @Test

         @AfterMethod

      @AfterClass

   @AfterTest

@AfterSuite


@beforesuite -> this annotation will call before executing all the tests

@beforetest -> this annotation will call before executing all test cases

@beforeclass -> this annotation will call before executing all test cases in a class

@beforemethod -> this annotation will call before executing each and every test case

@Test -> it represents a Test Case

@aftermethod -> this annotation will call after executing each and every test case

@afterclass -> this annotation will call after executing all test cases in a class

@aftertest -> this annotation will call after executing all test cases

@aftersuite -> this annotation will call after executing all the tests

What is an Assertion?

Assertion is used for validation. We use Assert class from testng library to this validations. It has methods like assertEquals(), assertTrue(), assertFalse()


How to run only smoke testcases?

We can set the tag in the feature file and it pass in the TestRunner file.


What are the dependecies required for Cucumber BDD Framework?

Along with selenium-java and testng, also require

cucumber-testng

cucumber-java


What are CucumberOptions in TestRunner File?

We have CucumberOptions like

1. features

2. glue

3. tags

4. format

5. dryRun

6. monochrome

7. strict

Explanation:

features option is for setting up the path of the feature files

glue option is for setting up the path of the stepDefinition files

tags is to instruct what tag from feature file to execute

format is to set which report format to be generate after execution

dryRun to check all feature steps has respective matched Step Definition. Default Value is False

monochrome to display console output in readable way. Default Value is False

strict is to fails the execution if there are undefined or pending steps. Default Value is False


What are the Hooks in Cucumber?

@Before and @After

-> Before executes before executing all the steps

-> After executes after executing all the steps


What is the framework you are using and Can you explain briefly?

I am working on BDD Framework with cucumber. It contains the components like

1. feature files

2. stepdefinition files

3. pageobjects

4. testrunner

5. WebDriverManager

6. utility

7. testdata

8. properties file

9. target

10. config folder

11. pom.xml


What is the feature file?

feature file contains all the scenarios to be execute. 

One feature file contains multiple scenarios

One scenario contains multiple steps

We write scenarios and steps in Gherkin Language


What are the Keywords use in feature file?

We use Gherkin Keywords like

feature at feature level

scenario and scenario outline at scenario level

Given, When, Then, And, But at step level


What is deference between scenario and scenario outline?

we do not pass the testdata in scenario but we can pass testdata in "scenario outline" using "Example" keyword.


Can you write BDD steps for Gmail login Functionality in the feature file?

Yes I write.

with Scenario:

Feature: Application Login

Scenario: Verify Login Functionality

Given I Open The Gmail

When I Entered The Username "abc@gmail.com" and password "12345"

And I Click On Login Button

Then I See Gmail Home Page


or 


with Scenario Outline:

Feature: Application Login

Scenario Outline: Verify Login Functionality

Given I Open The Gmail

When I Entered The <username> and <password>

And I Click On Login Button

Then I See Gmail Home Page

Examples:

      | username | password |

      | abc@gmail.com | 12345 |




Tuesday, January 5, 2021

 Type Casting:

The process of converting value of one Datatype to another Datatype. Two ways of Casting:

Widening:  Converting a smaller datatype to higher datatype is called widening.

byte-> short -> char -> int -> long -> float -> double

widening happens automatically and it is safe operation. We also call widening as implicit casting.

              Ex:       int n=10;

                          float  x=n;

Narrowing: Converting a higher datatype to smaller datatype is called narrowing.

double -> float -> long -> int -> char -> short -> byte

narrowing happens manually and it is not safe operation. We also call narrowing as explicit casting.

              Ex:       float     n=10.2f;

                          int x=(int)n                  Output: 10

 

selenium-repo by venu

Blog helps to a student or IT employee to develop or improve skills in Software Testing.
For Online Classes Email us: gadiparthi122@mail.com

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *

Popular Posts