Programming Articles

Page 2124 of 2547

How to upload files using Selenium Webdriver?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 22-Nov-2021 5K+ Views

We can upload files using Selenium Webdriver. This is achieved by the sendKeys method. We have to first identify the element which performs the file selection by mentioning the file path [to be uploaded].This is only applied to an element having a type attribute set to file as a value along with the element tag name as input. The below html code shows the element with type = file value set.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class WndsFileUpl{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");   ...

Read More

Selenium WebDriver With Java Quickstart.

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 22-Nov-2021 862 Views

We can work with Selenium webdriver with Java Quickstart template. This can be done by following the below steps −Step1− Click on the File menu in Eclipse. Then select the option New. Next click on Other.Step2− Click on Maven Project from the Maven folder. Then click on Next.Step3− Proceed with the further steps.Step4− Select maven-archetype-quickstart template. Then click on Next.Step5− Add GroupId as Selenium, Artifact Id as Automation-Selenium, and proceed.Step6− A project should get created with an archetype project structure. The Selenium-related scripts should be written within the src/test/java folder.

Read More

How to run tests using a test runner file for Cucumber?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 22-Nov-2021 18K+ Views

We can run tests using a test runner file for Cucumber. The test runner file should contain the path of the feature file and step definition file that we want to execute.Code Implementation of the Feature fileFeature − Login ModuleScenario − Welcome Page Login verificationGiven User is on Welcome PageThen Welcome page should be displayedExampleCode Implementation of step definition filepackage stepDefinations; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; public class stepDefination {    @Given("^User is on Welcome Page$")    public void user_on_welcome_page() {       System.out.println("User on welcome page");    }    @Then("^Welcome page should be displayed$")    public void verify_user_on_welcome_page() {   ...

Read More

How to map a step definition to a feature file in Cucumber?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 22-Nov-2021 5K+ Views

We can map a step definition file to a feature file in Cucumber. This can be done using the below steps −Step1− Create a feature file with .feature extension(say Login.feature) with the following −Feature − Login ModuleScenario − Welcome Page Login verificationGiven User is on Welcome PageThen Welcome page should be displayedStep2− Create a step definition java file(say stepDefination.java) having the mapping of the step definition file to the feature file.Examplepackage stepDefinations; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; public class stepDefination { @Given("^User is on Welcome Page$") public void user_on_welcome_page() { ...

Read More

How to transform the response to the Java list in Rest Assured?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 22-Nov-2021 4K+ Views

We can transform the response to Java list in Rest Assured. This can be achieved when we have a JSON array Response. To convert the JSON array to List, we need to use the method as.(List.class).Once the JSON array Response is converted to a List, we need to convert it to a Map and get all values in the Response in a key-value pair. We shall first send a GET request via Postman on a mock API URL and go through the JSON Response array.ExampleCode Implementationimport java.util.List; import org.testng.annotations.Test; import io.restassured.RestAssured; public class NewTest {    @Test    public void ...

Read More

Explain how to get the size of a JSON array response in Rest Assured.

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 22-Nov-2021 3K+ Views

We can get the size of a JSON array response in Rest Assured. First, we shall obtain a Response body which is in JSON format from a request. Then convert it to string. Finally, obtain its length with the size method. Code Implementationimport static io.restassured.RestAssured.given; import org.testng.annotations.Test; import io.restassured.RestAssured; import io.restassured.path.json.JsonPath; import io.restassured.response.Response; public class NewTest {    @Test    public void jsonAryLen() {       //obtain Response from GET request       Response res = given()       .when()       .get("https://jsonplaceholder.typicode.com/posts");       //convert JSON to string       JsonPath ...

Read More

How to add Cucumber Maven dependencies to the project?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 22-Nov-2021 4K+ Views

We can add Cucumber Maven dependencies to a project. This can be done by following the below steps −Step1− Create a Maven project. The details on how to create a Maven project is discussed in detail in the below link −https://www.tutorialspoint.com/maven/index.htmStep2− Add the following dependencies in the pom.xml file in a project for Cucumber.Cucumber JVM - Java dependencyhttps://mvnrepository.com/artifact/io.cucumber/cucumber-javaCucumber JVM - JUnit dependencyhttps://mvnrepository.com/artifact/io.cucumber/cucumber-junitStep3− Click on the Project menu, then select the option Build Automatically.Step4− Click on the Maven Dependencies folder within the project. All the Cucumber-related dependencies which we have obtained via Maven should be visible.

Read More

How to get a value from a nested list in Rest Assured?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 22-Nov-2021 3K+ Views

We can get a value from a nested list in Rest Assured. This is done with the help of the extract method. To grab the item, we have to use the path method(after the extract method) and pass the item in the response we want to obtain.We shall first send a GET request via Postman on a mock API URL and go through its Response having a nested list.ExampleCode Implementationimport org.testng.annotations.Test; import static io.restassured.RestAssured.given; import java.util.ArrayList; import io.restassured.RestAssured; import io.restassured.http.ContentType; public class NewTest {    @Test    public void getRequest() {       //base URL       ...

Read More

How to use the then method in Rest Assured?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 22-Nov-2021 2K+ Views

We can use the then method in Rest Assured. It is mainly used to validate a Response obtained from a request. Thus, most assertions are included within a then method.SyntaxRestAssured.baseURI = "http://dummy.restapiexample.com"; //GET operation with then methods given() .when().get("/api/v1/employees").then() //verify status code as 404 .assertThat().statusCode(404);ExampleCode Implementationimport org.testng.annotations.Test; import static io.restassured.RestAssured.*; import io.restassured.RestAssured; public class NewTest {    @Test    void test() {       //base URL       RestAssured.baseURI =       "http://dummy.restapiexample.com";       //input details for GET request       given()       .when().get("/api/v1/employee/1")       ...

Read More

How to change the color of line in xyplot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 596 Views

To change the color of line in xyplot, we can use col argument.For example, if we have two vectors say X and Y and we want to create a red colored xyplot between X and Y then we can use the following command −xyplot(x~y,type="l", col="red")Check out the below example to understand how it works.ExampleTo change the color of line in xyplot, use the code given below −set.seed(123) library(lattice) xyplot(1:5~rpois(5,5),type="l",col="blue")OutputIf you execute the above given code, it generates the following output −

Read More
Showing 21231–21240 of 25,466 articles
Advertisements