I'm trying to print the test data used in webdriver test inside a print line in Java
I need to print multiple variables used in a class inside a system.out.print
function (printf
/println
/whatever).
public String firstname; public String lastname; firstname = "First " + genData.generateRandomAlphaNumeric(10); driver.findElement(By.id("firstname")).sendKeys(firstname); lastname = "Last " + genData.generateRandomAlphaNumeric(10); driver.findElement(By.id("lastname")).sendKeys(lastname);
I need those print in a print statement as:
First name: (the variable value I used)
Last name: (the variable value I used)
Using something like below gives the exact result.
But I need to reduce the number of printf
lines and use a more efficient way.
System.out.printf("First Name: ", firstname); System.out.printf("Last Name: ", lastname);
Thanks!
You can print multiple types of data by appending them using + symbol in system. out. println method in one line.
Python print multiple variables To print multiple variables in Python, use the print() function. The print(*objects) is a built-in Python function that takes the *objects as multiple arguments to print each argument separated by a space.
You can do it with 1 printf
:
System.out.printf("First Name: %s\nLast Name: %s",firstname, lastname);
Or try this one:
System.out.println("First Name: " + firstname + " Last Name: "+ lastname +".");
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With