I wanted to tap on webview. No specific content. But any where in a webivew.
The webview content is having a graph. I need to tap on the graph.
How can I do that?
I tried using this:
XCUIApplication().descendants(matching: .webView).element.tap()
But no luck
try something like this:
func testSomething() {
let app = XCUIApplication()
app.launch()
app.webviews.tap()
}
Related
I'm pretty new to XCode UI tests and I'm trying to run a test where I fill two text labels and then I press a button. After the button is pressed the app should make an URL call and be redirected to another view controller. I want to check if at the end of this operation the second view controller is displayed.
To test this, I have written the following test:
let app = XCUIApplication()
app.launch()
let ownerTextField = app.textFields["ownerTextField"]
ownerTextField.tap()
ownerTextField.typeText("UserA")
let repositoryTextField = app.textFields["repositoryTextField"]
repositoryTextField.tap()
repositoryTextField.typeText("AppB")
app.buttons["SearchButton"].tap()
XCTAssertTrue(app.isDisplayingResults)
Where isDisplayingResults is
extension XCUIApplication {
var isDisplayingResults: Bool {
return otherElements["resultView"].exists
}
}
I have set up the identifier of the View controller inside its swift file class:
override func viewDidLoad() {
super.viewDidLoad()
view.accessibilityIdentifier = "resultView"
...
Nonetheless to say, the test fails. How can I get a success?
It's so simple.
If after clicking the URL, Viewcontroller is presenting means your previous VC button doesn't exist on screen.
So Just check for previous VC button exists or not.
If app.buttons["SearchButton"].esists()
{ //write if code
} else {
// Write else code
}
let mainQueue = NSOperationQueue.mainQueue()
NSNotificationCenter.defaultCenter().addObserverForName(UIApplicationUserDidTakeScreenshotNotification,
object: nil,
queue: mainQueue) { notification in
// executes after screenshot
}
This code works after taking screenshot.
Is there any way we can replace view with blank view while taking screenshot?
As we know we cannot disable screenshot in ios.
I have a problem with the above stated. I can not find the exact information on the forums. Most of them are outdated and I have written the code programmatically. I have a controller that contains a view to edit the profile. I can not access that after changing the function listed below. I have a rootviewcontroller set to something else, but I tried the UiApplication calls anyway and it return nil and I can not open the profile controller. This is the function listed below.
#objc func handleOpen2() {
(UIApplication.shared.keyWindow?.rootViewController as? BaseSlidingController)?.openMenu()
}
Xcode does not give me an error but I can not get my menu to open. My rootviewcontroller is set to something else in app delegate. I have a controller that is used to control the sliding menu when I press the edit profile button.
func openMenu() {
isMenuOpened = true
redViewLeadingConstraint.constant = menuWidth
redViewTrailingConstraint.constant = menuWidth
performAnimations()
setNeedsStatusBarAppearanceUpdate()
}
This code is used to open my side bar menu with the information I need and also to perform animations as well. I was wondering if someone had any idea what I can do different instead in my handleOpen2 function. If you need more code, please let me know. Thanks
On swift 5 version:
(UIApplication.shared.windows.first?.rootViewController as? BaseSlidingController)?.openMenu()
I am trying to show my long text on Navigation Bar in 2 lines. I am using LargeTitles.
What I need is this https://i.stack.imgur.com/Yb85L.png // sorry cant post picture.
Image was taken from this post
I have tried a lot of examples and have achieved in showing the title in 2 lines. but the problem is that when I open a ViewController with a long title it jumps to adjust the title. Following is my code I have tried. I want to avoid jumping (increasing) and show the multiline text as same as it if using single line text. the normal effect.
func multiLineHeader() {
if #available(iOS 11.0, *) {
if let subviews = self.navigationController?.navigationBar.subviews {
for navItem in subviews {
for itemSubView in navItem.subviews {
if let largeLabel = itemSubView as? UILabel {
if largeLabel.canFitInSingleLine() { return }
largeLabel.numberOfLines = 2
largeLabel.lineBreakMode = .byWordWrapping
largeLabel.sizeToFit()
self.navigationController?.navigationBar.frame.size.height += largeLabel.frame.height
self.navigationController?.navigationBar.layoutIfNeeded()
}
}
}
}
}
}
I am calling this from viewDidAppear(). I tried calling from viewDidLoad() and viewWillAppear() does not work event title is not in 2 lines. as it was when called from viewDidAppear().
If there is anything which is not clear, comment and I will add more details.
This is not a solution to solve the multiline jump effect.
My question was based on the multiline title which I saw in the App Store(app) which did not have a jump effect. After a while when I dig deep into it. I found out that even in the App Store there is a jump effect on some screens and in some places App Store is using view rather than navigation bar.
For example, if you go to the App Store and search for Thunderbox entertainment.
1) Go to one of its apps and then click on company name to see all apps you will see a navigation bar with jump effect.
2) If you open the company profiles directly from the search screen you won't see any jump effect.
Recently I used this to Move View Behind Keyboard When textfield is selected
http://www.ioscreator.com/tutorials/move-view-behind-keyboard-ios8-swift
What if I need to move view only for some inputs, others are near top and don't need it? I tries the following code but no success in that.
var searcher
func keyboardWillShow(notification: NSNotification) {
if (searcher.tag == 1){
if let userInfo = notification.userInfo {
if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
kbHeight = keyboardSize.height
self.animateTextField(true)
}
}
}
}
Thanks in advance!
I would recommend you to use AutoKeyboardScrollView library instead of adding code manually. This library already does what you need with the expected behaviour.
As seen on the project's readme:
Another great library for this is IQKeyboardManager. https://github.com/hackiftekhar/IQKeyboardManager
Simple to use and will do this globally for your entire app. Easy configuration and it adds previous, next and done functionality
If you're using cocoapods, just add
pod 'IQKeyboardManager-Swift'
Check out the docs on the GitHub page for the config options