Access is denied exception while running autoit exe file from selenium java code - exception

In my selenium webdriver code i am calling an autoit exe for handling an windows authentication dialog . But when i execute the code it it throwing exception
the code is
try {
String s2 = System.getProperty("user.dir");
String path2 = s2 + "\\src\resources\\AuthHandler.exe";
java.lang.Runtime.getRuntime().getRuntime().exec(path2);
} catch (IOException e1) {
e1.printStackTrace();
}
The exception is
java.io.IOException: Cannot run program
"D:\ProjCode\workspace\xxxx\src": CreateProcess error=5, Access is
denied
What might be the reason for this . i tried
Process p = new ProcessBuilder(path2).start();
but getting the same result .
The exe is having execute privilege, when i double click it, it is working fine .

try {
String s2 = System.getProperty("user.dir");
String[] myEXEpath = new String[]{ s2 + "\\src\\resources\\"+"MyExe.exe","firefox" };
java.lang.Runtime.getRuntime().getRuntime().exec(myEXEpath);
} catch (IOException e1) {
e1.printStackTrace();
}

Related

Using mockwebserver to test URL/URI DataHandler/DataSource

I am trying to use mockwebserver to test POSTing via a Jakarta-based activation URLDataSource's outputStream.
In the jakarta.activation.DataSource, you only have "getInputStream()/getOutputStream()".
The 'getOutputStream()' method internally opens a URLConnection and gets and returns its OutputStream().
#Override
public OutputStream getOutputStream() throws IOException {
URLConnection connection = this.uri.toURL().openConnection();
connection.setDoOutput(true);
return connection.getOutputStream();
}
I can write to the output-stream with no problem. But closing the output-stream does not trigger the MockWebServer dispatcher. Since I don't have the connection in the caller, I can't call "getResponseCode()" to make the request hit the server (as in some examples I have seen).
try (OutputStream os = (new URIDataSource(mockWebServerUri)).getOutputStream()) {
IOUtils.write(testMessage, os, StandardCharsets.UTF_8);
} catch (IOException ex) {
fail ("Unable to obtain OutputStream from URIDataSource.");
}
Any suggestions on how / if I can trigger the dispatcher after closing the output-stream without having the connection?
Cheers, Jeff

Run Sikuli commands on Katalon-Studio

I'm trying to run a test that contains Sikuli methods in it via Katalon-Studio.
I added the necessary libraries but still getting this error when it tries to execute the Sikuli command:
[error] ResourceLoaderBasic: checkLibsDir: libs dir is not on system path: C:\Users\roinr\git\QA\Drivers\libs
[action] ResourceLoaderBasic: checkLibsDir: Please wait! Trying to add it to user's path
[info] runcmd: reg QUERY HKCU
[info] runcmd: reg QUERY HKEY_CURRENT_USER\Environment /v PATH
[error] ResourceLoaderBasic: checkLibsDir: Logout and Login again! (Since libs folder is in user's path, but not activated)
[error] Terminating SikuliX after a fatal error! Sorry, but it makes no sense to continue!
If you do not have any idea about the error cause or solution, run again
with a Debug level of 3. You might paste the output to the Q&A board.
This is my script:
import internal.GlobalVariable as GlobalVariable
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.sikuli.script.Key;
import org.sikuli.script.Screen;
//Initializing server
System.setProperty("webdriver.chrome.driver", "C:/selenium/chromedriver.exe");
//Initializing variables
ChromeDriver wd = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(wd,10);
Screen s = new Screen();
wd.manage().window().maximize();
wd.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
System.out.println("*** Login Sikuli ***");
wd.get("https://autoqa-materials-zone.firebaseapp.com/login");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[2]/div/input")));
wd.findElement(By.xpath("//div[2]/div/input")).click();
try { Thread.sleep(1000l); } catch (Exception e) { throw new RuntimeException(e); }
s.paste("<USERNAME>");
try { Thread.sleep(1000l); } catch (Exception e) { throw new RuntimeException(e); }
s.type(Key.TAB);
try { Thread.sleep(800l); } catch (Exception e) { throw new RuntimeException(e); }
s.paste("<PASSWORD>");
try { Thread.sleep(1000l); } catch (Exception e) { throw new RuntimeException(e); }
wd.findElement(By.xpath("//form[#id='form']//paper-button[.='login']")).click();
try { Thread.sleep(5000l); } catch (Exception e) { throw new RuntimeException(e); }
wd.quit();
Hope you can help me with that,
thanks.

Files are always Read-only when Using EPPLUS to generate Excel file from Database table

I'm using EPPLUS to generate Excel file from Database table but the file created stay on Read-only mode until the full SSIS process is stopped.
I need to move the file after later in the process and this will always fail with the following message in SSIS:
[File System Task] Error: An error occurred with the following error
message: "The process cannot access the file because it is being used
by another process.".
When I try to open the file in excel I got the "File in Use"
book1.xlsx is locked for editing
by 'another user'.
Open 'Read-Only' or click 'Notify' to open read-only and receive notification when the document is no longer in use.
I hope you'll be able to help me.
Here is my code:
public void Main()
{
try
{
String FilePath = Dts.Variables["$Package::DestinationFileName"].Value.ToString();
String TableName = Dts.Variables["$Package::SourceTableName"].Value.ToString();
String ConnStr = Dts.Variables["$Project::ConnStr_DataWarehouse"].Value.ToString();
//SqlConnection Conn = (SqlConnection)(Dts.Connections["DW"].AcquireConnection(Dts.Transaction) as SqlConnection);
using (SqlConnection Conn = new SqlConnection(ConnStr))
{
String Sql = "SELECT * FROM " + TableName;
if (File.Exists(FilePath))
{
try { File.Delete(FilePath); }
catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); Dts.TaskResult = (int)ScriptResults.Failure; }
}
using (DataTable dt = new DataTable())
{
using (SqlCommand cmd = new SqlCommand(Sql, Conn))
{
Conn.Open();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
FileInfo newFile = new FileInfo(FilePath);
using (ExcelPackage p = new ExcelPackage(newFile))
{
using (ExcelWorksheet ws = p.Workbook.Worksheets.Add("RejectetionReport"))
{
ws.Cells["A1"].LoadFromDataTable(dt, true);
p.Save();
}
}
}
Conn.Close();
}
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
Dts.TaskResult = (int)ScriptResults.Failure;
}
}
I'm using EPPLUS 4.0.5 which I plan to update to 4.1 but the release note doesn't seam to cover this issue.
EDIT:
I've upgraded to 4.1 but the issue still exists.
I found the issue.
There is a bug in the EPPLUS library which is not disposing of a stream before disposal of the package.
I've submitted a fix an pull request under fork DebugPackageDispose
Hopefully, this will be integrated soon.

Exception Handling in java to show user the catch error message from the nested method calls

I have doubt in Exception handling in java,when the exception is thrown in the called method, how to show the catch error in the calling method
Yes, it is possible to catch exception inside called method, and then re-throw same exception back to caller method.
public String readFirstLineFromFile(String path) throws IOException {
try {
BufferedReader br = new BufferedReader( new FileReader (path));
StringBuilder lines = new StringBuilder();
String line;
while((line = br.readLine()) != null) {
System.out.println("REading file..." + line);
lines.append(line);
}
return lines.toString();
} catch(IOException ex) {
System.out.println("Exception in called method.." + ex);
throw ex;
}
}
Note: It is not possible if you are using try with resources, and exception occurred inside resources itself like opening of file, or file not found. In that case exception will be directly thrown back to caller.

Running pig local, UDF program cannot write files/folder: PriviledgedActionException

Newbie with Pig/hadoop..
Running pig at local.
java -Xmx512m -Xmx1024m -cp $PIGDIR/pig.jar org.apache.pig.Main -Dpig.temp.dir=/tmp/$USER/$RANDOM -stop_on_failure -x local script-buzz.pig
with my script.pig:
(...)
buzz = FOREACH files GENERATE chiron.buzz.Honey(file, id) as buzz_file, id;
Trying to write a folder/file with my UDF raise:
[JobControl] ERROR org.apache.hadoop.security.UserGroupInformation - PriviledgedActionException as:felipehorta cause:org.apache.pig.backend.executionengine.ExecException: ERROR 2118: Input path does not exist: file:/Users/felipehorta/dev/ufrj/pig/pig-buzz/output
the following code must (!) writes files that are consumed at the next LOAD.
jar works fine with: $ java -jar Pgm.jar *
(...)
public String exec(Tuple input) throws IOException {
try{
System.out.println(input.get(0).toString());
BumbleBee b = new BumbleBee(input.get(0).toString());
return b.writeRelation(input.get(1).toString());
} catch(Exception e){
System.err.println("Failed to process input; error - " + e.getMessage());
return null;
}
}
public String writeRelation(String folder) throws IOException {
try {
// writing file!
File output = new File("output/ERelation_" + folder + ".txt");
output.getParentFile().mkdirs();
FileWriter fw = new FileWriter(output);
String line = System.getProperty("line.separator");
fw.append("YEAR;WORD;COUNT" + line);
for (Integer year : buzzCandidates.keySet()) {
Map<String, Long> wordCounts = buzzCandidates.get(year);
for (String word : wordCounts.keySet()) {
long value = wordCounts.get(word);
if (value >= 3) {
fw.append(year + ";" + word.replace(" ", "_") + ";" + String.valueOf(value) + line);
}
}
}
fw.flush();
fw.close();
return output.getAbsolutePath();
} catch (Exception e) {
System.out.println(">>> ERROR!!\t" + e.getMessage());
return "ERROR";
}
}
I think it is about permission writing files with UDF, but I dont know where set permissions. Any help?
Thanks in advance, fellows!
Error reads Input path does not exist: file:/Users/felipehorta/dev/ufrj/pig/pig-buzz/output Please check the pig script as to how the load is used.
relation = load '/Users/felipehorta/dev/ufrj/pig/pig-buzz/output' using ...
would be the correct way of doing it.
Not sure if this could be the exact reason. Would be great if you could post the scripts.