Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #1 and #3 #5

Merged
merged 4 commits into from Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 17 additions & 30 deletions README.md
Expand Up @@ -8,47 +8,33 @@ This program uses the Command Line Interface (CLI) to run the .jar file. Once th
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

### Prerequisites

- [Chrome Web Driver](https://chromedriver.chromium.org/)
- [Windows Terminal - up to date](https://github.com/lextm/windowsterminal-shell)
- DeadLinkage.jar file
- [Windows Terminal - up to date](https://github.com/lextm/windowsterminal-shell) is required as it supports ANSI colour codes.
- [Google Chrome](https://www.google.com/intl/en_ca/chrome/) must be installed as chromedriver relies on the Chrome Browser to send and test Get requests.

### Installing

A step by step series of examples that tell you how to get a testing environment running on CLI.

Download .jar file from the repository.

![Repo](https://raw.githubusercontent.com/pyvelkov/DeadLinkage/master/0.1%20MDassets/github%2001.JPG?token=ANEOJ54GEUAD6SINYHCHFFK7OTM4E)
![Repo Path](https://raw.githubusercontent.com/pyvelkov/DeadLinkage/master/0.1%20MDassets/github%2002.JPG?token=ANEOJ57RPQAK6WJGY4JQCJ27OTNA4)

Once you have the .jar file, download the [Chrome Web Driver](https://chromedriver.chromium.org/) for your correct version of Google Chrome.

Once you retrieve the correct chromedriver.exe, an environment variable path must be set.

Place the chromedriver.exe in a new location anywhere on your drive.
i.e.
1. `git clone https://github.com/pyvelkov/DeadLinkage.git`
2. Set the system environment variable PATH variable by doing the following:
1. Place the chromedriver.exe located in the DeadLinkage folder in a new location anywhere on your harddrive (optional). For my example I will make a new folder called webdrivers in my User folder.
![enter image description here](https://raw.githubusercontent.com/pyvelkov/DeadLinkage/master/0.1%20MDassets/chromedriver%2001.JPG?token=ANEOJ52DGUDODVIIMC6TP6K7OTSUG)
Now copy the path where the chromedriver.exe is located (highlighted above)

1. Right click on "This PC"
2. Click "properties" on the pop-up window
3. Click "Advanced system settings"
4. A "System Properties" window will appear, click on "Environment Variables..." button on the bottom.
2. Now copy the path where the chromedriver.exe is located (highlighted above)
3. Right click on "This PC"
4. Click "properties" on the pop-up window
5. Click "Advanced system settings"
6. A "System Properties" window will appear, click on "Environment Variables..." button on the bottom.
![enter image description here](https://raw.githubusercontent.com/pyvelkov/DeadLinkage/master/0.1%20MDassets/chromedriver%2002.JPG?token=ANEOJ5352TCLEECP4KPPIDK7OTT7C)
5. Click on "Path" under the System Variables select box and hit "Edit..."
7. Click on "Path" under the System Variables select box and hit "Edit..."
![enter image description here](https://raw.githubusercontent.com/pyvelkov/DeadLinkage/master/0.1%20MDassets/chromedriver%2003.JPG?token=ANEOJ5354SMJW4YKXJDB6427OTUFI)
6. Click "New" and paste the location of chromedriver.exe
8. Click "New" and paste the location of chromedriver.exe
![enter image description here](https://raw.githubusercontent.com/pyvelkov/DeadLinkage/master/0.1%20MDassets/chromedriver%2004.JPG?token=ANEOJ52FGLYAC4N3HPBOSH27OTUTW)
3. Type `refreshenv` into Windows Terminal.
4. `cd DeadLinkage\out\artifacts\DeadLinkage_jar` and run the respective commands listed below.

Congratulations. You are now set up to use the DeadLinkage tool.

## Running the tests

Once all requirements and installations have been met and completed it is time to run the tool from the CLI.

Open the updated Windows Terminal downloaded from above and navigate to where you saved the .jar file, using the cd (change directory command).

Once all requirements and installations have been met and completed it is time to run the tool from the CLI. Running any of the commands will cause Google Chrome to open and the tests to begin in the Windows Terminal.

### Valid arguments

Expand All @@ -69,7 +55,7 @@ java -jar DeadLinkage.jar -u URL
```
i.e.
```
java -jar DeadLinkage.jar -u github.com/pyvelkov/DeadLinkage
java -jar DeadLinkage.jar -u https://github.com/pyvelkov/DeadLinkage
```
To run the tool with a local html file located in the same directory as the .jar

Expand All @@ -89,3 +75,4 @@ java -jar DeadLinkage.jar -f fileName.html
## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

18 changes: 0 additions & 18 deletions src/DeadLinkTest.java
Expand Up @@ -11,14 +11,10 @@


public class DeadLinkTest {

//colors
//text
public static final String RED = "\033[0;31m";
public static final String GREEN = "\033[0;32m";
public static final String WHITE = "\033[0;37m";
public static final String RESET = "\033[0m";
//bgd
public static final String RED_BACKGROUND = "\033[41m";
public static final String GREEN_BACKGROUND = "\033[42m";

Expand All @@ -29,26 +25,21 @@ public static void main(String[] args)
if (args.length == 0){
driver.quit();
helpMessage();
//System.exit(0);
}
else if (args[0].equals("-v")){
driver.quit();
versionMessage();
//System.exit(0);
}
else if(args[0].equals("-f") && args[1].endsWith(".html")){
/*using relative path============================================*/
Path pathFile = Paths.get(args[1]);
driver.get(pathFile.toUri().toString());
}
else if(args[0].equals("-u") && args[1].contains("http")){
/*using website=================================================*/
driver.get(args[1]);
}
else{
driver.quit();
helpMessage();
//System.exit(0);
}

driver.manage().window().maximize();
Expand Down Expand Up @@ -108,23 +99,14 @@ public static void checkLink(String linkUrl)
try
{
URL url = new URL(linkUrl);

HttpURLConnection httpURLConnect=(HttpURLConnection)url.openConnection();

httpURLConnect.setRequestMethod("HEAD");

//use this so I don't get my ip blacklisted for scraping too much
//httpURLConnect.setConnectTimeout(1000);

httpURLConnect.connect();

if(httpURLConnect.getResponseCode() == 200)
{
System.out.println(GREEN + linkUrl + " ----> " + "[" + WHITE + GREEN_BACKGROUND + HttpURLConnection.HTTP_OK + RESET + GREEN + "] - " + httpURLConnect.getResponseMessage() + RESET);
}
/*else if(httpURLConnect.getResponseCode()>=300 && httpURLConnect.getResponseCode()<=399){
System.out.println(RED + linkUrl + " ----> " + WHITE + RED_BACKGROUND + httpURLConnect.getResponseMessage() + " - " + HttpURLConnection.HTTP_MOVED_PERM + RESET);
}*/
else if(httpURLConnect.getResponseCode() >= 400 && httpURLConnect.getResponseCode() <= 499)
{
System.out.println(RED + linkUrl + " ----> " + "[" + WHITE + RED_BACKGROUND + HttpURLConnection.HTTP_NOT_FOUND + RESET + RED + "] - " + httpURLConnect.getResponseMessage() + RESET);
Expand Down