Sunday, March 24, 2024

How to execute selenium test in Github Actions

 Create a simple Maven TestNG Selenium project as below.


        System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");

        ChromeOptions chromeOptions = new ChromeOptions();

        chromeOptions.addArguments("--headless");

        driver = new ChromeDriver(chromeOptions);

        driver.get("https://www.xxxx.com/playlists");

        WebElement element = driver.findElement(By.xpath("(//*[@class='yt-simple-endpoint style-scope ytd-playlist-thumbnail'])[4]"));

        element.click();

        driver.quit();


Make sure to give a correct web driver path when you are testing the code in our local environment.

We will change it when we deploy it to GitHub actions.


Now push your code GitHub and enable actions from the project settings section.


Create a new yml file which will automatically generate when you select maven build project.

There will be a new yml file available as for the below screen shot.



In adition to default content I have to add

  • Chrome driver
  • Chrome web browser

This is the code to download above from the yml file.

 # Download Chrome version 114.0.5735.90

    - name: Download ChromeDriver

      run: | 

          

          # Download Chrome version 114.0.5735.90

          wget -q "https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_114.0.5735.90-1_amd64.deb" -O chrome.deb

          # Install Chrome

          sudo dpkg -i chrome.deb

          # Install dependencies

          sudo apt-get install -f

          # Clean up

          rm chrome.deb

          LATEST_CHROMEDRIVER_VERSION=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE")

          wget "https://chromedriver.storage.googleapis.com/${LATEST_CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" -P ~/

          unzip ~/chromedriver_linux64.zip -d ~/ && rm ~/chromedriver_linux64.zip

          sudo mv -f ~/chromedriver /usr/local/bin/chromedriver

          sudo chmod +x /usr/local/bin/chromedriver


Then add below code to execute the test.

    - name: Build with Maven

      run: mvn clean install -B


You can find the full code with copying screen shots  at https://github.com/chathurahjm/gitActionWIthScreenShots



Friday, March 1, 2024

How to execute custome jar file in JMeter

1). Create your jar file using Eclipse.

2). Because Eclipse will allow you to convert a single java method (without any main method) to a jar file.

  • Package name  : tempDBUpdate
  • Class name : update
  • Method name : updatedb

All my libraries are inside reference Libraries folder.


3). Convert to a jar file by right-click on your project → select Export → Select JAR file under java folder.


4). Move the newly generated jar file to JMeter \apache-jmeter-5.6.3\apache-jmeter-5.6.3\lib\ext folder.

5). From open JMeter and add a JSR223 Sampler

6). Set language as groovy

7). Import the jar file as for the line number 1.

8). Create an object of the class as for the line 3.

9). Call the method.



Dont use Main method to call in J Meter as it will give errors and it will not call the actual Main method implementations.

Don't use IntelliJ to cremate jar files as IntelliJ only allow Main method to convert to jar file.