0

I am running c# Unit Tests through Windows Jenkins and while executing tests console output window shows me same error for all the tests:

Error Message: Test method Levan_Test threw exception: System.ComponentModel.Win32Exception: Access is denied Stack Trace: at System.Windows.Forms.SendKeys.SendInput(Byte[] oldKeyboardState, Queue previousEvents) at System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait) at System.Windows.Forms.SendKeys.SendWait(String keys)

It looks like there is some problem with permissions or power shell command execution.

code snippet:

Thread.Sleep(1000);
driver.FindElement(By.XPath("//*[@id=\"solutionsDropdown\"]/div/i")).Click();
Thread.Sleep(1000);
driver.FindElement(By.XPath("//*[@id=\"solutionsDropdown\"]/ul/li[2]/a")).Click();
Thread.Sleep(1000);
SendKeys.SendWait("{Enter}");
budi
  • 6,351
  • 10
  • 55
  • 80
  • Yep, that's sure what it looks like. Any additional clues, like maybe some code to look at? – Robert Harvey Jul 06 '17 at 18:48
  • I'm finding plenty of advice about this on Google. Looks like you're not the only one who has had this problem. In particular: https://stackoverflow.com/questions/42501443/access-denied-error-while-running-powershell-script – Robert Harvey Jul 06 '17 at 18:52
  • Did you have a look at that other Stack Overflow article? Your problem is fairly unremarkable; you're using an account on the target machine that doesn't have the necessary permissions. – Robert Harvey Jul 06 '17 at 19:39
  • I tried to run Jenkins service as administrator instead of local system but it did not start the service at all. – Levan Taktakishvili Jul 06 '17 at 20:24
  • _This could be totally off_: By any chance, do you _really_ intend to use Windows Forms? Did you perhaps mean to use [WebElement.sendKeys](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html#sendKeys-java.lang.CharSequence...-)? There is a way to [directly send Enter to a WebElement](https://stackoverflow.com/questions/1629053/typing-enter-return-key-in-selenium). – Stefan Hanke Jul 06 '17 at 20:28
  • I can not replicate command: SendKeys.SendWait("C:\\Users\\Levan Taktakishvili\\Downloads\\Test.docx"); – Levan Taktakishvili Jul 06 '17 at 20:46
  • I posted an answer to my question. – Levan Taktakishvili Jul 12 '17 at 21:57

1 Answers1

0

After a lot of research I found out that: if you are running Jenkins as a service, it can't do stuff that interacts with the desktop, e.g., Windows forms applications. You would want to have a build agent running on the desktop using JNLP as a normal user that runs these tests.