Automation QA Testing Course Content

Selenium Issues and Solutions

 1)while launching the chrome browser, the application URL is not opening and thrown below error

org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection to http://localhost:65230/devtools/browser/f9347ed5-d12f-4d7d-8260-fc7c9f9394d4 Build info: version: '4.8.1', revision: '8ebccac989'

14:29:11  Dec 07, 2021 1:28:54 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
14:29:11  INFO: Found exact CDP implementation for version 95
14:29:11  Dec 07, 2021 1:29:04 PM org.openqa.selenium.remote.http.netty.NettyWebSocket lambda$new$0
14:29:11  WARNING: connection timed out: /x.x.x.x:4444
14:29:11  java.net.ConnectException: connection timed out: /x.x.x.x:4444
14:29:11  	at org.asynchttpclient.netty.channel.NettyConnectListener.onFailure(NettyConnectListener.java:179)
14:29:11  	at org.asynchttpclient.netty.channel.NettyChannelConnector$1.onFailure(NettyChannelConnector.java:108)
14:29:11  	at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:28)
14:29:11  	at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:20)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117)
14:29:11  	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:262)
14:29:11  	at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98)
14:29:11  	at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:170)
14:29:11  	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
14:29:11  	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
14:29:11  	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
14:29:11  	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
14:29:11  	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
14:29:11  	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
14:29:11  	at java.base/java.lang.Thread.run(Thread.java:866)
14:29:11  Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /10.42.2.196:4444
14:29:11  	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261)
14:29:11  	... 9 more
------------------------------------------------------------------------------------------------------------------

Solutions:

Create chrome option class object and pass into your ChromeDriver class like below:

ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
ChromeDriver driver = new ChromeDriver(options);

Reference Links:https://github.com/SeleniumHQ/selenium/issues/10117
https://stackoverflow.com/questions/75680149/unable-to-establish-websocket-connection
=========================================================================================


Selenium4 Network Tab,Console,PerformanceMetrics Methods

 

Intercepting HTTP Response

Fore intercepting the response we will be using Network.responseReceived event. This fired when the HTTP response is available, with this we can listen to URL, response headers, response code, etc. To get the response body use the method Network.getResponseBody

 public static void validateResponse(String applicationfractionUrl) {

System.out.println("**********Getting Network Tab Response Details****************");

        final RequestId[] requestIds = new RequestId[1];

        devTools.send(Network.enable(Optional.of(100000000), Optional.empty(), Optional.empty()));

        devTools.addListener(Network.responseReceived(), responseReceived -> {

        if (responseReceived.getResponse().getUrl().contains(applicationfractionUrl)) {

                System.out.println("URL: " + responseReceived.getResponse().getUrl());

                System.out.println("Status: " + responseReceived.getResponse().getStatus());

                System.out.println("Type: " + responseReceived.getType().toJson());

                responseReceived.getResponse().getHeaders().toJson().forEach((k, v) -> System.out.println((k + ":" + v)));

                requestIds[0] = responseReceived.getRequestId();

                System.out.println("Response Body: \n" + devTools.send(Network.getResponseBody(requestIds[0])).getBody() + "\n");

        }

        });

        System.out.println("--------------end of response-----------------------------------");   

}

=============================================================

Capture Console Logs

When the application is opened, the console error logs published by the application are captured.

 public static void consoleLogs(){

System.out.println("************Getting Console Logs****************");

        devTools.send(Log.enable());


        devTools.addListener(Log.entryAdded(),


                logEntry -> {


                    System.out.println("log: "+logEntry.getText());


                    System.out.println("level: "+logEntry.getLevel());


                });


        System.out.println("--------------end of Console logs-----------------------------------");   

    }

After fetching logs disable and clear the logs

devTools.send(Log.clear()); devTools.send(Log.disable()); -------------------------------------------------------------------------------------------

Performance Metrics

With DevTools we can get performance metrics while running automation tests.

 public static void getPerformanceMetrics(){

System.out.println("************Getting Performance Metrics****************");

       devTools.send(Performance.enable(Optional.empty()));

       List<Metric> metrics = devTools.send(Performance.getMetrics());

       metrics.forEach(metric-> System.out.println(metric.getName() +" : "+ metric.getValue()));

       /**

        * for(Metric m : metricList) {

        System.out.println(m.getName() + " = " + m.getValue());

}

        */

       System.out.println("--------------end of performnce Metrics-----------------------------------");   

}   

==========================================================================================

Validating Cookies

With chrome dev tools API we can play around with browser cookies. We can clear browser cookies, delete all cookies, get and set cookie or cookies.

public void getAllCookies() {

devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));

          //Getting all cookies

        List<Cookie> cookies = devTools.send(Network.getAllCookies());

        cookies.forEach(cookie -> System.out.println(cookie.getName()));

        List<String> cookieName = cookies.stream().map(cookie -> cookie.getName()).sorted().collect(Collectors.toList());

        Set<org.openqa.selenium.Cookie> seleniumCookie = driver.manage().getCookies();

        List<String> selCookieName = seleniumCookie.stream().map(selCookie -> selCookie.getName()).sorted().collect(Collectors.toList());

        Assert.assertEquals(cookieName, selCookieName);


        //Clearing browser cookies

        devTools.send(Network.clearBrowserCookies());

        List<Cookie> cookiesAfterClearing = devTools.send(Network.getAllCookies());

        Assert.assertTrue(cookiesAfterClearing.isEmpty());

    }

=======================================================================================


Java-Spring-can you explain me spring & springboot differences

 can you explain me spring & springboot differences:

Spring and Spring Boot are both frameworks for building Java applications. However, there are some key differences between the two:

  1. Purpose: Spring is a comprehensive framework for building Java applications, including support for web applications, data access, security, and many other features. Spring Boot, on the other hand, is a framework for building production-ready applications quickly and easily, with minimal setup and configuration.

  2. Configuration: Spring requires a significant amount of configuration to get started, which can be time-consuming and complex. With Spring Boot, the framework automatically configures itself based on the dependencies included in the project, which makes getting started much easier and faster.

  3. Default Setup: Spring provides a lot of flexibility in how you structure and build your application, but this also means that you need to configure a lot of different components to get started. Spring Boot provides a default setup with sensible defaults, so you can start building your application right away.

  4. Third-party Libraries: Spring provides support for a wide range of third-party libraries, but requires you to configure and integrate these libraries into your application. With Spring Boot, these libraries are automatically integrated into the framework, so you can start using them right away.

  5. Deployment: Spring applications can be deployed to any Java application server, but the deployment process can be complex and time-consuming. Spring Boot applications, on the other hand, can be packaged as executable JAR files, making deployment much simpler and faster.

  6. In summary, Spring Boot is a way to simplify the development and deployment of Spring applications. If you need a fast, easy-to-use framework for building Java applications, with minimal setup and configuration, then Spring Boot may be a good choice for you. But if you need a more flexible and customizable framework, with a wider range of features and options, then Spring may be a better choice.

java-streams-by-examples

Java Streams API

Java Streams