# Katalon: Custom keyword working when executing on Chrome but not on Firefox

**URL:** <https://forum.katalon.com/t/katalon-custom-keyword-working-when-executing-on-chrome-but-not-on-firefox/62356>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [February 9, 2022, 4:59am UTC](https://forum.katalon.com/t/katalon-custom-keyword-working-when-executing-on-chrome-but-not-on-firefox/62356 "2022-02-09T04:59:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mauri.figueroa](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mauri.figueroa/32/16104_2.png) [@mauri.figueroa](https://forum.katalon.com/u/mauri.figueroa)\
**Post date:** [February 9, 2022, 4:59am UTC](https://forum.katalon.com/t/katalon-custom-keyword-working-when-executing-on-chrome-but-not-on-firefox/62356/1 "2022-02-09T04:59:43Z")

</div>

I have this custom keyword that waits until a file is downloaded and then deletes the file, the thing is that in chrome works okay but when I execute in firefox I get an error.

```
 @Keyword
public verifyDownloadedFile2(String downloadPath, String fileName, timeOut) {
int counter = 0
boolean fileExist = new File(downloadPath + fileName).exists()
        
while(!fileExist == true) {
    if(counter != timeOut) {
        WebUI.delay(1)
        fileExist = new File(downloadPath + fileName).exists()
        counter++
    }
    else if(counter == timeOut){
        throw new Exception("File was not downloaded within" + timeOut + " seconds.")
    }   
}

File dir = new File(downloadPath);
File[] dirContents = dir.listFiles();

if (dirContents.length > 0) {
    for (int i = 0; i < dirContents.length; i++) {
        dirContents[i].delete();
    }
}

assert fileExist == true
}

```

Error:

> # =============== ROOT CAUSE ===================== Caused by: org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: windows.interactions.deleteFile2() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.Integer) values: [F:\Downloads\Katalon\_Studio\_Windows\_64-8.1.0\Data\Temp, …]

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [February 9, 2022, 6:06am UTC](https://forum.katalon.com/t/katalon-custom-keyword-working-when-executing-on-chrome-but-not-on-firefox/62356/2 "2022-02-09T06:06:31Z")

</div>

I made a copy of your keyword class as this:

```auto
package mauri

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

public class Util {

	@Keyword
	public verifyDownloadedFile2(String downloadPath, String fileName, timeOut) {
		File file = new File(downloadPath + fileName)
		println "file=" + file.toString()
		
		int counter = 0
		boolean fileExist = file.exists()
		while(!fileExist == true) {
			if(counter != timeOut) {
				WebUI.delay(1)
				fileExist = file.exists()
				counter++
			}
			else if(counter == timeOut){
				throw new Exception("File was not downloaded within" + timeOut + " seconds.")
			}
		}

		File dir = new File(downloadPath);
		File[] dirContents = dir.listFiles();

		if (dirContents.length > 0) {
			for (int i = 0; i < dirContents.length; i++) {
				dirContents[i].delete();
			}
		}

		assert fileExist == true
	}
}

```

I changed just 2 lines to make a variable of `File file`.

I made a Test Case to execute the keyword:

```auto
CustomKeywords."mauri.Util.verifyDownloadedFile2"("tmp", "a.txt", 10)

```

When I execute this Test Case, it failed with the following message.

```auto
2022-02-09 14:59:38.031 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2022-02-09 14:59:38.035 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/mauri
file=tmpa.txt
2022-02-09 14:59:48.818 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - ❌ java.lang.Exception: File was not downloaded within10 seconds.
2022-02-09 14:59:48.823 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/mauri FAILED.
Reason:
com.kms.katalon.core.exception.StepErrorException: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.Exception: File was not downloaded within10 seconds.
	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.throwError(CustomKeywordDelegatingMetaClass.java:96)
	

```

Please find the following output:

```auto
file=tmpa.txt

```

This is too bad. I have a file “tmp/a.txt” on my Mac (or “tmp\a.txt” on Windows). There is no file named `tmpa.txt`. So, it is rational that the test fails.

Your code has a mistake at

```auto
... new File(downloadPath + fileName)

```

This code would never work properly.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [February 9, 2022, 6:10am UTC](https://forum.katalon.com/t/katalon-custom-keyword-working-when-executing-on-chrome-but-not-on-firefox/62356/3 "2022-02-09T06:10:19Z")

</div>

Do you want some solution? Then, read this article

- [https://www.baeldung.com/java-path-vs-file](https://www.baeldung.com/java-path-vs-file)

In there you will find a sample code:

```auto
Path path2 = Paths.get("baeldung").resolve("tutorial.txt");

```

This is what you need.

You shouldn’t use `java.io.File` class any longer. Prefer `java.nio.file.Path`.

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [February 9, 2022, 4:06pm UTC](https://forum.katalon.com/t/katalon-custom-keyword-working-when-executing-on-chrome-but-not-on-firefox/62356/4 "2022-02-09T16:06:36Z")

</div>

> [@mauri.figueroa](#):
>
> public verifyDownloadedFile2(String downloadPath, String fileName, timeOut) {

I will let you two discuss the File variable, but could it be that the error is passed to the “missingMethod…” because it’s wanting a data type to your “timeOut” variable, if it uses that?

```auto
public verifyDownloadedFile2(String downloadPath, String fileName, int timeOut) {

```

---

<div class="post-metadata">

**Author:** ![mauri.figueroa](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mauri.figueroa/32/16104_2.png) [@mauri.figueroa](https://forum.katalon.com/u/mauri.figueroa)\
**Post date:** [February 9, 2022, 6:51pm UTC](https://forum.katalon.com/t/katalon-custom-keyword-working-when-executing-on-chrome-but-not-on-firefox/62356/5 "2022-02-09T18:51:05Z")

</div>

Hi thanks for noticing this!

I fixed it and now it doesn’t generate an error, but when running on firefox some files are deleted after verifying them and some are not, not sure what is happening.

---

<div class="post-metadata">

**Author:** ![mauri.figueroa](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mauri.figueroa/32/16104_2.png) [@mauri.figueroa](https://forum.katalon.com/u/mauri.figueroa)\
**Post date:** [February 9, 2022, 6:51pm UTC](https://forum.katalon.com/t/katalon-custom-keyword-working-when-executing-on-chrome-but-not-on-firefox/62356/6 "2022-02-09T18:51:09Z")

</div>

Hey Thanks for the help but I wasn’t able to use “Paths”, sorry I am new to programming and I am not sure why it is not working. Thanks anyways!

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [February 9, 2022, 10:12pm UTC](https://forum.katalon.com/t/katalon-custom-keyword-working-when-executing-on-chrome-but-not-on-firefox/62356/7 "2022-02-09T22:12:50Z")

</div>

> [@mauri.figueroa](#):
>
> I wasn’t able to use “Paths”

you need to write appropriate `import` statements for `Paths`.

See [https://www.baeldung.com/java-nio-2-path](https://www.baeldung.com/java-nio-2-path) for examples.
