TESTEVERYTHING
Tuesday, 22 December 2015
Tuesday, 4 August 2015
How to use ADB (Android Debug Bridge) over WiFi | Android automation
Whenever we work with
Android mobile app automation we have to connect the device using USB cable. We
can connect the device over Wi-Fi. To get rid of from the USB there
is a super simple way! All you need is a USB cable (for the initial setup) and
have both devices in the same network. This will work for non-rooted devices also.
Precondition:
- Your system and device must be in the same network.
- Android mobile must have developer option set to true.
- ADB (Android debug bridge) must be configure
- Android SDK installed.
Step 1. Attach mobile via USB
It will confirm that your device is connected and able to recognize by android sdk.
Step 2. Open then command terminal type adb devices and press enter
Step 3: type:
adb tcpip 5555
Step 4:To find the mobile ip type:
adb shell ip -f inet addr show wlan0
Step 5: The ip address will be shown in second line like this:
inet 192.168.1.233/24 brd 192.168.1.255 scope global wlan0
where 192.168.1.233 is the ip address of your mobile.
Step 6:Remove USB cable and type:
adb connect <mobile-ip>:5555
like:
adb connect <192.168.1.233>:5555
adb connect <192.168.1.233>:5555
Note:
- Make sure: that you do not have Android studio running before executing the - 'restart adb in tcpip mode' command
- If you have IDE running then adb may have been already started and you may need to restart it in some cases: adb kill-server; adb start-server
Saturday, 25 July 2015
How to know app package and activities information without having apk | android app | Appium
How to know app package and activities information without having apk | android app | Appium
In Android app mobile automation,we need apk file of app but sometimes we have to perform action on inbuild app(pre installed) which come with device like call,sms etc.. for this we do not have apk file. Basically in android app automation we need app package information and app activities. In case of apk it is easy to get above information with appium. But if we do not have apk and need the app package/activities information, we can use following command:
Precondition:
1. Android mobile must have developer option set to true.
2. ADB (Android debug bridge) must be configure
3. Android SDK installed.
Step1. Open then command terminal type adb devices and press enter
Step2: Now in mobile, open the app of which you want to get app pkg info/activities. In your mobile, it should be current activated app with focus. Means current window of your mobile should be app like calling/msg/your app window.
Step3: Now type adb shell and press enter to open the adb shell
Step4: type dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp' and press enter
Above command will show the current activated app info of your mobile. Now check the value of mCurrentFocus.
First highlighted text is pkg info
Second highlighted text is app activities info
Here you can see that we can use this:
Friday, 17 July 2015
WebDriver compare data/css between two pages
Hi All,
In Web based project like implemented in CQ5 where we have to check same site for different country. For this we have to rollout/replicate some/all pages for different countries OR I can say downloaded/uploaded the production data in testing environment or vice versa.
After this we have to validate page static data (like text) with production site Data, page wise validation.
E.g. One page of US site and replicate the same page for another country then verify page content or css
For this we have to check manually, we can automate the same. I assume both pages having same text content (English).
Logic to implement this:
• First we have to analyze page objects properties (what are the common page objects (elements) properties are being used) like class, id, type etc and create array of this.
• Then we have to get all elements from the base page(expected) using xpath(//*)
• For each element get all properties and value using java script and store only those element properties/value which are matching with common page objects (elements) properties stored in array.
• Create locators for those elements by generating xpath for them.
• Now same locator(xpath) should be exist in actual page
• open two driver instances driver1 for page1 , driver2 for another country page2
• Using WebDriver find element by xpath(locator) from base page and same for another page, match the text using gettext() method if same element present in both pages
• We can use same for CSS attribute values check for two pages having same element with same type of properties(class, ID etc)
Here is the code to implement this.
public static List<String> getPageLocatorsxPath(WebDriver driverbase,String pageURL )
{
List<String> strLocatorxPath = new ArrayList<>();
/// Common attributes from base site pages
String[] attributes = { "class", "data-class", "data-class-name",
"data-tab", "id", "name", "data-countrycode" };
HashMap<String, String> mapWeblementAttributes = new HashMap<String, String>();
JavascriptExecutor js = (JavascriptExecutor) driverbase;
/// get all elements from page
List<WebElement> childElementsGSAM = driverbase.findElements(By
.xpath("//body//*"));
int counter=0;
for (WebElement webElement : childElementsGSAM) {
// check only those element which are visible and displayed
if (webElement.isDisplayed() & webElement.isEnabled()) {
mapWeblementAttributes.clear();
// get element tag name use for creating Xpath
String strTagName = webElement.getTagName();
String strAttributes = (String) js
.executeScript(
"var str = '', obj = arguments[0].attributes; for (var key in obj){if(obj.hasOwnProperty(key)){str = str + '~' + obj[key].name + '=' + obj[key].value;}}; return str;",
webElement);
// store element properties and value in map
String[] arrAttValues = strAttributes.split("~");
for (String attribute : attributes) {
for (int k = 0; k < arrAttValues.length; k++) {
String[] arrAttrValue = arrAttValues[k].split("=");
if (arrAttrValue.length == 2) {
String strAttr = arrAttValues[k].split("=")[0];
String strAttrValue = arrAttValues[k].split("=")[1];
// store only if element property match with defined properties
if (attribute.equals(strAttr)) {
mapWeblementAttributes.put(strAttr,
strAttrValue);
}
}
}
}
// create element locators only if attribute size >1 like class and id etc..
if (mapWeblementAttributes.size() > 1) {
Set<String> setUIKeys = mapWeblementAttributes.keySet();
String strLocatorStart = "//" + strTagName + "[";
String strLocator = "";
Boolean bAnd = false;
for (String key : setUIKeys) {
if (bAnd) {
strLocator = strLocator + "and@" + key + "='"
+ mapWeblementAttributes.get(key) + "'";
} else {
strLocator = strLocator + "@" + key + "='"
+ mapWeblementAttributes.get(key) + "'";
}
bAnd = true;
}
String finalxpath = strLocatorStart +strLocator + "]";
System.out.println(finalxpath);
strLocatorxPath.add(finalxpath);
counter++;
} else {
System.out.println("not able to create locator for "
+ strTagName
+ mapWeblementAttributes.values().toString());
}
///######################
//// only for class attribute if element has only one class attribute
if (mapWeblementAttributes.size() == 1) {
Set<String> setUIKeys = mapWeblementAttributes.keySet();
String strLocatorStart = "//" + strTagName + "[";
String strLocator = "";
Boolean bAnd = false;
for (String key : setUIKeys) {
if (key.equalsIgnoreCase("class"))
{
if (mapWeblementAttributes.get(key).matches(".*\\d.*"))
{
System.out.println("not able to create locator for "
+ strTagName
+ mapWeblementAttributes.values());
}else
{
if (bAnd) {
strLocator = strLocator + "and@" + key + "='"
+ mapWeblementAttributes.get(key) + "'";
} else {
strLocator = strLocator + "@" + key + "='"
+ mapWeblementAttributes.get(key) + "'";
}
bAnd = true;
String finalxpath = strLocatorStart + strLocator + "]";
System.out.println(finalxpath);
strLocatorxPath.add(finalxpath);
}
}
}
}
///#####################
}
}
System.out.println("Total xpath locator created from base page " + strLocatorxPath.size());
return strLocatorxPath;
}
------------------------------------------------------#############---------------------
WebDriver driverbase = new FirefoxDriver(profile);
driverbase.manage().window().maximize();
WebDriver driverStatic = new FirefoxDriver(profile);
driverbase.manage().window().maximize();
String page1 = "http://www.google.com/";
String page2 = "http://www.google.com/";
driverbase.get(page2);
driverStatic.get(page1);
///######## Getting elements locator from base page ###################
List<String> strLocatorxPathofBasepage = getPageLocatorsxPath(driverbase, page1);
////##########################
System.out.println("Total xpath locator created from base page " + strLocatorxPathofBasepage.size());
for (String xpathExpression : strLocatorxPathofBasepage) {
System.out.println("Checking for xpath " + xpathExpression);
String strLocator = xpathExpression;
try {
boolean elementFoundinBasePage = (driverbase.findElements(By.xpath(xpathExpression))
.size() > 0);
boolean elementFoundinGivenPage = (driverStatic.findElements(By.xpath(xpathExpression))
.size() > 0);
if ((elementFoundinBasePage==true)
& (elementFoundinGivenPage==true)) {
strLocator = xpathExpression;
WebElement childElementGSAM = driverbase.findElement(By
.xpath(xpathExpression));
WebElement childElementStatic = driverStatic.findElement(By
.xpath(xpathExpression));
// call verify css method for css validation
verifyCSSAttributes(WebElement childElementGSAM,WebElement childElementStatic);
System.out.println(driverbase.findElement(
By.xpath(xpathExpression)).getText());
System.out.println(driverStatic.findElement(
By.xpath(xpathExpression)).getText());
/// call verify text method
verifyText(WebElement childElementGSAM,WebElement childElementStatic);
}
}}
##############################################
In this way we can check for multiple pages
In Web based project like implemented in CQ5 where we have to check same site for different country. For this we have to rollout/replicate some/all pages for different countries OR I can say downloaded/uploaded the production data in testing environment or vice versa.
After this we have to validate page static data (like text) with production site Data, page wise validation.
E.g. One page of US site and replicate the same page for another country then verify page content or css
For this we have to check manually, we can automate the same. I assume both pages having same text content (English).
Logic to implement this:
• First we have to analyze page objects properties (what are the common page objects (elements) properties are being used) like class, id, type etc and create array of this.
• Then we have to get all elements from the base page(expected) using xpath(//*)
• For each element get all properties and value using java script and store only those element properties/value which are matching with common page objects (elements) properties stored in array.
• Create locators for those elements by generating xpath for them.
• Now same locator(xpath) should be exist in actual page
• open two driver instances driver1 for page1 , driver2 for another country page2
• Using WebDriver find element by xpath(locator) from base page and same for another page, match the text using gettext() method if same element present in both pages
• We can use same for CSS attribute values check for two pages having same element with same type of properties(class, ID etc)
Here is the code to implement this.
public static List<String> getPageLocatorsxPath(WebDriver driverbase,String pageURL )
{
List<String> strLocatorxPath = new ArrayList<>();
/// Common attributes from base site pages
String[] attributes = { "class", "data-class", "data-class-name",
"data-tab", "id", "name", "data-countrycode" };
HashMap<String, String> mapWeblementAttributes = new HashMap<String, String>();
JavascriptExecutor js = (JavascriptExecutor) driverbase;
/// get all elements from page
List<WebElement> childElementsGSAM = driverbase.findElements(By
.xpath("//body//*"));
int counter=0;
for (WebElement webElement : childElementsGSAM) {
// check only those element which are visible and displayed
if (webElement.isDisplayed() & webElement.isEnabled()) {
mapWeblementAttributes.clear();
// get element tag name use for creating Xpath
String strTagName = webElement.getTagName();
String strAttributes = (String) js
.executeScript(
"var str = '', obj = arguments[0].attributes; for (var key in obj){if(obj.hasOwnProperty(key)){str = str + '~' + obj[key].name + '=' + obj[key].value;}}; return str;",
webElement);
// store element properties and value in map
String[] arrAttValues = strAttributes.split("~");
for (String attribute : attributes) {
for (int k = 0; k < arrAttValues.length; k++) {
String[] arrAttrValue = arrAttValues[k].split("=");
if (arrAttrValue.length == 2) {
String strAttr = arrAttValues[k].split("=")[0];
String strAttrValue = arrAttValues[k].split("=")[1];
// store only if element property match with defined properties
if (attribute.equals(strAttr)) {
mapWeblementAttributes.put(strAttr,
strAttrValue);
}
}
}
}
// create element locators only if attribute size >1 like class and id etc..
if (mapWeblementAttributes.size() > 1) {
Set<String> setUIKeys = mapWeblementAttributes.keySet();
String strLocatorStart = "//" + strTagName + "[";
String strLocator = "";
Boolean bAnd = false;
for (String key : setUIKeys) {
if (bAnd) {
strLocator = strLocator + "and@" + key + "='"
+ mapWeblementAttributes.get(key) + "'";
} else {
strLocator = strLocator + "@" + key + "='"
+ mapWeblementAttributes.get(key) + "'";
}
bAnd = true;
}
String finalxpath = strLocatorStart +strLocator + "]";
System.out.println(finalxpath);
strLocatorxPath.add(finalxpath);
counter++;
} else {
System.out.println("not able to create locator for "
+ strTagName
+ mapWeblementAttributes.values().toString());
}
///######################
//// only for class attribute if element has only one class attribute
if (mapWeblementAttributes.size() == 1) {
Set<String> setUIKeys = mapWeblementAttributes.keySet();
String strLocatorStart = "//" + strTagName + "[";
String strLocator = "";
Boolean bAnd = false;
for (String key : setUIKeys) {
if (key.equalsIgnoreCase("class"))
{
if (mapWeblementAttributes.get(key).matches(".*\\d.*"))
{
System.out.println("not able to create locator for "
+ strTagName
+ mapWeblementAttributes.values());
}else
{
if (bAnd) {
strLocator = strLocator + "and@" + key + "='"
+ mapWeblementAttributes.get(key) + "'";
} else {
strLocator = strLocator + "@" + key + "='"
+ mapWeblementAttributes.get(key) + "'";
}
bAnd = true;
String finalxpath = strLocatorStart + strLocator + "]";
System.out.println(finalxpath);
strLocatorxPath.add(finalxpath);
}
}
}
}
///#####################
}
}
System.out.println("Total xpath locator created from base page " + strLocatorxPath.size());
return strLocatorxPath;
}
------------------------------------------------------#############---------------------
WebDriver driverbase = new FirefoxDriver(profile);
driverbase.manage().window().maximize();
WebDriver driverStatic = new FirefoxDriver(profile);
driverbase.manage().window().maximize();
String page1 = "http://www.google.com/";
String page2 = "http://www.google.com/";
driverbase.get(page2);
driverStatic.get(page1);
///######## Getting elements locator from base page ###################
List<String> strLocatorxPathofBasepage = getPageLocatorsxPath(driverbase, page1);
////##########################
System.out.println("Total xpath locator created from base page " + strLocatorxPathofBasepage.size());
for (String xpathExpression : strLocatorxPathofBasepage) {
System.out.println("Checking for xpath " + xpathExpression);
String strLocator = xpathExpression;
try {
boolean elementFoundinBasePage = (driverbase.findElements(By.xpath(xpathExpression))
.size() > 0);
boolean elementFoundinGivenPage = (driverStatic.findElements(By.xpath(xpathExpression))
.size() > 0);
if ((elementFoundinBasePage==true)
& (elementFoundinGivenPage==true)) {
strLocator = xpathExpression;
WebElement childElementGSAM = driverbase.findElement(By
.xpath(xpathExpression));
WebElement childElementStatic = driverStatic.findElement(By
.xpath(xpathExpression));
// call verify css method for css validation
verifyCSSAttributes(WebElement childElementGSAM,WebElement childElementStatic);
System.out.println(driverbase.findElement(
By.xpath(xpathExpression)).getText());
System.out.println(driverStatic.findElement(
By.xpath(xpathExpression)).getText());
/// call verify text method
verifyText(WebElement childElementGSAM,WebElement childElementStatic);
}
}}
##############################################
In this way we can check for multiple pages
Labels:
Adobe,
Class,
Communique5,
CQ5,
ID,
locator,
WCMS,
Webdriver,
WebElement,
XPATH
Wednesday, 17 June 2015
Difference between action.build().perform() and action.perform()
In Webdriver, handling keyboard events and mouse events (including actions such as Drag and Drop or clicking multiple elements With Control key) are done using the advanced user interactions API . It contains Actions and Action classes which are needed when performing these events. In order to perform action events, we need to use org.openqa.selenium.interactions.Actions class.
The build() method is used compile all the listed actions into a single step.
we have to use build() when we are performing sequence of operations and no need to use only if we are performing single action.
example where build() required
Actions builder = new Actions(driver);
builder.clickAndHold((WebElement)listItems.get(0)).clickAndHold((WebElement)listItems.get(3)).click().build().perform();
in the above code we are performing more than one operations so we have to use build() to compile all the actions into a single step
example where build is not required
WebElement draggable = driver.findElement(By.id("draggable"));
WebElement droppable = driver.findElement(By.id("droppable"));
new Actions(driver).dragAndDrop(draggable, droppable).perform();
in the above code we are performing just a single operations so no need to use build()
in the above code we are performing just a single operations so no need to use build()
Wednesday, 11 March 2015
What qualities should have in your automation framework
The following are some qualities should have in your automation framework.
- Maintainability
- Portability
- Flexibility
- Robustness
- Scalability
- Reliability
- Usability
- Performance
Thursday, 5 March 2015
Scrolling web page with Webdriver using java
We can scroll the web page using javaScript Executor or You can use the "org.openqa.selenium.interactions.Actions" class to move to an element:
Following classes you required in you java code
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
1. We may require to scroll to bottom of the page and then perform operations. For this scenario we can use following code
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
2. Some times, we may require to scroll to particular element and peform operations on that particular element. For this we need to pass the element on which we need to perform operation. For this scenario we ca use following code
WebElement element = driver.findElement(By.linkText("googleMap"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element);
OR
WebElement element = driver.findElement(By.id("my-id"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();
3. We can also use the coordinates to scroll to particular position by passing the coordinates. For this scenario we use following code
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)");
Wednesday, 11 February 2015
How to Re-Sign an iOS App from an External Developer/
iReSign allows iDevice app bundles (.ipa) files to be signed or resigned with a digital certificate from Apple for distribution. This tool is aimed at enterprises users, for enterprise deployment, when the person signing the app is different than the person(s) developing it.
If you ever work with 3rd party developers, you know that getting the final project into production can take two different routes. You can either let the developer push the code/project into production or they hand it over to your internal team to release. There are pros and cons for each, but I always prefer to publish things ourselves since it reduces security concerns and gives us more control. The Apple App Store is no different, and it is actually really simple to take a developer app and turn it into an App Store version for submission.
Note: You can use this exact same process to resign the app to your developer certificate and profile, so you can install it on your own registered developer devices.
Step
1: Pull
the latest iResign code from Github “$ git clone https://github.com/maciekish/iReSign.git”
Step
2: Build
the code from Xcode
Step
3: In
the window that appears “Enter the path to valid provisioning profile”, “Leave
the fields to .plist file blank” and “Enter the build identifier from
application”
Step
4: From
the drop-down "Select valid developer profile” and click on "ReSign!”
button.
Note: Resigned
file will be saved to same directory as of original application.
Advantage:
- We now have to ask from client just .ipa file for
automating on iOS platform, same as we require just .apk file for
automating on android platform
Refer the below link for more reference
https://github.com/maciekish/iReSign
http://dev.mlsdigital.net/posts/how-to-resign-an-ios-app-from-external-developers/
Tuesday, 13 January 2015
HOW TO INSTALL PLUGINS IN JENKINS
HOW TO INSTALL PLUGINS IN JENKINS
Buy Mobiles & Tablets from Amazon
1.
Navigate to manage Plugins page.
Jenkins>Manage Jenkins>Manage plugins
2.
Select available tab and type plugin name in
search field.
Buy Mobiles & Tablets from Amazon
HOW TO UNINSTALL JENKINS
How to uninstall Jenkins on Mac system
1. Execute
from terminal
/Library/Application
Support/Jenkins/Uninstall.command
2. Or use
Finder to navigate into that folder and double-click on Uninstall.command.
3. If the
uninstallation script cannot be found, use:
sudo launchctl unload
/Library/LaunchDaemons/org.jenkins-ci.plist
sudo rm
/Library/LaunchDaemons/org.jenkins-ci.plist
sudo rm -rf /Applications/Jenkins
"/Library/Application Support/Jenkins" /Library/Documentation/Jenkins
4. if you
want to get rid of all the jobs and builds:
sudo rm -rf /Users/Shared/Jenkins
5. to delete
the jenkins user and group (if you chose to use them):
sudo dscl .
-delete /Users/jenkins
sudo dscl .
-delete /Groups/jenkins
Wednesday, 7 January 2015
To know all devices connected to machines / simulator information on mac machine
Open the terminal type following command:
$ instruments -s deivces
$ instruments -s deivces
Known Devices:
mobileQA’s Mac mini [303FD57A-BA31-5AF8-BBC4-85D1F3FF38A3]
Resizable iPad (8.0 Simulator) [5C7AFC61-6B75-49DE-9B28-4CCD125A1F24]
Resizable iPhone (8.0 Simulator) [D88F397A-98B4-4CE7-A625-230A56730086]
iPad 2 (7.0.3 Simulator) [C2C72D3E-147C-4796-90DD-682E4DBD469E]
iPad 2 (7.1 Simulator) [696557BE-7723-49A3-ADA6-46090B2576FB]
iPad 2 (8.0 Simulator) [3395DD16-17E6-4A69-BAB2-D7414759E04B]
iPad Air (7.0.3 Simulator) [1432341A-C3DD-47B8-95D4-5F17C08BF4A7]
iPad Air (7.1 Simulator) [14C9A977-4D56-404A-897F-F5DE8F5F7208]
iPad Air (8.0 Simulator) [F92E44D9-8E3F-43D2-9124-00C688126AED]
iPad Retina (7.0.3 Simulator) [4FFA8E0D-290A-47BB-B7D6-806641AFAEF7]
iPad Retina (7.1 Simulator) [76F3CC43-0E3A-4ADD-9520-AA1E20F8DD71]
iPad Retina (8.0 Simulator) [DC9C5DFA-988B-40A5-8E81-3F3FB0D11043]
Subscribe to:
Posts (Atom)