Skip to content

Commit

Permalink
Make sure that it works with any OSs (Windows/Mac)
Browse files Browse the repository at this point in the history
  • Loading branch information
agilecreativity committed Jul 30, 2016
1 parent f563a07 commit 92935f8
Show file tree
Hide file tree
Showing 28 changed files with 395 additions and 868 deletions.
37 changes: 21 additions & 16 deletions .project
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>selenium-cucumber-java</name>
<comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
<name>testscj</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
9 changes: 2 additions & 7 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#Sun Jul 24 17:20:45 EDT 2016
encoding/src/test/java=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
encoding/src/main/resources=UTF-8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
encoding/src/main/java=UTF-8
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
eclipse.preferences.version=1
encoding/src/test/resources=UTF-8
org.eclipse.jdt.core.compiler.source=1.7
Binary file added Screenshots/screenshot20150401193118.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/screenshot20150401194652.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/screenshot20150428193817.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/screenshot20150428194030.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<version>4.11</version>
<scope>test</scope>
</dependency>

<!-- These are the selenium-webdriver dependencies -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
Expand All @@ -57,7 +56,6 @@
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
Expand All @@ -69,7 +67,6 @@
<source>1.7</source>
<target>1.7</target>
<compilerArgument>-Werror</compilerArgument>

<systemPropertyVariables>
<property>
<name>browser</name>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/env/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import methods.NavigateMethods;
import methods.ProgressMethods;
import methods.ScreenShotMethods;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public interface BaseTest
{
public interface BaseTest {
public static WebDriver driver = Env.CreateWebDriver(Env.getBrowserName());
public static WebDriverWait wait = new WebDriverWait(driver, 30);

Expand Down
92 changes: 44 additions & 48 deletions src/main/java/env/Env.java
Original file line number Diff line number Diff line change
@@ -1,67 +1,63 @@
package env;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.safari.SafariDriver;

public class Env
{
public class Env {

static WebDriver driver = null;
static String browserName = null;

public static String getBrowserName()
{
public static String getBrowserName() {
browserName = System.getProperty("browser");

if(browserName == null)
if (browserName == null)
browserName = "ff";
return browserName;
}

public static WebDriver CreateWebDriver(String browser)
{
System.out.println("Browser: " + browser);

switch (browser.toLowerCase()) {
case "ff":
case "firefox":
//ProfilesIni allProfiles = new ProfilesIni();
//FirefoxProfile profile = allProfiles.getProfile("selenium");
//driver = new FirefoxDriver(profile);
driver = new FirefoxDriver();
break;

case "ch":
case "chrome":
driver = new ChromeDriver();
break;

case "ie" :
case "internetexplorer":
driver = new InternetExplorerDriver();
break;

case "safari":
driver = new SafariDriver();
break;

default:
System.out.println("Invalid browser name "+browser);
System.exit(0);
break;
}//switch

driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(60, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

return driver;
}

public static WebDriver CreateWebDriver(String browser) {
System.out.println("Browser: " + browser);

switch (browser.toLowerCase()) {
case "ff":
case "firefox":
// ProfilesIni allProfiles = new ProfilesIni();
// FirefoxProfile profile = allProfiles.getProfile("selenium");
// driver = new FirefoxDriver(profile);
driver = new FirefoxDriver();
break;

case "ch":
case "chrome":
driver = new ChromeDriver();
break;

case "ie":
case "internetexplorer":
driver = new InternetExplorerDriver();
break;

case "safari":
driver = new SafariDriver();
break;

default:
System.out.println("Invalid browser name " + browser);
System.exit(0);
break;
}// switch

driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(60, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

return driver;
}
}
32 changes: 13 additions & 19 deletions src/main/java/methods/ScreenShotMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,28 @@
import env.BaseTest;

public class ScreenShotMethods implements BaseTest {
/** Method to take screen shot and save in ./Screenshots folder */

public ScreenShotMethods() {
}

public void takeScreenShot() throws IOException {
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
File scrFile = (File) ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");

DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
Calendar cal = Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));

String scrFilepath = scrFile.getAbsolutePath();
System.out.println("scrFilepath: " + scrFilepath);

File currentDirFile = new File("Screenshots");
String path = currentDirFile.getAbsolutePath();
System.out.println("path: " + path + "+++");
System.out.println((new StringBuilder("scrFilepath: ")).append(scrFilepath).toString());

System.out.println("****\n" + path + "\\screenshot" + dateFormat.format(cal.getTime()) + ".png");
File currentDirFile = new File("Screenshots");

FileUtils.copyFile(scrFile, new File(path + "\\screenshot" + dateFormat.format(cal.getTime()) + ".png"));
String path = currentDirFile.getAbsolutePath();

/*
* DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
* Calendar cal = Calendar.getInstance();
* System.out.println(dateFormat.format(cal.getTime()));
*/
FileUtils.copyFile(scrFile,
new File((new StringBuilder(String.valueOf(path))).append(File.separator + "screenshot-")
.append(dateFormat.format(cal.getTime())).append(".png").toString()));
}
/*
* cur_time = Time.now.strftime('%Y%m%d%H%M%S%L')
* $driver.save_screenshot('./features/screenshots/screenshot' + cur_time +
* '.png')
*/
}
6 changes: 3 additions & 3 deletions src/test/java/stepDefintions/Hooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public class Hooks {
@After("@NegativeTest")
public void beforeScenario(Scenario scenario) {
// System.out.println("In hooks");
// System.out.println(scenario.getName());
// System.out.println(scenario.getStatus());
// System.out.println("In hooks");
// System.out.println(scenario.getName());
// System.out.println(scenario.getStatus());
}
}
Loading

0 comments on commit 92935f8

Please sign in to comment.