/*-
* #%L
* jasmine-maven-plugin
* %%
* Copyright (C) 2010 - 2017 Justin Searls
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.github.searls.jasmine.driver;
import com.github.searls.jasmine.mojo.Capability;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class WebDriverFactoryTest {
private WebDriverFactory factory;
@Before
public void setUp() {
factory = new WebDriverFactory();
factory.setBrowserVersion("FIREFOX_3_6");
factory.setWebDriverClassName(HtmlUnitDriver.class.getName());
}
@Test
public void defaultDriverIsCustomHtmlUnitDriver() throws Exception {
assertEquals(QuietHtmlUnitDriver.class, factory.createWebDriver().getClass());
}
@Test
public void defaultDriverEnablesJavascript() throws Exception {
HtmlUnitDriver htmlUnitDriver = (HtmlUnitDriver) factory.createWebDriver();
assertTrue(htmlUnitDriver.isJavascriptEnabled());
}
@Test
public void customDriverIsCreatedWithDefaultConstructorIfNoCapabilitiesConstructorExists() throws Exception {
factory.setWebDriverClassName(CustomDriverWithDefaultConstructor.class.getName());
assertEquals(CustomDriverWithDefaultConstructor.class, factory.createWebDriver().getClass());
}
@Test
public void customDriverIsCreatedWithCapabilitiesIfConstructorExists() throws Exception {
factory.setWebDriverClassName(CustomDriverWithCapabilities.class.getName());
assertEquals(CustomDriverWithCapabilities.class, factory.createWebDriver().getClass());
}
private Capabilities createWebDriverAndReturnCapabilities() throws Exception {
factory.setWebDriverClassName(CustomDriverWithCapabilities.class.getName());
CustomDriverWithCapabilities driver = (CustomDriverWithCapabilities) factory.createWebDriver();
return driver.capabilities;
}
@Test
public void enablesJavascriptOnCustomDriver() throws Exception {
assertTrue(createWebDriverAndReturnCapabilities().isJavascriptEnabled());
}
@Test
public void setsCapabilityFromMap() throws Exception {
Capability capability = new Capability();
capability.setName("foo");
capability.setValue("bar");
factory.setWebDriverCapabilities(ImmutableList.of(capability));
assertEquals("bar", createWebDriverAndReturnCapabilities().getCapability("foo"));
}
}