本文整理匯總了Java中org.openqa.selenium.Platform類的典型用法代碼示例。如果您正苦於以下問題:Java Platform類的具體用法?Java Platform怎麽用?Java Platform使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Platform類屬於org.openqa.selenium包,在下文中一共展示了Platform類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createSauce
import org.openqa.selenium.Platform; //導入依賴的package包/類
protected static RemoteWebDriver createSauce ( final Platform os, final String browser, final String version ) throws MalformedURLException
{
final DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities.setBrowserName ( browser );
if ( version != null )
{
capabilities.setVersion ( version );
}
capabilities.setCapability ( CapabilityType.PLATFORM, os );
capabilities.setCapability ( CapabilityType.SUPPORTS_FINDING_BY_CSS, true );
capabilities.setCapability ( "name", "Eclipse Package Drone Main Test" );
if ( System.getenv ( "TRAVIS_JOB_NUMBER" ) != null )
{
capabilities.setCapability ( "tunnel-identifier", System.getenv ( "TRAVIS_JOB_NUMBER" ) );
capabilities.setCapability ( "build", System.getenv ( "TRAVIS_BUILD_NUMBER" ) );
capabilities.setCapability ( "tags", new String[] { "CI" } );
}
final RemoteWebDriver driver = new RemoteWebDriver ( new URL ( String.format ( "http://%s:%[email protected]%s/wd/hub", SAUCE_USER_NAME, SAUCE_ACCESS_KEY, SAUCE_URL ) ), capabilities );
driver.setFileDetector ( new LocalFileDetector () );
return driver;
}
示例2: onPosix
import org.openqa.selenium.Platform; //導入依賴的package包/類
private boolean onPosix() {
Platform current = Platform.getCurrent();
switch (current) {
case LINUX:
case UNIX:
return true;
case MAC:
case ANY:
case VISTA:
case WINDOWS:
case XP:
case ANDROID:
default:
return false;
}
}
示例3: findCommand
import org.openqa.selenium.Platform; //導入依賴的package包/類
public String findCommand(String command) {
if (vmCommand != null) {
return vmCommand;
}
if (javaHome != null) {
File homeFolder = new File(javaHome);
if (!homeFolder.exists() || !homeFolder.isDirectory()) {
throw new WebDriverException(String.format("%s: No such directory", homeFolder));
}
File binFolder = new File(javaHome, "bin");
if (!binFolder.exists() || !binFolder.isDirectory()) {
throw new WebDriverException(String.format("%s: No bin directory found in home directory", binFolder));
}
File java = new File(binFolder, Platform.getCurrent().is(Platform.WINDOWS) ? command + ".exe" : command);
if (!java.exists() || !java.isFile()) {
throw new WebDriverException(String.format("%s: No such file", java));
}
return java.getAbsolutePath();
}
return command;
}
示例4: failsWhenRequestingNonCurrentPlatform
import org.openqa.selenium.Platform; //導入依賴的package包/類
public void failsWhenRequestingNonCurrentPlatform() throws Throwable {
Platform[] values = Platform.values();
Platform otherPlatform = null;
for (Platform platform : values) {
if (Platform.getCurrent().is(platform)) {
continue;
}
otherPlatform = platform;
break;
}
DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", otherPlatform);
try {
driver = new JavaDriver(caps, caps);
throw new MissingException(SessionNotCreatedException.class);
} catch (SessionNotCreatedException e) {
}
}
示例5: shouldRetrieveBrowserDefaults
import org.openqa.selenium.Platform; //導入依賴的package包/類
@Test
public void shouldRetrieveBrowserDefaults() {
final Map<String, String> chromeParameters = new HashMap<>();
chromeParameters.put(BROWSER_NAME, "chrome");
final XmlConfig config = new XmlConfig(chromeParameters);
final Browser chrome = StreamEx.of(browsers)
.findFirst(b -> b.name() == Browser.Name.Chrome)
.orElseThrow(() -> new AssertionError("Unable to retrieve Chrome"));
assertThat(chrome.isRemote()).isFalse();
assertThat(chrome.url()).isEqualTo("http://localhost:4444/wd/hub");
assertThat(chrome.defaultConfiguration(config))
.extracting(Capabilities::getBrowserName)
.containsExactly("chrome");
assertThat(chrome.defaultConfiguration(config))
.extracting(Capabilities::getVersion)
.containsExactly("");
assertThat(chrome.defaultConfiguration(config))
.extracting(Capabilities::getPlatform)
.containsExactly(Platform.getCurrent());
assertThat(chrome.configuration(config)).isEqualTo(chrome.defaultConfiguration(config));
}
示例6: createNullFile
import org.openqa.selenium.Platform; //導入依賴的package包/類
public static int createNullFile( Path file, long size ) throws IOException, InterruptedException
{
if( Platform.getCurrent().equals( Platform.LINUX ) || Platform.getCurrent().equals( Platform.MAC ) )
{
final String CMD = String.format( "dd if=/dev/zero of=%s count=1024 bs=%d", file, size / 1024 );
Process process = Runtime.getRuntime().exec( CMD );
BufferedReader input = new BufferedReader( new InputStreamReader( process.getInputStream() ) );
String processBuffer;
while ( ( processBuffer = input.readLine() ) != null )
{
logger.debug( "create null file: {}", processBuffer );
}
input.close();
return process.waitFor();
}
throw new NotImplementedException();
}
示例7: createTextFile
import org.openqa.selenium.Platform; //導入依賴的package包/類
public static int createTextFile( Path file, long size ) throws IOException, InterruptedException
{
if( Platform.getCurrent().equals( Platform.LINUX ) || Platform.getCurrent().equals( Platform.MAC ) )
{
final String CMD = String.format( "dd if=/dev/urandom of=%s count=1024 bs=%d", file, size / 1024 );
Process process = Runtime.getRuntime().exec( CMD );
BufferedReader input = new BufferedReader( new InputStreamReader( process.getInputStream() ) );
String processBuffer;
while ( ( processBuffer = input.readLine() ) != null )
{
logger.debug( "create text file: {}", processBuffer );
}
input.close();
return process.waitFor();
}
throw new NotImplementedException();
}
示例8: setCapabilities
import org.openqa.selenium.Platform; //導入依賴的package包/類
/**
* This method sets the browser capability to the Desired Capabilities
* @param Object - current device Object value
* @param DesiredCapabilities
* @param String - name of the option
* @return DesiredCapabilities
*/
@SuppressWarnings("unchecked")
protected DesiredCapabilities setCapabilities(Object value, DesiredCapabilities dc, String name) {
if (value instanceof Boolean)
{
dc.setCapability( name, value );
}
else if (value instanceof String)
{
dc.setCapability( name, value );
}
else if (value instanceof Platform)
{
dc.setCapability( name, value );
}
else if (value instanceof Map)
{
dc = BrowserCapabilityManager.instance().getBrowsercapabilityFactory(name)
.createBrowserOptions(dc, (Map<String,Object>)value);
}
return dc;
}
示例9: getValue
import org.openqa.selenium.Platform; //導入依賴的package包/類
private Object getValue( String clazz, String value )
{
Object rtn = null;
switch ( clazz )
{
case "BOOLEAN":
rtn = Boolean.parseBoolean( value );
break;
case "OBJECT":
rtn = value;
break;
case "STRING":
rtn = value;
break;
case "PLATFORM":
rtn = ((value != null) ? Platform.valueOf( value.toUpperCase() ) : null );
break;
}
return rtn;
}
示例10: capabilitiesAreSetWhenCreatingBrowser
import org.openqa.selenium.Platform; //導入依賴的package包/類
@Test
public void capabilitiesAreSetWhenCreatingBrowser() throws MalformedURLException {
given(configuration.getRemoteBrowserName()).willReturn("firefox");
given(configuration.getRemoteBrowserVersion()).willReturn("46.0.1");
given(configuration.getRemoteFirefoxMarionette()).willReturn(true);
given(configuration.getRemoteHost()).willReturn("localhost");
given(configuration.getRemotePort()).willReturn(4444);
cut.createBrowser();
then(webDriverProducer).should().apply(urlCaptor.capture(), capabilitiesCaptor.capture());
URL url = urlCaptor.getValue();
assertThat(url).hasProtocol("http").hasHost("localhost").hasPort(4444).hasPath("/wd/hub");
DesiredCapabilities capabilities = capabilitiesCaptor.getValue();
assertThat(capabilities.getCapability(CapabilityType.BROWSER_NAME)).isEqualTo("firefox");
assertThat(capabilities.getCapability(CapabilityType.VERSION)).isEqualTo("46.0.1");
assertThat(capabilities.getCapability(CapabilityType.PLATFORM)).isEqualTo(Platform.ANY);
assertThat(capabilities.getCapability(CapabilityType.HAS_NATIVE_EVENTS)).isEqualTo(false);
assertThat(capabilities.getCapability(CapabilityType.ACCEPT_SSL_CERTS)).isEqualTo(true);
assertThat(capabilities.getCapability("marionette")).isEqualTo(true);
}
示例11: setVersionAndPlatform
import org.openqa.selenium.Platform; //導入依賴的package包/類
private static DesiredCapabilities setVersionAndPlatform(
DesiredCapabilities capability, String version, String platform) {
if (MAC.equalsIgnoreCase(platform)) {
capability.setPlatform(Platform.MAC);
} else if (LINUX.equalsIgnoreCase(platform)) {
capability.setPlatform(Platform.LINUX);
} else if (XP.equalsIgnoreCase(platform)) {
capability.setPlatform(Platform.XP);
} else if (VISTA.equalsIgnoreCase(platform)) {
capability.setPlatform(Platform.VISTA);
} else if (WINDOWS.equalsIgnoreCase(platform)) {
capability.setPlatform(Platform.WINDOWS);
} else if (ANDROID.equalsIgnoreCase(platform)) {
capability.setPlatform(Platform.ANDROID);
} else {
capability.setPlatform(Platform.ANY);
}
if (version != null) {
capability.setVersion(version);
}
return capability;
}
示例12: getDriver
import org.openqa.selenium.Platform; //導入依賴的package包/類
/**
* Creates a new webdriver instance for your test.
* @return WebDriver that has been configured to execute the specified platform and browser.
* @throws MalformedURLException
*/
private WebDriver getDriver() throws MalformedURLException{
URL server = new URL("http://localhost:4444/wd/hub");
DesiredCapabilities capababilities = new DesiredCapabilities();
// Set your OS (platform) here.
capababilities.setPlatform(Platform.MAC);
// Set your Browser here.
capababilities.setBrowserName("chrome");
// Set your Browser version here. This should be a number.
capababilities.setVersion("58");
capababilities.setJavascriptEnabled(true);
RemoteWebDriver ret = new RemoteWebDriver(server, capababilities);
ret.navigate().to("https://www.amazon.com/");
return ret;
}
示例13: onException
import org.openqa.selenium.Platform; //導入依賴的package包/類
@Override
public void onException(Throwable throwable, WebDriver driver) {
if (Platform.getCurrent().is(Platform.ANDROID)) {
// Android Java APIs do not support java.awt
return;
}
String encoded;
try {
workAroundD3dBugInVista();
Rectangle size = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage image = new Robot().createScreenCapture(size);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(image, "png", outputStream);
encoded = new Base64Encoder().encode(outputStream.toByteArray());
session.attachScreenshot(encoded);
} catch (Throwable e) {
// Alright. No screen shot. Propogate the original exception
}
}
示例14: testInitializeCapabilitiesFromProperties
import org.openqa.selenium.Platform; //導入依賴的package包/類
@Test
public void testInitializeCapabilitiesFromProperties() throws IOException {
ClassLoader classLoader = getClass().getClassLoader();
File origin = new File(classLoader.getResource("converttest.yaml").getFile());
File dest = folder.newFile();
FileUtils.copyFile(origin, dest);
Properties example = new Properties();
example.setProperty("CAPABILITIES", dest.getCanonicalPath());
TestRunnerConfig config = TestRunnerConfig.initialize(example);
Assert.assertEquals("chrome", config.capabilities().getBrowserName());
Assert.assertEquals("1280x1024", config.capabilities().getCapability("screenResolution"));
Assert.assertEquals("47.0", config.capabilities().getVersion());
Assert.assertEquals(Platform.fromString("OS X 10.10"), config.capabilities().getPlatform());
}
示例15: testFormat_selector
import org.openqa.selenium.Platform; //導入依賴的package包/類
/**
* 通常のフォーマットテスト(セレクタ)
*/
@Test
public void testFormat_selector() throws Exception {
PtlCapabilities capabilities = new PtlCapabilities(new HashMap<String, Object>());
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setBrowserName("firefox");
capabilities.setVersion("38");
PersistMetadata metadata = new PersistMetadata("testId", "testClass", "testMethod", "scId",
new IndexDomSelector(SelectorType.TAG_NAME, "body", 1), null, capabilities);
FileNameFormatter formatter = new FileNameFormatter(
"{platformName}_{platformVersion}_{browserName}_{version}_{screenArea}.png");
String result = formatter.format(metadata);
assertThat(result, is("testMethod_scId_WINDOWS_firefox_38_TAG_NAME_body_[1].png"));
}