When I access the login page for a network device, a credentials popup opens as shown below. Katalon studio does not record actions or we cannot do any spy object within this window.Is this because that window is not a web element? I am using Katalon Studio web version 7.7.2. Thanks.
import java.awt.Robot as Robot
import java.awt.event.KeyEvent as KeyEvent
def th = new Thread((({
for (i = 0; i < 10; i++) {
Robot robot = new Robot()
Thread.sleep(5000)
robot.keyPress(KeyEvent.VK_ENTER)
Thread.sleep(1000)
break
}
}) as Runnable))
and add below code just before the action where popup displays
th.start()
def th = new Thread((({
for (i = 0; i < 10; i++) {
Robot robot = new Robot()
Thread.sleep(5000)
robot.keyPress(KeyEvent.VK_ENTER)
Thread.sleep(1000)
break
}
}) as Runnable))
//Enter username and password
WebUI.executeJavaScript('window.open();', [])
String currentWindow = WebUI.getWindowIndex()
//Go in to new tab
WebUI.switchToWindowIndex(currentWindow + 1)
WebUI.navigateToUrl(GlobalVariable.activationURL)
th.start()
WebUI.click(findTestObject(inputUsername))
WebUI.setText(findTestObject(inputUsername),username)
WebUI.click(findTestObject(inputPassword))
WebUI.setText(findTestObject(inputPassword),password)
WebUI.click(findTestObject(signIn))
//Click on activation field
WebUI.click(findTestObject(inputActivationCode))
WebUI.setText(findTestObject(inputActivationCode),result)
WebUI.click(findTestObject(activateButton))
//Coming back
WebUI.switchToWindowIndex(currentWindow)
//Verify that the camera has been enrolled
}
FYI, it says it cannot find the test object. That is normal because i cannot spy on that object. Is there a solution/workaround for this? Thanks.
I m sorry for delay, not sure why it is not identifying the popup, can you try on another browser. if still face the issue, ask your developers (try to enable popup) . let me know what they say thanks
Aside: It is my strong belief that when writing test case code, there are very, very few situations where threading is a requirement or even a benefit. So few, in fact, I have never come across one.
If you donât need added complexity, donât add it.
Basically, when I select the spy web to spy on any object in that popup, I dont have the option to capture the object. Even if I record a test case, it will not record any actions on any object within that popup.
Ok lets ignore the code, I was using that code because it was suggested to me to fix the problem. Letâs recap. I have an HTML URL (see below) that I would need to access to change something within that web page. When I access the web page, a credentials popup is shown (See below). Katalon Studio web will not let me do a spy object on any of the elements within that popup (eg: username/password, sign In, etc). That is the issue I am encountering. Any thoughts? comments?
I see no reason why Robot wouldnât work there, as long as you get the timing right (I noticed you need to switch windows/tabs). Be sure you arrive at the new window in a timely manner and run the robot code. To move from Name to Password, use a Tab key.
My advice, remove the thread stuff but keep the closure (everything between { and }) and call it from your test case at the correct step position (i.e. after the new window/tab is open and ready).
Lastly, letâs see if we can get @Brandon_Hein to take a look - I think he posted something relevant to basic auth dialogs a while backâŚ
From within the robot code, I fail to see where the actually setting of the username and password is done. Note that I have copied the code given to me exactly as is.DO i need to adapt it to my needs?
It is currently failing at where the setText command is ran. This is because it cannot find the object. DO i need to include this somehow in the robot part of the code? If so, how? Thanks.
@Keyword
def activateSCP(result,username,password){
//Enter username and password
WebUI.executeJavaScript(âwindow.open();â, )
String currentWindow = WebUI.getWindowIndex()
//Go in to new tab
WebUI.switchToWindowIndex(currentWindow + 1)
WebUI.delay(5)
int i
def th = new Thread((({
for (i = 0; i < 10; i++) {
Robot robot = new Robot()
Thread.sleep(5000)
robot.keyPress(KeyEvent.VK_ENTER)
Thread.sleep(1000)
break
}
}) as Runnable))
th.start()
WebUI.navigateToUrl(GlobalVariable.mobotixActivationURL)
WebUI.setText(findTestObject(inputUsername),username)
WebUI.click(findTestObject(inputPassword))
WebUI.setText(findTestObject(inputPassword),password)
WebUI.click(findTestObject(signIn))
//Click on activation field
WebUI.click(findTestObject(inputActivationCode))
WebUI.setText(findTestObject(inputActivationCode),result)
WebUI.click(findTestObject(activateButton))
//Coming back
WebUI.switchToWindowIndex(currentWindow)
//Verify that the camera has been enrolled
}
In essence, the Robot API targets the OS, just like a user does when (s)he uses the keyboard or mouse - no user ever has to specify the text input directly, they type into the control with focus, or set it first with a click. Then the OS directs the keyboard keys to the control.
See?
Thatâs why I said, as long as you get the timing right and Be sure you arrive at the new window in a timely manner. The dialog should be allowed time to appear, THEN you can execute the Robot code.
Again - that thread stuff is NOT included in my advice. Iâm working under the assumption itâs not there.
Sorry iâm confused. How is the text set in the username/password fields? What am I missing in the code I provided? Right now it just shows the sign-in popup and stops there. Thanks.
I removed the thread stuff, here is what my code looks like. Also, the for look iterates 10 times, not sure what that is for to be honest. I used this code as suggested in my script. What do i need to do to adapt it to my test case? Ie: login to the web page with credentials.
Thanks.
@Keyword
def activateSCP(result,username,password){
//Enter username and password
WebUI.executeJavaScript(âwindow.open();â, [])
String currentWindow = WebUI.getWindowIndex()
//Go in to new tab
WebUI.switchToWindowIndex(currentWindow + 1)
WebUI.delay(5)
int i
//def th = new Thread((({
for (i = 0; i < 10; i++) {
Robot robot = new Robot() //Thread.sleep(5000) //robot.keyPress(KeyEvent.VK_ENTER) //Thread.sleep(1000)
break
}
//}) as Runnable))
//th.start()
WebUI.navigateToUrl(GlobalVariable.mobotixActivationURL)
//WebUI.click(findTestObject(inputUsername))
WebUI.setText(findTestObject(inputUsername),username)
WebUI.click(findTestObject(inputPassword))
WebUI.setText(findTestObject(inputPassword),password)
WebUI.click(findTestObject(signIn))
//Click on activation field
WebUI.click(findTestObject(inputActivationCode))
WebUI.setText(findTestObject(inputActivationCode),result)
WebUI.click(findTestObject(activateButton))
//Coming back
WebUI.switchToWindowIndex(currentWindow)
//Verify that the camera has been enrolled
}
Yes I am aware of that. I would like to know how do i set text in the username/password field using the robot code? I haven;t found anything to help me with this. I was hoping I would get help from someone in the forum. Thanks.