Hi all!
I have a script that calls another script to verify if the actual account is the one that is logged in, if not,switch to that account. THe script runs perfectly well when ran on its own. In the other script which calls this one, it fails on the second switch. Please see error below. I am wondering if this is because when i created the switch script the object’s properties were different than what they are now.
Is is because when you do a spy on an object, it uses xpaths that are specific to where you did spy the object from? And if you are in another part of the web page, it cannot find those properties and hence fail? I am confused as to why this is happening. Any comments? suggestions? Thanks.
Unable to find the element located by ‘By.xpath: .//*[normalize-space(text()) and normalize-space(.)=‘2.3_Train09’])[2]/following::div[4]’. Please recheck the objects properties to make sure the desired element is located.
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 static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
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 com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
String integratorLink = “Object Repository/Page_Stratocast portal - Cloud administrators/IntegratorsLink”;
String oldIntegratorNameLink = “Object Repository/Page_Stratocast portal - Integrators/integratorName”
String backArrowIntegratorEditPage = “Object Repository/Page_Stratocast portal - Massimo2.3_Train09 - Edit/backArrow”
String integratorsTabLink = “Object Repository/Page_Stratocast portal - Massimo2.3_Train09 - Edit/a_Integrators”
String clientsLink = “Object Repository/Page_Stratocast portal - Client accounts/span_Clients”
String accountName = “Object Repository/Page_Stratocast portal - Client accounts/accountName”
String switchAccountsArrow = “Object Repository/Page_Stratocast portal - Cloud administrators/switchAccountsArrow”
//String configurationsButton = “Object Repository/Page_Stratocast portal - Dashboard/span_Configurations”
Boolean accountLoggedIn
TestObject configurationsButton = new TestObject(“Object Repository/Page_Stratocast portal - Dashboard/span_Configurations”)
WebUI.callTestCase(findTestCase(‘Admission Authority/Admission Authority - Login - Organizational Account (750)’), [:], FailureHandling.CONTINUE_ON_FAILURE)
//Switch accounts
accountLoggedIn = CustomKeywords.‘admissionAuthority.AdminLogin.getLoggedInAccount’(GlobalVariable.switchToCloudAdmin,accountLoggedIn)
WebUI.click(findTestObject(integratorLink))
CustomKeywords.‘integrators.Integrators.filterIntegrator’(GlobalVariable.oldIntegratorName)
WebUI.click(findTestObject(oldIntegratorNameLink))
//Remote monitoring setting
CustomKeywords.‘integrators.Integrators.remoteMonitoringSetting’(GlobalVariable.remoteMonitoringSetting1)
CustomKeywords.‘integrators.Integrators.scrollToElement’(switchAccountsArrow)
//Switch accounts
accountLoggedIn = CustomKeywords.‘admissionAuthority.AdminLogin.getLoggedInAccount’(GlobalVariable.switchToClientAccount,accountLoggedIn)
@Keyword
def getLoggedInAccount(String account,accountLoggedIn) {
‘this method is to verify which account is logged in and sets a flag to determine if the client account needs to be logged in’
accountLoggedIn = false
if (WebUI.verifyElementVisible(findTestObject(cloudAdminAccount),FailureHandling.OPTIONAL)){
KeywordUtil.markPassed(‘Cloud administrator is logged in’)
if (account != ‘Cloud administrator’) {
‘if we want the cloud administrator to be logged in, switch to that account’
WebUI.click(findTestObject(switchAccountsArrow))
WebUI.click(findTestObject(switchAccountsMenuOption))
new clientAccount.ClientAccount().getRowColumnTable(account)
return accountLoggedIn
}
}
else if (WebUI.verifyElementVisible(findTestObject(integratorAdminAccount), FailureHandling.OPTIONAL)){
KeywordUtil.markPassed(‘Integrator administrator is logged in’)
if (account != ‘Integrator administrator’) {
‘if we want the integrator administrator to be logged in, switch to that account’
WebUI.click(findTestObject(switchAccountsArrow))
WebUI.click(findTestObject(switchAccountsMenuOption))
new clientAccount.ClientAccount().getRowColumnTable(account)
return accountLoggedIn
}
}
else {
if (WebUI.verifyElementVisible(findTestObject(clientAdminAccount), FailureHandling.OPTIONAL)) {
KeywordUtil.markPassed(‘Client administrator is logged in’)
accountLoggedIn = true
//If client admin is the one that is not suppose to be logged in, switch accounts
if (account != ‘Client administrator’) {
‘if we want the client administrator to be logged in, switch to that account’
WebUI.click(findTestObject(switchAccountsArrow))
WebUI.click(findTestObject(switchAccountsMenuOption))
new clientAccount.ClientAccount().getRowColumnTable(account)
return accountLoggedIn = false
}
return accountLoggedIn
}
else {
KeywordUtil.markFailed(“Account " + account + " was not successfully logged in”)
}
}