woensdag 24 november 2021

Do you need to make test checks on your Azure Portal subscription which Azure Resources you have deployed in a Resource Group? Then I've made this Pester script to check the location of a resource.

  $resourcegroup = 'YOUR_REOURCE_GROUP'
  $resourcename = 'YOUR_RESOURCE_NAME'
  $resources = Get-AzResource -Name $resourcename -ResourceGroupName $resourcegroup  

  # Create an empty array
  $testcases = @()
  $resources.ForEach{$testcases += @{resource = $_}}

  Describe 'Azure Resources'{
       It "Gives correct region to <resource>" -TestCases $testcases  {              
              $resource.Location | Should -Be 'westeurope'      
       }      
}

What tool is Pester?

source: https://github.com/pester/Pester

video: https://www.youtube.com/watch?v=qeiy8fRMHf8&t

vrijdag 31 januari 2020

Gitlab Ubuntu image

Always had plans to play with Gitlab but never get a change or time? Then simply download my Ubuntu image within Gitlab, NodeJS example test project* and Docker gitlab-runner.

You only have to install Oracle Virtualbox:

And the download my Ubuntu image (20GB free diskspace for downloading and unzipping):

Action after starting ubuntu:
  1. user/ww: osboxes.org
  2. wait 5 minutes after login action to start up Gitlab in the background
  3. Start firefox and go to http://10.0.2.15/ and then user/ww: root/gitlab20 for Gitlab
  4. Inside Gitlab you can navigate to the screenshot below to see the last runned pipeline.
*Source:






maandag 25 februari 2019

Try Cypress in VM for VirtualBox

Like to try Cypress without installing it by yourself? Then download this Ubuntu VM for VirtualBox!
https://drive.google.com/file/d/1gq8fBKUrMyXZ7H1Y0Fv7LtLk0vYH3sDU/view

user and password: osboxes.org

Start Cypress in new Terminal window with command:
osboxes@osboxes: cd ~/Work/Cypress && npm run cypress:open

Example testcase 1:
describe('Check if the Hotel App from Adactin is available', function() {
  it('Visits the Adactin Hotel App website', function() {
    cy.visit('https://adactin.com/HotelApp/')
    cy.contains('Welcome to AdactIn Group of Hotels')
    cy.get('#username')
      .type('Cucumbertestuser')
    cy.get('#password')
      .type('cucumbertestuser')
    cy.get('#login').click()
  })
})

Install Visual Studio code if you need another IDE to edit Cypress scripts:
https://websiteforstudents.com/install-visual-studio-code-on-ubuntu-16-04-18-04/ 

Example testcase 2:
describe('Check if you can book a room with the Hotel App from Adactin', function () {

  const todaysDate = Cypress.moment().format('DD/MM/YYYY')
  const fourteenDaysForward = Cypress.moment().add(14, 'day');
  const todaysDatePlus14 = Cypress.moment(fourteenDaysForward).format('DD/MM/YYYY');
  const twoYearsForward = Cypress.moment().add(2, 'year');
  const todaysDatePlusTwoYears = Cypress.moment(twoYearsForward).format('YYYY');

  beforeEach(function () {
    // login on the website before each test
    cy.visit('https://adactin.com/HotelApp/')
    cy.contains('Welcome to AdactIn Group of Hotels')
    cy.get('#username')
      .type('Cucumbertestuser')
    cy.get('#password')
      .type('cucumbertestuser')
    cy.get('#login').click()
    cy.contains('Search Hotel')
    cy.contains('Fields marked with Red asterix (*) are mandatory')
  })

  function fillsearchscreen(Location, Hotels, RoomType, RoomNos, DatepickIn, DatepickOut, AdultRoom, ChildRoom) {
    cy.get('#location')
      .select(Location)
    cy.get('#hotels')
      .select(Hotels)
    cy.get('#room_type')
      .select(RoomType)
    cy.get('#room_nos')
      .select(RoomNos)
    cy.get('#datepick_in').clear()
      .type(DatepickIn)
    cy.get('#datepick_out').clear()
      .type(DatepickOut)
    cy.get('#adult_room')
      .select(AdultRoom)
    cy.get('#child_room')
      .select(ChildRoom)
    cy.get('#Submit').click()
    cy.contains('Select Hotel')
  }

  // it('can fill the screen for search hotel', function () {
  //   fillsearchscreen('London', 'Hotel Sunshine', 'Double', '2 - Two', todaysDate, todaysDatePlus14, '2 - Two', '2 - Two')
  // })

  // it('can select a hotel after searching', function () {
  //   fillsearchscreen('London', 'Hotel Sunshine', 'Double', '2 - Two', todaysDate, todaysDatePlus14, '2 - Two', '2 - Two')
  //   cy.get('#radiobutton_0').click()
  //   cy.get('#continue').click()
  //   cy.contains('Book A Hotel')
  // })

  // it('can select the second hotel after searching', function () {
  //   fillsearchscreen('Sydney', '- Select Hotel -', 'Double', '2 - Two', todaysDate, todaysDatePlus14, '2 - Two', '2 - Two')
  //   cy.get('#radiobutton_2').click()
  //   cy.get('#continue').click()
  //   cy.contains('Book A Hotel')
  // })

  it('can book an hotel and search it in the reservation menu', function () {
    fillsearchscreen('Sydney', '- Select Hotel -', 'Double', '2 - Two', todaysDate, todaysDatePlus14, '2 - Two', '2 - Two')
    cy.get('#radiobutton_2').click()
    cy.get('#continue').click()
    cy.contains('Book A Hotel')
    cy.get('#first_name')
      .type('CypressFirst')
    cy.get('#last_name')
      .type('CypressLast')
    cy.get('#address')
      .type('CypressAddress')
    cy.get('#cc_num')
      .type('1234567812345678')
    cy.get('#cc_type')
      .select('VISA')
    cy.get('#cc_exp_month')
      .select('June')
    cy.get('#cc_exp_year')
      .select(todaysDatePlusTwoYears)
    cy.get('#cc_cvv')
      .type('1234')
    cy.get('#book_now').click()
    cy.contains('Please wait! We are processing your Hotel Booking').should('be.visible')
    cy.contains('Booking Confirmation').should('be.visible')

    cy.get('#order_no').then(ordernr => {
      const OrderNo = Cypress.$(ordernr).val();
      cy.get('#my_itinerary').click()
      cy.contains('Search Order Id')
      cy.get('#order_id_text')
        .type(OrderNo)
      cy.get('#search_hotel_id').click()
      cy.contains('1 result(s) found').should('be.visible')
      cy.get('tr:nth-child(2) > td:nth-child(2) > input').should('have.value', OrderNo)
      cy.get('td:nth-child(4) > input').should('have.value', 'Hotel Creek')
      cy.get('#check_all').click()
      cy.get('input.reg_button:nth-child(1)').click()
      cy.get('#order_id_text')
        .type(OrderNo)
      cy.get('#search_hotel_id').click()
      cy.contains('0 result(s) found').should('be.visible')
    });
  })
})

Or a project* with this above example combining Cucumber and Cypress:
Cypress Cucumber Example project
*source: https://github.com/TheBrainFamily/cypress-cucumber-example 

dinsdag 19 februari 2019

On Docker Hub I've created a new Docker Container with a working Cucumber project.

If you want to try this by yourself:
1. Install Docker on your host device
2. Visit my container on Docker Hub: https://hub.docker.com/r/steavy/docker-cucumber-demo
3. Read the Overview on Docker Hub for more information

woensdag 5 december 2018

Async Groovy script for polling database results for ReadyAPI (SoapUI) TestCases

Make a new "Groovy Script" Step in your SoapUI TestCase for Async calls to a database for waiting for a certain result:


import groovy.sql.Sql
import com.eviware.soapui.support.GroovyUtils
import static org.junit.Assert.assertThat
import static org.hamcrest.CoreMatchers.containsString

log.info("")
log.info(" init DB connection...")

com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("oracle.jdbc.driver.OracleDriver")
sql = Sql.newInstance("jdbc:oracle:thin:<USERNAME>/<password>@<HOSTNAME:PORT/DATABASENAME>", "oracle.jdbc.OracleDriver")

def timeout = 0
log.info("setup done")

while (true)
{
   def itemCount = sql.firstRow("select count(*) from <TABLENAME> where <QUERY>")
   def itemCount_nr = itemCount[0].toString()
   log.info("while count = " + itemCount_nr)
   sleep(2000)
   timeout++
   if (itemCount_nr == "1") break
   else if (timeout % 22 == 0) break
}

log.info("sql close")
sql.close()



In this above example the result will depend on the count (expect 1 row) if not then loop 2000msec with the max of 22 x 2000 msec then "break". If between this 44 sec there is a result then "break". After that always close the SQL connection.

vrijdag 8 december 2017

Meerdere testomgevingen configureren voor je Maven Cucumber-Java project dmv profiles

Om tegen verschillende testomgevingen aan te kunnen testen heb ik een opzet gemaakt dmv profiles in de pom file van een Maven project.

Door onderstaande aan je maven file toe te voegen kun je met een extra parameter in je Maven commando aangeven met welke omgeving config.properties de testen moeten draaien. Door meerdere profiles met verschillende <id> neer te zetten in de POM kun je aangeven welke config.properties vanuit je resources naar je target directory gekopieerd moet worden.

Dit kan erg handig zijn als je meerdere builds in bijvoorbeeld Jenkins wilt configureren voor meerdere testomgevingen.

Bronvermelding:

Maven commando met juiste parameter (-Ptst) om testomgeving te bepalen:
mvn clean test -Ptst

Voorbeeld profile (TST omgeving) die opgenomen kan worden in je Pom file:
<profiles>
        <!-- TST profile -->
        <profile>
            <id>tst</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>generate-test-sources</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <delete file="target/test-classes/config.properties"/>
                                        <copy file="src/test/resources/config.tst.properties"
                                              tofile="target/test-classes/config.properties"/>
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.20.1</version>                
                        <dependencies>
                            <dependency>
                                <groupId>org.apache.maven.surefire</groupId>
                                <artifactId>surefire-junit4</artifactId>
                                <version>2.20.1</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
                <finalName>TstEnvironment</finalName>
            </build>
        </profile>
</profiles>



dinsdag 25 juli 2017

Hamcrest icm een Rest Assured demo project

Lijkt het je leuk om eens met Hamcrest te spelen? Dan heb ik goed nieuws. Ga snel naar mijn volgende GitHub repo: https://github.com/Steavy/hamcrest-rest-assured-demo/tree/develop