roni1800
roni1800

Reputation: 117

how to embed an external javascript file to a c# selenium test unit?

I'm using visual studio to write a c# test unit using the selenium webdrive, at some point I've decided to implement a javascript file.

The Javascript file is a little too long to write it directly in the c# code, so I've added an empty Javascript file in Visual studio and copied the code there.

The .js file is visible in the solution explorer but I don't know how to access it from the c# code.

Can you guys provide a sample code on how to access the .js file? thanks.

Upvotes: 1

Views: 834

Answers (1)

maryum375
maryum375

Reputation: 727

Try that:

using System.IO;


IJavaScriptExecutor selenium = _driver as IJavaScriptExecutor;
string path = @"Path to your file";
string jsFileContent = File.ReadAllText(path);
selenium.ExecuteScript (jsFileContent);

Upvotes: 1

Related Questions