With the release of 10.2.1, BlackBerry 10 now supports Selenium WebDriver! Selenium is a tool that automates the browser, making it significantly easier to test web sites and web applications. Selenium is extremely useful because it is supported by a variety of browsers (Chrome, FireFox, iOS, Android, etc.) and it supports a variety of language bindings (Java, C, Python, Ruby, etc.), so you can choose the one that is best for your workflow. Selenium is supported within the browser on device and in the simulator.
Visit the official Selenium docs for a detailed document and to learn about how Selenium can work within your development and testing workflow.
Selenium WebDriver on BlackBerry 10: Getting Started Guide
Requirements:
- BlackBerry 10 Device
- Software version 10.2.1 or later
Setup
Device
- Connect your device to your computer
- Open the BB10 browser. Click on Settings > Developer Tools > Enable “Selenium WebDriver”. Make note of the IP address and port.
- Exit the menus and keep the browser open
General Setup and Bindings
Please visit SeleniumHQ for the latest information on how to use the language binding of your choice with Selenium.
Java and Eclipse setup example
This example will open google.com, search for ‘BlackBerry 10’ and print the resulting page title to the debug console.
1, Download the Java bindings (selenium-java-x.xx.0.zip) here https://code.google.com/p/selenium/downloads/list
2. Locate and unzip the file
3. Open the unzipped folder, select both “.jar” files (selenium-java-x.xx.x-srcs.jar and selenium-java-x.xx.jar) and move them into the “libs” directory within the same unzipped folder.
a. Remember this file location you will import these in step 7
4. Launch the Eclipse app (download and install Eclipse Standard )
5. Create a new Java project
a. File > New > Java Project
6. Name your Project
a. In our case we called it “Selenium”, click finish
7. Import the Java bindings into your project
a. Right click your project “Selenium”, click “Properties”
b. Select “Java Build Path” located on the left side-menu
c. Click “Add External JARs” (within the “Libraries” tab)
i. Select all jar files in the “selenium-x.xx.x /libs” directory you unzipped in step 2
ii. This should include the two Selenium jar files you added to the “libs” directory
8. Click “Open”
9. Click “Ok”
10. Create and name a new “Package” and “Class”
a. Right click on your “Selenium” project > New > Package name it “test”
i. Ensure “Create package-info.java” remains unchecked
ii. Click “Finish”
b. Right click on your “Selenium” project and select “Class”, name it “test”
i. Note: ensure “public static void main(String[ ] args)” is checked
ii. Click “Finish”
11. Copy and paste the following into your project:
package test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.*; import java.net.MalformedURLException; import java.net.URL; public class test { public static void main(String[] args) throws MalformedURLException { //BB10 bindings //the IP will vary based on your device configuration //go to Browser > Settings > Developer Tools > Selenium WebDriver for your IP DesiredCapabilities capability = DesiredCapabilities.chrome(); WebDriver driver = new RemoteWebDriver(new URL("http://169.254.0.1:1338"), capability); //Navigate to Google.com driver.get("http://www.google.com/"); //Finds the element "q" WebElement element = driver.findElement(By.name("q")); //Types "BlackBerry 10" into the input field element.sendKeys("BlackBerry 10"); //Equivalent to hitting "enter" when in a input field element.submit(); //Returns the title of the page System.out.println("Page title is: " + driver.getTitle()); //Exits the test case driver.quit(); } }
12. Click Run (shift-cmd-f11)
a. From the Save and Launch window click “Ok”
Example with Python Bindings
from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.desired_capabilities import DesiredCapabilities #BB10 bindings, #the IP will vary based on your device configuration #Go to Browser > Settings > Developer Tools > Selenium WebDriver for your IP driver = webdriver.Remote(command_executor='http://169.254.0.1:1338', desired_capabilities={}) #Navigate to Google.com driver.get("http://www.google.com/"); #Finds the element "q" by name element = driver.find_element_by_name("q") #Types "BlackBerry 10" into the input field element.send_keys("BlackBerry 10") #Equivalent to hitting "enter" key when in a input field element.submit() #Returns the title of the page print driver.title #Exits the test case driver.quit()
Questions about Selenium WebDrive support for BlackBerry 10? Let us know in the comments below!