Skip to content

Instantly share code, notes, and snippets.

@tcd1558
Last active April 29, 2021 01:59
Show Gist options
  • Save tcd1558/a641ef301e26484996ce3bcf2848be7a to your computer and use it in GitHub Desktop.
Save tcd1558/a641ef301e26484996ce3bcf2848be7a to your computer and use it in GitHub Desktop.
Selenium Essential Training - GitHub Repository and IntelliJ Java project

Selenium Essential Training - GitHub repository and IntelliJ Java project

1. Overview

Here are the steps necessary to set up a GitHub repository with the files provided through the Selenium Essential Training course and have it work as a Java project inside IntelliJ. The idea is to take the files provided by the course and add them into a GitHub repository. You will then clone the repository onto your local system and perform the first exercise. The first exercise represents a change to your source tree. You could file an issue on GitHub and submit your solution as a fix to the issue.
This text ist written from the perspective of MacOS.

2. Syntax

[button] - is a button on the screen with the text 'button' on it.   
InputField: - is a field labeled 'InputField:', where you can enter text.   
<PlaceHolder> - a placeholder to be replaced with your own text (without the '<' and '>').  
[v] Label1 - ensure there is a check mark in front of the label 'Label1'
[x] Label2 - ensure there is an 'x' in the check box in front of the label 'Label2'
1/3 - step 1 of in total 3 steps
$ - prompt for a regular user
# - prompt for the root user (system administrator)

3. Create a Java Project in IntelliJ

  1. Open IntelliJ
  2. [New Project]
  3. Java
  4. [Next]
  5. [Next]
  6. Project name: SeleniumEssentialTraining
  7. [Finish]

4. Create a GitHub Repository

  1. Go to the GitHub page of the team leader (If it is just you, you are the team leader):
    https://github.com/<team lead>
  2. In the top, black bar click on the + sign
  3. Select 'New repository'
  4. Match the name with local project:

SeleniumEssentialTraining

  1. Provide a Description

Exercise files for the LinkedIn course Selenium Essential Training

  1. [v] Add a README file
  2. Click [Create repository]
  3. Capture the URL:
    https://github.com/<team lead>/SeleniumEssentialTraining

5. Move IntelliJ Project

Make room to clone the GitHub directory and temporary rename (not delete) your project directory

$ mv SeleniumEssentialTraining SeleniumEssentialTraining.Project

P.S. There is an alternative way of solving this, by renaming, rebasing the local repository. For details refer to the gist https://gist.github.com/tcd1558/a838deda7dd5968bab6c3d88b9aa466d

6. Clean up IntelliJ project selector

  1. Go back to IntelliJ
  2. Close the window, which opened when you created your new IntelliJ Java project SeleniumEssentialTraining
  3. You will see, that your project SeleniumEssentialTraining is grayed out (because you renamed it).
  4. Let's clean up this entry in the project list by clicking it.
  5. You will get a notification stating

The path <your path> does not exist. If it is on a removable or network drive, please make sure that the drive is connected.

  1. Click [Remove From List]

7. Clone GitHub repository

  1. In the window 'Welcome to IntelliJ IDEA', click on the top, right button [Get from VCS]
  2. In the window 'Get from Version Control', click on [GitHub]
  3. ***What if you have not signed in yet - needs edit ***
  4.    [PyCharm], [Preferences], [GitHub], [+], [Login via GitHub...]
  5.    [PyCharm], [Preferences], [Appearance], [System Settings], [Passwords]
  6. Do not save, forget passwords after restart
  7. [Log in via GitHub...]
  8. URL: https://github.com/<team lead>/SeleniumEssentialTraining
  9. Directory: /Users/<user>/IdeaProjects/SeleniumEssentialTraining
  10. [Clone]
  11. Close the IntelliJ Project Window and leave the window 'Welcome to IntelliJ IDEA'

8. Merge IntelliJ project with GitHub repository

  1. Make a copy of the just cloned directory for backup.

$ cp -r SeleniumEssentialTraining SeleniumEssentialTraining.GitHub

  1. Add the IntelliJ misc.xml, SelenumEssentialTraining.iml file

$ cp SeleniumEssentialTraining.Project/.idea/misc.xml SeleniumEssentialTraining/.idea
$ cp SeleniumEssentialTraining.Project/.idea/SelenumEssentialTraining.iml SeleniumEssentialTraining/.idea
$ echo "/out/
/chromedriver_mac64.zip
/Ex_Files_Selenium_EssT.zip
/selenium-java/selenium-java-3.141.59.zip" >SeleniumEssentialTraining/.gitignore

  1. Create the src direcory:

$ mkdir SeleniumEssentialTraining/src

  1. In the window 'Welcome to IntelliJ IDEA', select/open the SeleniumEssentialTraining project.

8.1 Git add 1/5

Select the <my_project> directory Right click Git Add

or

$ git add .
   or
$ git add --all

8.2 Git commit 1/5

Right click on the project SeleniumEssentialTraining or the src directory
Git
Commit Directory...
A Changelist pops up
In the lower part of the Commit window, provide a Commit Message:
      "Initial Check-in of the SeleniumEssentialTraining files"
Click [Commit]

or

$ git commit -m "Initial Check-in of the SeleniumEssentialTraining files"

8.3 Git push 1/5

Right Click on the project Git Push or Shift+CMD+K Push

or

$ git push

9 Add Selenium Essential Training frame work

  1. Add the chromedriver

$ cp <Downloads>/chromedriver_<my_architecture>.zip SeleniumEssentialTraining

  1. Add selenium-java.zip

$ mkdir SeleniumEssentialTraining/selenium-java
$ cp <Downloads>/selenium-java/selenium-java-3.141.59.zip SeleniumEssentialTraining/selenium-java

Hint: to see the content of a zip file use:

$ unzip -l <zipfile>

The chromedriver is not inside a directory, when unzipping. This is fine, since it is only one file.
The selenium-java files are not inside a directory, when unzipping. Since these are several files, unzip this file inside the selenium-java directory.

  1. unzip all zip files using:

$ unzip <zipfile>

Refresh IntelliJ with:
Right click the project
Reload from Disk

9.1 Git add 2/5

9.2 Git commit 2/5

9.3 Git push 2/5

10 Enable IntelliJ to find the jar files

First, exercize 06_0x need JUnit. The prepare the environment for all tests, let's first download the JUnit jar file. Below is the chain of links and documents to download the JUnit jar files. I hope this is useful to find your way around, when the chain changed. You can also just click on the Maven Central link.

Use Shift+Click to open below links in another window https://junit.org/junit5/
Click on Code & Issues (GitHub) - https://github.com/junit-team/junit5/
https://github.com/junit-team/junit5/README.md
User Guide - https://junit.org/junit5/docs/current/user-guide/
1.4 Getting Started - https://junit.org/junit5/docs/current/user-guide/#overview-getting-started
1.4.1 Download JUnit Artifacts - https://junit.org/junit5/docs/current/user-guide/#dependency-metadata
10.2 Dependency Metadata - Maven Central - https://search.maven.org/

Maven Central - search for 'junit' The search results are sorted by release date. Click on the Download icon (last column) to download the jar file. Move the junit-4.13.2.jar file to SeleniumEssentialTraining/selenium-java, so all needed jar files are in one location.

$ mv ~/<Downloads>/junit-4.13.2.jar SeleniumEssentialTraining/selenium-java

10.1 Make all the needed jar files available to the IntelliJ projecs

Add all jar files to the IntelliJ libraries with:

  1. Highlight the Project
  2. File > Project Structure (or CMD+;)
  3. Project Setting > Libraries > click on the '+' in the middle pannel
  4. New Project Library > Java
  5. A file explorer window pops up. Navigate to selenium-java
  6. Select all .jar libs/.jar files (using CMD+click), click on [open], click on [ok]
  7. When all of them are listed, click on [ok]

10.2 Git add 3/5

10.3 Git commit 3/5

10.4 Git push 3/5

11 Add Selenium Essential Training exercises

  1. Add Ex_Files_selenium_EssT.zip

$ cp <Downloads>/Ex_Files_Selenium_EssT.zip SeleniumEssentialTraining

Hint: to see the content of a zip file use:

$ unzip -l <zipfile>

The Ex_Files_Selenium_EssT.zip files are stored inside a directory, when unzipping.

Note: The directory struction of the exercise files contains 3 problems:

  1. There is a directory with a space in the name. Java can not handle this properly
  2. The examples are inside directories, whose name starts with a number. Java has problems with this as well.
  3. When you start doing the first exercise and you try to run your java code, IntelliJ tries to compile all the java

Addressing problem 1:
Move the exercise directories to the src directory created when you created the IntelliJ project

$ mv SeleniumEssentialTraining/Ex_Files_Selenium_EssT/Exercise\ Files/* SeleniumEssentialTraining/src

Addressing problem 2: Put a prefix of letters in front of all the exersise directories:

$ cd SelentiumEssentialTraining/src
$ for DIR in `ls -d [0-9][0-9]_[0-9][0-9]`
do
   mv $DIR Ex_$DIR
done

Some exercizes come with an iml file. They need to be adjusted to the new directory name:

$ cd SelentiumEssentialTraining/src
$ mv ./Ex_02_02/.idea/02_02.iml ./Ex_02_02/.idea/Ex_02_02.iml
$ mv ./Ex_05_03/.idea/05_03.iml ./Ex_05_03/.idea/Ex_05_03.iml

Addressing problem 3: Hide all java exercise files by renaming them until you get to them.

$ cd SelentiumEssentialTraining/src
$ for FILE in ` find . -name \*.java `
do
     mv $FILE $FILE.org
done

Modify all java.org files to reflect the location of your chromedriver. If you followed the above instructions, your chromedriver can be found under:
~/IdeaProjects/SeleniumEssentialTraining/chromedriver

*** work in progress ***

$ cd SelentiumEssentialTraining/src
$ for FILE in ` find . -name \*.java `
do
     echo $FILE
done

Refresh IntelliJ with:
Right click the project
Reload from Disk

11.1 Git add 3/5

11.2 Git commit 3/5

11.3 Git push 3/5

12 Tag the branch

Tag your branch, so you can always get back to this point of the repository.

$ git tag v1.0

12.1 Git add 3/5

12.2 Git commit 3/5

12.3 Git push 3/5

@RiditaNizam
Copy link

exercises, not exercizes

@RiditaNizam
Copy link

Java, not Jave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment