Found 719 Articles for Testing Tools

Checking HTTP Status Code in Selenium.

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:54:54

1K+ Views

We can check HTTP status code in Selenium. As we run tests, we can verify the status code of a response from a resource. Some of the various HTTP status codes are −5XX – Error in server.4XX – Resource not detected.3XX - Redirected.2XX – Ok.An instance of the class HttpURLConnection is used to get the HTTP status code. To have a connection to an URL, the openConnection method shall be utilized. Then we have to take the help of setRequestMethod and pass HEAD as a parameter to that.To establish the connection, the connect method is to be applied to the object ... Read More

How to open a new tab using Selenium WebDriver?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:50:58

1K+ Views

We can open a new tab with Selenium. The Keys.chord and sendKeys methods are used for this. Multiple keys can be passed simultaneously with the Keys.chord method. A group of strings or keys can be passed as parameters to that method.The Keys.CONTROL and Keys.ENTER are passed as parameters to the Keys.chord method here. This is stored as a string value and finally passed as a parameter to the sendKeys method.SyntaxString nwtb = Keys.chord(Keys.CONTROL, Keys.ENTER); driver.findElement(By.xpath("//*[text()='Company']")).sendKeys(nwtb);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 OpnLinkNwTab{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");   ... Read More

How to check if an image is displayed on page using Selenium?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:41:16

10K+ Views

We can check if an image is displayed on page with Selenium. To verify an image we shall take the help of Javascript Executor. We shall utilize executeScript method to execute the Javascript commands in Selenium.Then pass the command return arguments[0].complete && typeof arguments[0].naturalWidth != \"undefined\" && arguments[0].naturalWidth > 0 as a parameter to that method. Moreover, the statement import org.openqa.selenium.JavascriptExecutor has to be added in code.SyntaxWebElement i = driver.findElement(By.xpath("//img[@title='Tutorialspoint']")); Boolean p = (Boolean) ((JavascriptExecutor)driver) .executeScript("return arguments[0].complete " + "&& typeof arguments[0].naturalWidth != \"undefined\" " + "&& arguments[0].naturalWidth > 0", i);Let us check if the below image is present on page −ExampleCode ... Read More

How to get innerHTML of whole page in selenium driver?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:37:50

2K+ Views

We can get the innerHTML of the whole page in Selenium. We shall use the method getPageSource and print the values captured by it in the console.SyntaxString s = driver.getPageSource();We can also get the HTML source code via Javascript commands in Selenium. We shall utilize executeScript method and pass the command return document.body.innerHTML as a parameter to the method.SyntaxJavascriptExecutor j = (JavascriptExecutor) driver; String s = (String) j.executeScript("return document.body.innerHTML;");ExampleCode Implementation with getPageSource.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 PageHTMLcode{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = ... Read More

Getting console.log output from Firefox with Selenium.

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:33:09

1K+ Views

We can get console.log output from Firefox with Selenium. This is done with the setProperty method.FirefoxDriver.SystemProperty.BROWSER_LOGFILE and the path of the file in which the logs are to be captured are passed as parameters to that method.SyntaxSystem.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "FFLogs.txt");After refreshing the project folder, we shall get the FFLogs.txt file where the logs shall be captured.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.logging.LogType; public class FirefoxLogs{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");       // set the System Property to BROWSER_LOGFILE and path of log file       System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, ... Read More

Behind the scenes working of Selenium.

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:31:02

124 Views

The behind scenes workings of Selenium is illustrated below −Source − https://www.tutorialspoint.com/what-is-web-driver-in-seleniumSelenium webdriver architecture comprises of −Selenium Binding Languages – It can used on multiple languages (Java, Ruby, Javascript, C#, Python, and so on). So it possesses the language bindings for multiple languages.JSON Wire Protocol – It is known as the Javascript Object Notation. It sends the data from the server to the client page. It is built on the concepts of Rest API which conveys information within HTTP servers.Browser Driver – A browser has a browser driver. It communicates with its browser. When a driver gets a command, it ... Read More

How do you test pages that require authentication with Selenium?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:26:55

322 Views

We can test pages that need authentication with Selenium. For this, we have to send the credentials of the user to the URL. Actually, we are passing both the username and password appended to the URL.Syntaxhttps://username:password@URL https://admin:admin@the-internet.herokuapp.com/basic_authHere, the admin is the username and password.URL – www.the-internet.herokuapp.com/basic_authLet us see how to accept the authentication pop-up.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class TestAuthnPopup{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String t = "admin";       // adding username, password with ... Read More

How to use clickandwait in Selenium Webdriver using Java?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:24:42

2K+ Views

We can click and wait in Selenium. This can be achieved by the synchronization concept. We shall use the explicit wait condition and wait for an element to be clickable prior to the next step.The explicit wait waits for a specified amount of time before throwing an exception. To verify if an element is clickable, we can use the expected condition elementToBeClickable.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; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class ElementClickableWait{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();     ... Read More

How to connect to Chromium Headless using Selenium?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:21:59

376 Views

We can connect to Chromium headless with Selenium. The headless execution helps in reducing resource utilization and is a modern technique used in the industry.Chrome can be used in headless mode after the 59 version. The ChromeOptions class is used to change the default browser behavior. The headless value is passed to the addArguments method as a parameter for headless execution.SyntaxChromeOptions op = new ChromeOptions(); op.addArguments("headless"); WebDriver d = new ChromeDriver(op);ExampleCode Implementation.import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.concurrent.TimeUnit; public class HeadlessChromium{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       //ChromeOptions object     ... Read More

How to get HTTP Response Code using Selenium WebDriver?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:16:29

5K+ Views

We can get an HTTP response code in Selenium webdriver. While running test cases, we can check the response code from a resource. Common HTTP response codes include −5XX – Issue in server.4XX – Resource cannot be determined.3XX - Redirection.2XX – Fine.An object of the class HttpURLConnection is created to get the HTTP response code. To establish a link to an URL, the openConnection method shall be used. Next, we shall utilize the setRequestMethod and pass HEAD as a parameter.For connection, the connect method is to be applied to the instance of the HttpURLConnection class. At last, the getResponseCode method ... Read More

Advertisements