Using key pressing while executing test suite via Jenkins doesn't work

I have a test case which using this solution for file uploading

when i execute this case via Katalon - it works like a charm, but when i setup this case to be executed in jenkins - it doesn’t work.
my opinion that this ctrl+c ctrl+v solution has issues while working on background…

Anyone faced that issue or probably there is another solution for files uploading in background? (regular UploadFile doesn’t work)

Would be appreciated for any help…

2 Likes

Anyone pls…

This part of script

WebUI.click(findTestObject(‘products-add-upload/Page_pr/button_Add image_to_product’))

WebUI.delay(4, FailureHandling.STOP_ON_FAILURE)

WebUI.focus(findTestObject(‘products-add-upload/Page_pr/Upload-image-product-modal’))

CustomKeywords.‘upload.Uploader.uploadFile’(findTestObject(‘products-add-upload/Page_pr/form_Drop files here to upload_product_image’),

'C:\\\Users\\\spiblin\\\Downloads\\\3005471.jpg')

WebUI.delay(5, FailureHandling.STOP_ON_FAILURE)

WebUI.click(findTestObject(‘products-add-upload/Page_pr/button_Save_product_image_after upload’))

And this is a custom keyword

package upload

import java.awt.Robot

public class Uploader {

@Keyword

def uploadFile(TestObject to, String filePath) {

WebUI.click(to)

StringSelection ss = new StringSelection(filePath);

Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);

Robot robot = new Robot();

sleep(3000)

robot.keyPress(KeyEvent.VK_ENTER);

robot.keyRelease(KeyEvent.VK_ENTER);

robot.keyPress(KeyEvent.VK_CONTROL);

robot.keyPress(KeyEvent.VK_V);

robot.keyRelease(KeyEvent.VK_V);

robot.keyRelease(KeyEvent.VK_CONTROL);

robot.keyPress(KeyEvent.VK_ENTER);

robot.keyRelease(KeyEvent.VK_ENTER);

}

}

It fails when Save button doesn’t found
I think it’s because upload is not successful and save window doesn’t appear

Is there an error message?

No related to image uploading

04-24-2018 01:16:07 PM - [INFO]   - Focusing on object: 'Object Repository/products-add-upload/Page_pr/Upload-image-product-modal'04-24-2018 01:16:07 PM - [PASSED] - Object: 'Object Repository/products-add-upload/Page_pr/Upload-image-product-modal' is focused04-24-2018 01:16:07 PM - [END]    - End action : focus04-24-2018 01:16:07 PM - [START]  - Start action : upload.Uploader.uploadFile04-24-2018 01:16:07 PM - [INFO]   - Finding Test Object with id 'Object Repository/products-add-upload/Page_pr/form_Drop files here to upload_product_image'04-24-2018 01:16:07 PM - [INFO]   - Checking object04-24-2018 01:16:07 PM - [INFO]   - Checking timeout04-24-2018 01:16:07 PM - [INFO]   - Finding web element with id: 'Object Repository/products-add-upload/Page_pr/form_Drop files here to upload_product_image' located by 'By.xpath: //form[(text() = 'Drop files here to upload' or . = 'Drop files here to upload')]' in '30' second(s)04-24-2018 01:16:07 PM - [INFO]   - Found 1 web elements with id: 'Object Repository/products-add-upload/Page_pr/form_Drop files here to upload_product_image' located by 'By.xpath: //form[(text() = 'Drop files here to upload' or . = 'Drop files here to upload')]' in '30' second(s)04-24-2018 01:16:07 PM - [INFO]   - Clicking on object: 'Object Repository/products-add-upload/Page_pr/form_Drop files here to upload_product_image'04-24-2018 01:16:07 PM - [PASSED] - Object: 'Object Repository/products-add-upload/Page_pr/form_Drop files here to upload_product_image' is clicked on04-24-2018 01:16:10 PM - [PASSED] - upload.Uploader.uploadFile is PASSED04-24-2018 01:16:10 PM - [END]    - End action : upload.Uploader.uploadFile04-24-2018 01:16:10 PM - [START]  - Start action : delay04-24-2018 01:16:10 PM - [INFO]   - Delaying browser in 5 second(s)04-24-2018 01:16:15 PM - [PASSED] - Delayed 5 second(s)04-24-2018 01:16:15 PM - [END]    - End action : delay04-24-2018 01:16:15 PM - [START]  - Start action : click04-24-2018 01:16:15 PM - [INFO]   - Finding Test Object with id 'Object Repository/products-add-upload/Page_pr/button_Save_product_image_after upload'04-24-2018 01:16:15 PM - [INFO]   - Checking object04-24-2018 01:16:15 PM - [INFO]   - Checking timeout04-24-2018 01:16:15 PM - [INFO]   - Finding web element with id: 'Object Repository/products-add-upload/Page_pr/button_Save_product_image_after upload' located by 'By.xpath: //button[@class = 'btn btn-info btn-continue' and @type = 'button' and (text() = 'Save' or . = 'Save')]' in '30' second(s)--------------------------------------------------------------------------------04-24-2018 01:16:47 PM - [FAILED] - Unable to click on object 'Object Repository/products-add-upload/Page_pr/button_Save_product_image_after upload' (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'Object Repository/products-add-upload/Page_pr/button_Save_product_image_after upload' located by 'By.xpath: //button[@class = 'btn btn-info btn-continue' and @type = 'button' and (text() = 'Save' or . = 'Save')]' not found)
04-24-2018 01:16:47 PM - [END]    - End action : click04-24-2018 01:16:47 PM - [FAILED] - Test Cases/Auto4-products-add-remove-upload FAILED because (of) Unable to click on object 'Object Repository/products-add-upload/Page_pr/button_Save_product_image_after upload' (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'Object Repository/products-add-upload/Page_pr/button_Save_product_image_after upload' located by 'By.xpath: //button[@class = 'btn btn-info btn-continue' and @type = 'button' and (text() = 'Save' or . = 'Save')]' not found)

The test is trying to click on a button bit it can’t find it. You should check the xpath is correct.

I understand that… but it can’t find it because window is doesn’t appear, and looks like it doesn’t appear because image upload is not working.
I wrote earlier that when i run test case in Katalon and looking for a result - everything seems to be fine, but when i execute it from jenkins e.g. in background - it fails on that step.

So? No luck?
Let try from another side
Following case:
You’re using jenkins for regular automate testing and you have a modern field to upload file or image, no matter.
How do you handle this?
Dropzone looks this way

dropzone.jpg

Vladyslav Bayrak said:

I understand that… but it can’t find it because window is doesn’t appear, and looks like it doesn’t appear because image upload is not working.
I wrote earlier that when i run test case in Katalon and looking for a result - everything seems to be fine, but when i execute it from jenkins e.g. in background - it fails on that step.

Did you find the solution for this…Even i am facing similar problem where File Upload is working fine when test suite run from Katalon Studio where as it fails when run through Jenkins…How you have handle in order to run through Jenkins

Me too, i use robot to save the download file also not working if i trigger the job from jenkins. However it run successfully if the click the run icon from katalon.

Anyone found a solution regarding this? I have the same issue with the file upload with jenkins.

Hello

Anyone found a solution for this? It would be very helpful.

@vitlev, @aumei.chua

Please share details about your problem.

Hi @duyluong

Good day. Sorry for the late reply.

I am facing similar problem where File Upload is working fine when test suite run from Katalon Studio locally, where as it fails when run through Jenkins.

The keyword I used is below:
def uploadFileToTest(TestObject to, String filePath){
WebUI.click(to)
WebUI.delay(3)
StringSelection ss = new StringSelection(filePath)
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null)
WebUI.delay(2)

	Robot robot = new Robot()
	robot.keyPress(KeyEvent.VK_ENTER)
	robot.keyRelease(KeyEvent.VK_ENTER);
	robot.keyPress(KeyEvent.VK_CONTROL);
	robot.keyPress(KeyEvent.VK_V);
	robot.keyRelease(KeyEvent.VK_V);
	robot.keyRelease(KeyEvent.VK_CONTROL);
	robot.keyPress(KeyEvent.VK_ENTER);
	robot.keyRelease(KeyEvent.VK_ENTER);

}

The file I use to upload, I had already put in Data Files folder.

Any solution to this?