Setting up selenium on Visual Studio is similar to setting up on Eclipse editor. However, to run the java program, we need to import certain libraries. We need to follow a few more steps to get the Selenium/WebDriver code running on the VS Code. Installation is easy and simple.
Setting up VS for Java.
To create a Java project, write code and run the code, we need to install Java extension Pack to the Visual Studio. To install it from VS marketplace, click the link here. This will redirect you to the following page. Click on the Install button.
Download ChromeDriver
To interact with the Chrome Browser, you should have latest ChromeDriver on your system and it should be discoverable by WebDriver. Also, the ChromeDriver major version has to match with your Chrome browser version. I suggest to use latest Chrome browser and corresponding ChromeDriver. Please note that Chrome Browser and ChromeDriver both are different. Download latest ChromeDriver from here.
Base on your operating system, select either binary file or EXE file. Once downloaded, unzip it in the common folder that you can use across multiple project. Next, you download ChromeDriver should be discoverable by WebDriver.On Linux or macOS, you can use the following command to make the filediscoverable.
export PATH=$PATH:~/<yourFolder>/drivers/bin/
here <yourFolder>/drivers/bin/ is a folder path where you have downloaded and unzipped ChromDriver.
There is another way to make this binary or EXE file discoverable by WebDriver. You should set the system property in your code. Add the path to ChromeDriver in your test code:
Open Command Pallet in VS Code (Ctrl / Cmd + Shift + P).
In next Step, Select No Builds option, Select Project Location or Workspace and enter project name. This will create a Java Project in the given folder. The New Project will have lib and src folder along with a sample java program that will print “Hello World” in the terminal.
Click on the run button available in the top right corner.
So far, so good. You can create and run java program. Now let’s set up Selenium/WebDriver.
Setup Selenium WebDriver
Download the latest stable Selenium Web Driver client and Java language bindings.
Now in VS Editor go the left side bottom and click on the + sign near Referenced Library under Java Section. See the following screenshot. Select Selenium server jasr file and import it. Now let’s import jar files for the java client. Click on + sign and import all jar files from the Selenium-Java-4.8.1 folder. Again import all files from the lib file under Selenium-Java-4.8.1 folder.
Congratulations!!!! You completed the set of Visual Studio for the Selenium with Java Programming language.
Open Google.com using Selenium
Now let’s modify App.java file available under src folder. First we need to import WebDriver and then Chrome Driver class.
Import WebDriver and ChromeDriver.
Adding the following two lines at the top of the App.java program.
Import org.openqa.selenium.WebDriver;
Import org.openqa.selenium.chrome.ChromeDriver;
Now inside main function, add code to open browser and get the URL.
That’s It.
Hope you like this article. Please do not forget to rate it.
What is PyCharm? PyCharm is a cross-platform IDE that provides consistent experience on the Windows, macOS, and Linux operating systems. PyCharm is available in three editions: Professional, Community, and Edu. The Community and Edu editions are open-source projects and they are free, but they have fewer features. PyCharm Edu provides courses and helps you learn programming with Python. The Professional edition is commercial, and provides an outstanding set of tools and features. For details, see the editions comparison matrix PyCharm also run and debug tests in the same way as other applications/IDE like Eclipse, Visual Studio or Visual Code, by running the run/debug configurations you have added. When doing so, it passes the specified test classes or methods to the test runner. To configure the Run options, we need to follow the following steps Benefits of running tests from PyCharm UI improves productivity lot. Easier to run eithe...
What is Pytest: Pytest Benefits: Pytest Installation: This tutorial uses Python 3 , and we will be working inside a virtualenv . Python 3 has inbuilt support for creating virtual environments. We can very easily create and use a virtual environment for this demo project. We need to run the following commands in the cmd. mkdir pytest_demo # this will create directory. cd pytest_demo # move to newly create directory Python3 -m venv pytest-demo # this creates a virtual environment called pytest-env in our working directory. To see, Run command dir [on Mac or Unix OS] source pytest-demo/bin/activate . # This activates virtual environment. As long as this virtualenv is active, any package we install will be installed in this new virtual environment. [on Winodws OS] pytest-demo\Scripts\activate pip install pytest # This installs pytest on virtual environment. pytest -h ...
How to create simple log file that contain Timestamp, Filepath, line number and user message. i.e. 2012-03-22 16:06:30 C:/Automation/lib/Utils.pl : 1569 -- Command Line options are : XYZ How do we print message on CMD in different color based on message type? What is message Type: Warning message Fatal Error Debug information General error Test case pass Test case failed Test case review Perl Code: use strict; use warnings; use Cwd; use vars qw($VERSION); $VERSION = '0.01'; use Color::Output; Color::Output::Init; my %msgColors = ( "debug" => 14, # Cyan "info" => 15, # "white", "warn" => 13, # yellow "error" => 4, #"red", "fatal" =...
Comments
Post a Comment