Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way of writing a test for testing a multilingual website?

I've just written this code for testing our login process for the German version of our website:

describe('login', () => {

    context('Language: DE', () =>{

        beforeEach(() => {
            ...
        })

        it('links to #/passwordforgotten', () => {
            ...
        })

        it('links to #/register', () => {
            ...
        })

        it('links to login further options', () => {
            ...
        })

        it('requires username', () => {
            ...
        })

        it('requires password', () => {
            ...
        })

        it('requires valid username and password', () => {
            ...
        })

        it('navigates to #/ on successful login', () => {
            ...
        }) 
    })
})

Our website is offered in nine languages. Should I replicate this piece of code for each language:

describe('login', () => {

    context('Language: DE', () =>{
        ...
    })

    context('Language: EN', () =>{
        ...
    })

    context('Language: ES', () =>{
        ...
    })

    context('Language: IT', () =>{
        ...
    })

        ...
})

Or should I implement logical structures when it comes to checking the content?

it('requires password', () => {

            cy.get('#UserName').type('username{enter}')
            const url = cy.hash()

            if(url.contains('de')) 
                cy.contains('Bitte geben Sie Ihr Passwort ein!')
            if(url.contains('en')) 
                cy.contains('Please enter your password!')
            if(url.contains('es')) 
                cy.contains('Por favor introduzca su contraseña')
            if(url.contains('it')) 
                cy.contains('Il nome utente o password non è corretto.')

            ...
        }

What's more efficient? And what if this battery of tests is intended to be run regularly?

like image 967
Noob_Number_1 Avatar asked Feb 06 '20 08:02

Noob_Number_1


People also ask

What is Localisation testing?

What is Localization Testing? Essentially, localization testing is a technique to verify software behavior, accuracy, and suitability for specific locations and regions. This could be anything from a particular city to an entire country. The method tests how the software would behave when used in different areas.


1 Answers

I implemented testing for a multi-lingual site that supported 40 language locales by using this trick:

  1. Define one dictionary (JSON file) for each locale. In the locale file, define the mapping between element ID and text.

  2. Write the test suite to take 'locale' as the parameter / environment variable. Test cases will refer to the appropriate dictionary file, based on the locale parameter. Test case will do the assertions based on the mappings defined in locale dictionary.

  3. Run test suite with locale as the parameter. This had helped me avoid lot of if-else conditions and switch blocks!

It also helped run tests for only specific languages for a release. (Scenario where not all language sites were updated for every release)

like image 62
Gopinath Avatar answered Oct 06 '22 00:10

Gopinath