Choose the language of the application

Hi @Chris_Trevarthen,

Is it possible to force the language with which we want to run our test case?

For example: if my phone is set to French, and my test case is in English, is it possible to force the language of the application in English?

Thanks in advance

Hi @walpokbymon,

You might be able to use Appium’s Desired Capabilities to specify the language when starting the app:

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

String appFile = "/fullpathtomyfile/mobile-beta.apk"

// The language settings
RunConfiguration.setMobileDriverPreferencesProperty("language", "fr")
RunConfiguration.setMobileDriverPreferencesProperty("locale", "FR")

// Start the application
Mobile.startApplication(appFile, false)

Hope this helps,

Chris

Hi @Chris_Trevarthen

I tried your script but it works only the first time, here is my script:

import static com.kms.katalon.core.checkpoint.CheckpointFactory. findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory. findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory. findTestData
import static com.kms.katalon.core.testobject.ObjectRepository. findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory as MobileDriverFactory
import io.appium.java_client.AppiumDriver as AppiumDriver
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

String appFile = "/********###*******.apk"

// The language settings

RunConfiguration. setMobileDriverPreferencesProperty ("language", "fr")

RunConfiguration. setMobileDriverPreferencesProperty ("locale", "FR")

// Start the application

Mobile.startApplication (appFile, false )

Mobile.tap ( findTestObject ('android.widget.Button0 - Se connecter (22)'), 0)

Mobile.setText ( findTestObject ('android.widget.EditText0 - Email (11)'), 'dazda', 0)

Mobile.setText ( findTestObject ('android.widget.EditText1 - Mot de passe (11)'), 'aaaa', 0)

Mobile.tap ( findTestObject ('android.widget.Button0 - Se connecter (23)'), 0)

Mobile.verifyElementText ( findTestObject ("android.widget.TextView1 - Le champ e-mail nest pas au bon format (3)'), 'Le champ 'e-mail' n'est pas au bon format")

Mobile.clearText ( findTestObject ('android.widget.EditText0 - dazda'), 0)

Mobile.setText ( findTestObject ('android.widget.EditText0 - Email (11)'), 'adaaad@aaaaa.aaaaa', 0)

Mobile.clearText ( findTestObject ('android.widget.EditText1 - aaaa'), 0)

Mobile.setText ( findTestObject ('android.widget.EditText1 - Mot de passe (11)'), 'aaaassa', 0)

Mobile.tap ( findTestObject ('android.widget.Button0 - Se connecter (23)'), 0)

AppiumDriver<?> dd1 = MobileDriverFactory. getDriver ()

def tt1 = dd1.findElementByXPath('//android.widget.Toast[@text='Veuillez vérifier votre email et votre mot de passe (Erreur #113)']')

println('Toast element: ' + tt1)

if (tt1 == null ) {

KeywordUtil. markFailed ('ERROR: Toast object not found!')

}

Mobile.clearText ( findTestObject ('android.widget.EditText0 - adaaadaaaaa.aaaaa'), 0)

Mobile.setText ( findTestObject ('android.widget.EditText0 - Email (11)'), '***A###', 0)

Mobile.clearText ( findTestObject ('android.widget.EditText1 - aaaassa'), 0)

Mobile.setText ( findTestObject ('android.widget.EditText1 - Mot de passe (11)'), 'aaaaaq', 0)

Mobile.tap ( findTestObject ('android.widget.Button0 - Se connecter (23)'), 0)

AppiumDriver<?> drvfr1 = MobileDriverFactory. getDriver ()

def tstfr1 = drvfr1.findElementByXPath("//android.widget.Toast[@text='Veuillez vérifier votre email et votre mot de passe (Erreur #113)']")

println('Toast element: ' + tstfr1)

if (tstfr1 == null ) {

KeywordUtil. markFailed ('ERROR: Toast object not found!')

}

Mobile.clearText ( findTestObject ('android.widget.EditText1 - aaaaaq'), 0)

Mobile.setText ( findTestObject ('android.widget.EditText1 - Mot de passe (11)'), '**********###', 0)

Mobile.tap ( findTestObject ('android.widget.Button0 - Se connecter (23)'), 0)

Mobile.verifyElementExist ( findTestObject ('android.view.View0 - CONDITIONS GENERALES EASYMOVIE'), 0, FailureHandling. OPTIONAL )

Mobile.tap ( findTestObject ('android.widget.TextView1 - Accepter (5)'), 0, FailureHandling. OPTIONAL )

Mobile.verifyElementExist ( findTestObject ('android.widget.TextView0 - Template'), 0, FailureHandling. OPTIONAL )

Mobile.tap ( findTestObject ('android.widget.ImageView1'), 0, FailureHandling. OPTIONAL )

Mobile.tap ( findTestObject ('android.widget.ImageView1 (1)'), 0)

Mobile.verifyElementText ( findTestObject ('android.widget.TextView42 - Client'), 'Client : ***##')

Mobile.closeApplication ()




note that the first time I run the script, despite my Android device is set in English, the application is launched in French, but it does not work at the end of the script, it stopped at the first check of the toast
the other times I started the script, the application always runs in English

here is my log:

05-01-2019 01:49:19 PM tap(findTestObject("android.widget.Button0 - Se connecter (22)"), 0)

Elapsed time: 32,942s

Failed to tap on element 'Object Repository/android.widget.Button0 - Se connecter (22)' (Root cause: com.kms.katalon.core.exception.StepFailedException: Object Object Repository/android.widget.Button0 - Se connecter (22) not found

at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:48)

at com.kms.katalon.core.mobile.keyword.internal.MobileKeywordMain.stepFailed(MobileKeywordMain.groovy:40)

at com.kms.katalon.core.mobile.keyword.builtin.TapKeyword$_tap_closure1.doCall(TapKeyword.groovy:77)

at com.kms.katalon.core.mobile.keyword.builtin.TapKeyword$_tap_closure1.call(TapKeyword.groovy)

at com.kms.katalon.core.mobile.keyword.internal.MobileKeywordMain.runKeyword(MobileKeywordMain.groovy:21)

at com.kms.katalon.core.mobile.keyword.builtin.TapKeyword.tap(TapKeyword.groovy:83)

at com.kms.katalon.core.mobile.keyword.builtin.TapKeyword.execute(TapKeyword.groovy:66)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)

at com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords.tap(MobileBuiltInKeywords.groovy:485)

at com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords$tap$0.call(Unknown Source)

at TestConnectFr.run(TestConnectFr:30)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:336)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:327)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:306)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:298)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:232)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at TempTestCase1556714867190.run(TempTestCase1556714867190.groovy:21)

)

I think that the reason why the script stopped is because on the script, the text of the button where I wanted to tap is in French and on the application at the time of the test the button has the text in English.

Thanks in advance

Hi @walpokbymon,

I think you’re right, the error shows that the button cannot be found, and it’s probably because the text you’re expecting is French, but the button is in English when the test is running.

It’s weird that the app is starting in French the first time, but English after that. I wonder if you changed the second parameter to startApplication to be true if it would be in French every time:

Mobile.startApplication (appFile, true)

Could you try that and see if it’s any different?

Thanks,

Chris

Hi @Chris_Trevarthen,

I changed the second parameter to true but I still have the same result :frowning:
My script after the last modification :

import static com.kms.katalon.core.checkpoint.CheckpointFactory. findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory. findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory. findTestData
import static com.kms.katalon.core.testobject.ObjectRepository. findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory as MobileDriverFactory
import io.appium.java_client.AppiumDriver as AppiumDriver
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

String appFile = “/********###*******.apk”

// The language settings

RunConfiguration. setMobileDriverPreferencesProperty (“language”, “fr”)

RunConfiguration. setMobileDriverPreferencesProperty (“locale”, “FR”)

// Start the application

Mobile.startApplication (appFile, true )

Mobile.tap ( findTestObject (‘android.widget.Button0 - Se connecter (22)’), 0)

Mobile.setText ( findTestObject (‘android.widget.EditText0 - Email (11)’), ‘dazda’, 0)

Mobile.setText ( findTestObject (‘android.widget.EditText1 - Mot de passe (11)’), ‘aaaa’, 0)

Mobile.tap ( findTestObject (‘android.widget.Button0 - Se connecter (23)’), 0)

Mobile.verifyElementText ( findTestObject (“android.widget.TextView1 - Le champ e-mail nest pas au bon format (3)’), 'Le champ ‘e-mail’ n’est pas au bon format”)

Mobile.clearText ( findTestObject (‘android.widget.EditText0 - dazda’), 0)

Mobile.setText ( findTestObject (‘android.widget.EditText0 - Email (11)’), ‘adaaad@aaaaa.aaaaa’, 0)

Mobile.clearText ( findTestObject (‘android.widget.EditText1 - aaaa’), 0)

Mobile.setText ( findTestObject (‘android.widget.EditText1 - Mot de passe (11)’), ‘aaaassa’, 0)

Mobile.tap ( findTestObject (‘android.widget.Button0 - Se connecter (23)’), 0)

AppiumDriver<?> dd1 = MobileDriverFactory. getDriver ()

def tt1 = dd1.findElementByXPath(’//android.widget.Toast[@text=‘Veuillez vérifier votre email et votre mot de passe (Erreur #113)’]’)

println('Toast element: ’ + tt1)

if (tt1 == null ) {

KeywordUtil. markFailed (‘ERROR: Toast object not found!’)

}

Mobile.clearText ( findTestObject (‘android.widget.EditText0 - adaaadaaaaa.aaaaa’), 0)

Mobile.setText ( findTestObject (‘android.widget.EditText0 - Email (11)’), ‘***A###’, 0)

Mobile.clearText ( findTestObject (‘android.widget.EditText1 - aaaassa’), 0)

Mobile.setText ( findTestObject (‘android.widget.EditText1 - Mot de passe (11)’), ‘aaaaaq’, 0)

Mobile.tap ( findTestObject (‘android.widget.Button0 - Se connecter (23)’), 0)

AppiumDriver<?> drvfr1 = MobileDriverFactory. getDriver ()

def tstfr1 = drvfr1.findElementByXPath("//android.widget.Toast[@text=‘Veuillez vérifier votre email et votre mot de passe (Erreur #113)’]")

println('Toast element: ’ + tstfr1)

if (tstfr1 == null ) {

KeywordUtil. markFailed (‘ERROR: Toast object not found!’)

}

Mobile.clearText ( findTestObject (‘android.widget.EditText1 - aaaaaq’), 0)

Mobile.setText ( findTestObject (‘android.widget.EditText1 - Mot de passe (11)’), ‘**********###’, 0)

Mobile.tap ( findTestObject (‘android.widget.Button0 - Se connecter (23)’), 0)

Mobile.verifyElementExist ( findTestObject (‘android.view.View0 - CONDITIONS GENERALES EASYMOVIE’), 0, FailureHandling. OPTIONAL )

Mobile.tap ( findTestObject (‘android.widget.TextView1 - Accepter (5)’), 0, FailureHandling. OPTIONAL )

Mobile.verifyElementExist ( findTestObject (‘android.widget.TextView0 - Template’), 0, FailureHandling. OPTIONAL )

Mobile.tap ( findTestObject (‘android.widget.ImageView1’), 0, FailureHandling. OPTIONAL )

Mobile.tap ( findTestObject (‘android.widget.ImageView1 (1)’), 0)

Mobile.verifyElementText ( findTestObject (‘android.widget.TextView42 - Client’), ‘Client : ***##’)

Mobile.closeApplication ()

Please, is there any other way to solve this problem ?

Thank you in advance