Sunday, September 13, 2020

Selenium_Grid_With_Docker_Compose(yml file)

 docker-compose.yml


version: "3"

services:

  hub:

    image: selenium/hub:3.141.59

    ports:

      - "4444:4444"

  chrome:

    image: selenium/node-chrome:3.141.59

    depends_on:

      - hub

    environment:

      - HUB_HOST=hub  

  firefox:

    image: selenium/node-firefox:3.141.59

    depends_on:

      - hub

    environment:

      - HUB_HOST=hub  


Note:

i have already pulled images

docker-compose up 

launch in browser';


http://192.168.99.100:4444/grid/console


docker-compose up --scale chrome=4


sample Program:


public class GridTest {

@Test

public static void main(String[] args) throws MalformedURLException, InterruptedException {


DesiredCapabilities dc = new DesiredCapabilities();

// WebDriver driver;

//Thread.sleep(20000);

dc.setBrowserName("chrome");

dc.setPlatform(Platform.LINUX);

WebDriver driver = new RemoteWebDriver(new URL("http://192.168.99.100:4444/wd/hub"), dc);

//Thread.sleep(20000);

driver.manage().window().maximize();

driver.get("http://google.com");


//Thread.sleep(20000);

driver.close();

}


}


Next Step: Lets try to integrate with jenkins.

Sunday, September 6, 2020

Docker_With_Selenium Grid

Before this please go through


https://automationknowledgesharing2020.blogspot.com/2020/08/dockerlearning.html


https://automationknowledgesharing2020.blogspot.com/2020/08/selenium-gridhub-node.html 


Selenium grid helps to run our test cases in different operating systems and on different browsers.



Prerequisites:


Given below are a few things we need to check:

  • If your machine consists of JDK 1.7  or later version
  • Is Chrome and Firefox browsers installed on your local machine?
  • Selenium WebDriver and TestNG based test cases.
  • Configured Testng.xml file to run test cases as parallel tests.
Please refer blog



After the above set-up,lets pull required images from 





ImageCommand
Selenium hubdocker pull selenium/hub
Selenium firefox nodedocker pull selenium/node-firefox
Selenium chrome nodedocker pull selenium/node-chrome
Selenium firefox debugdocker pull selenium/node-firefox-debug
Selenium chrome debugdocker pull selenium/node-chrome-debug

After pull



To Start Selenium Hub

docker run -d -p 4444:4444 --name selenium-hub selenium/hub 

after you execute,

Type below in your browser






check logs for 

docker ps

docker logs 5af807482646





Lets Start Chrome and Firefox node,

docker run -d --link selenium-hub:hub selenium/node-chrome

docker run -d --link selenium-hub:hub selenium/node-firefox



Refresh below url,









Command to run chrome debug node from Docker

docker run -d -P --link selenium-hub:hub selenium/node-chrome-debug

docker run -d -P --link selenium-hub:hub selenium/node-firefox-debug




C:\Users\manjunathk\selenium>docker ps -a


NodesRunning Port Numbers
Chrome debug node32769
Firefox debug node32768

Now, we know the port numbers of chrome and firefox debug nodes that are running.

Now, we know the port numbers of chrome and firefox debug nodes that are running so we can start both the browsers using VNC viewer.

For that we need to follow the steps given below:

1) Download VNC viewer from their official site: Download VNC

2) Run it

3) Type the hub URL and the port number of each debug mode as shown below and click on the connect button

HUB URL: PORT NUMBER

  • For Chrome browser 192.168.99.100:32771

vnc

4) After clicking on the connect button VNC viewer will ask for a password. By default the password for VNC viewer is secret, type the password as secret and click Ok and you will be able to see a window for the chrome browser.

5) Likewise, you have to do the same for the Firefox browser by using a VNC viewer. Open the VNC application on your local computer and use Firefox running port number with the hub URL and click the connect button.

  • For Firefox browser 192.168.99.100:32772

Again you will see another window opening for the Firefox browser.


Firefox browser


see logs

13:50:27.686 INFO [DefaultRemoteProxy.onEvent] - Marking the node http://172.17.0.3:5555 as down: cannot reach the node for 2 tries
13:50:31.655 INFO [DefaultRemoteProxy.onEvent] - Marking the node http://172.17.0.4:5555 as down: cannot reach the node for 2 tries
13:51:32.197 INFO [DefaultRemoteProxy.onEvent] - Unregistering the node http://172.17.0.3:5555 because it's been down for 64511 milliseconds
13:51:32.197 WARN [DefaultGridRegistry.removeIfPresent] - Cleaning up stale test sessions on the unregistered node http://172.17.0.3:5555
13:51:36.169 INFO [DefaultRemoteProxy.onEvent] - Unregistering the node http://172.17.0.4:5555 because it's been down for 64514 milliseconds
13:51:36.169 WARN [DefaultGridRegistry.removeIfPresent] - Cleaning up stale test sessions on the unregistered node http://172.17.0.4:5555
13:53:24.807 INFO [DefaultGridRegistry.add] - Registered a node http://172.17.0.4:5555
13:53:24.897 INFO [DefaultGridRegistry.add] - Registered a node http://172.17.0.3:5555
14:00:34.032 INFO [DefaultGridRegistry.add] - Registered a node http://172.17.0.5:5555
14:00:51.277 INFO [DefaultGridRegistry.add] - Registered a node http://172.17.0.6:5555
14:04:21.183 INFO [DefaultGridRegistry.add] - Registered a node http://172.17.0.8:5555
14:04:21.226 INFO [DefaultGridRegistry.add] - Registered a node http://172.17.0.7:5555
14:05:13.629 INFO [RequestHandler.process] - Got a request to create a new session: Capabilities {browserName: chrome, platform: LINUX}
14:05:13.630 INFO [TestSlot.getNewSession] - Trying to create a new session on test slot {server:CONFIG_UUID=e6182590-23f0-4477-9f5f-0888750e64bc, seleniumProtocol=WebDriver, browserName=chrome, maxInstances=1, platformName=LINUX, version=84.0.4147.105, applicationName=, platform=LINUX}

C:\Users\manju


To run selenium grid test, watch,

https://automationknowledgesharing2020.blogspot.com/2020/08/selenium-gridhub-node.html



Selenium_Grid_With_Docker_Compose(yml file)

 docker-compose.yml version: "3" services:   hub:     image: selenium/hub:3.141.59     ports:       - "4444:4444"   chro...