Skip to content

Instantly share code, notes, and snippets.

@kazuki-ma
Last active December 23, 2015 13:05
Show Gist options
  • Save kazuki-ma/3601f949bf2e8160639b to your computer and use it in GitHub Desktop.
Save kazuki-ma/3601f949bf2e8160639b to your computer and use it in GitHub Desktop.
Safari Responsive Design Mode
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.IOException;
import lombok.Cleanup;
import org.openqa.selenium.safari.SafariDriver;
public class SafariCustomDriverProvider {
public static void main(String[] args) throws InterruptedException, IOException {
// Safari Driver 起動
@Cleanup("quit")
final SafariDriver driver = new SafariDriver();
// Safari Window を Screen Top に
Runtime.getRuntime().exec("open -a /Applications/Safari.app/Contents/MacOS/Safari").waitFor();
// Option + Command + R で Responsive Desing モード起動
try {
final Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_R);
robot.delay(100);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_META);
robot.keyRelease(KeyEvent.VK_R);
} catch (AWTException e) {
throw new RuntimeException(e);
}
driver.get("http://example.com/");
}
}
@kazuki-ma
Copy link
Author

@kazuki-ma
Copy link
Author

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